Skip to content

fix(openapi): scan every 2xx media type for the return schema - #917

Merged
AmaadMartin merged 2 commits into
google:mainfrom
AmaadMartin:fix/openapi-return-schema-mime-scan
Sep 18, 2026
Merged

AmaadMartin merged 2 commits into
google:mainfrom
AmaadMartin:fix/openapi-return-schema-mime-scan

Conversation

@adk-foundry-bot

@adk-foundry-bot adk-foundry-bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

This pull request will be merged automatically

Scheduled merge: 2026-09-18 21:30 UTC (about 24h from opening).

It was selected by [ADK Foundry] because the merge critic approved
the change, it is small, it touches no sensitive path, and CI is
green. No human has reviewed it.

To stop it: close this pull request, add the status/on-hold
label, or leave a review comment. Any of the three cancels the
merge; pushing a commit restarts the clock. Nothing is merged while
a question is open.

Approving does not stop it. An approval, or a comment that says
only lgtm, lets the merge run on schedule. Add any other text and
the merge stops.

Staged from fork PR #969.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

N/A

2. Or, if no issue exists, describe the change:

Problem:

An OpenAPI response may declare several media types, and only some of them
carry a schema. OperationParser read the first media type only, so it
dropped a return schema declared on a later entry. A 200 response with
text/plain before application/json parsed to the empty schema {}.
adk-python scans the whole content map and stops at the first entry that has a
schema.

Solution:

The scan now continues past a media type that has no schema. I added a public
getReturnValue() accessor, which gives the previously write-only
returnValue field a reader and lets the tests assert through the class. The
2xx selection rule, lowest status code wins, is unchanged. One divergence from
adk-python: this port skips a media type whose schema is an unresolved $ref,
a case OpenApiSpecParser.parse() makes unreachable because it resolves
references first.

Wiring ParsedOperation.returnValue in collectOperations is out of scope, so
OpenApiSpecParser and RestApiTool behave as before.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Four new it() blocks in
core/test/tools/openapi_tool/operation_parser_test.ts. The eleven existing
tests are untouched.

npx vitest run --project unit:core core/test/tools/openapi_tool/operation_parser_test.ts \
  core/test/tools/openapi_tool/openapi_spec_parser_test.ts \
  core/test/tools/openapi_tool/rest_api_tool_test.ts \
  core/test/tools/openapi_tool/openapi_toolset_test.ts \
  core/test/tools/openapi_tool/openapi_toolset_integration_test.ts
# Test Files 5 passed (5), Tests 97 passed (97)

Proof the tests can fail: I reverted the loop to the original single-media-type
lookup and re-ran the file. Three of the four new tests failed.

× should use the first 2xx media type that declares a schema
  -> AssertionError: expected undefined to be 'object'
× should scan the media types of the lowest 2xx response only
  -> AssertionError: expected undefined to be 'boolean'
× should skip a media type whose schema is an unresolved reference
  -> AssertionError: expected undefined to be 'string'

The fourth ("keep an empty return schema when no media type declares a schema")
still passed, as expected: it pins the fallback both versions share.

npm run lint and npm run format:check are clean on this commit.

Manual End-to-End (E2E) Tests:

Not applicable. The parsed return value has no consumer on the public surface
yet, so there is no user-visible flow to drive by hand. An in-memory
OpenAPIV3.OperationObject fully determines the behaviour.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

adk-foundry-bot added 2 commits September 17, 2026 14:07
An OpenAPI response may declare several media types and only some of
them carry a schema. The parser read the first media type only, so a
return schema declared on a later entry was dropped. adk-python scans
the whole content map and stops at the first entry with a schema.

Extract processReturnValue into a module-level parseReturnValue so the
scan is testable without widening the private returnValue field.
Revert the module-level extraction. The loop fix applies inside the
private method, and a public getReturnValue() accessor gives the
write-only returnValue field a reader for the tests to assert through.
@AmaadMartin AmaadMartin added the automerge: scheduled Foundry will merge this automatically; close it to stop that label Sep 17, 2026
@AmaadMartin

Copy link
Copy Markdown
Collaborator

Merging in about 6h unless someone objects. Close this PR, add status/on-hold, or comment to stop it. Approving, or commenting only lgtm, lets it merge. No human has reviewed this change.

@AmaadMartin

Copy link
Copy Markdown
Collaborator

Merging in about 1h unless someone objects. Close this PR, add status/on-hold, or comment to stop it. Approving, or commenting only lgtm, lets it merge. No human has reviewed this change.

@adk-foundry-approver adk-foundry-approver left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved automatically by ADK Foundry. No human has read this change.

This approval attests only that the change passed the gates below, all
enforced in code:

  • the merge critic read the diff and approved it (93.9% precision measured
    against 107 upstream pull requests with known maintainer outcomes)
  • ? changed lines across ? file(s), inside the 200/5 ceiling
  • no auth, credential, security, release or dependency-manifest path touched
  • required checks green, re-verified immediately before this approval
  • opened 25h ago and visible as automerge: scheduled throughout,
    with no objection from anyone

To stop this merging, close the pull request or add status/on-hold. To stop
the mechanism entirely, revoke this account's access; delivery continues and
nothing merges.

@AmaadMartin
AmaadMartin merged commit 975b693 into google:main Sep 18, 2026
15 checks passed
@AmaadMartin AmaadMartin added automerge: merged Merged automatically by Foundry after its 24h review window expired with no objection and removed automerge: scheduled Foundry will merge this automatically; close it to stop that labels Sep 18, 2026
@kalenkevich kalenkevich mentioned this pull request Sep 18, 2026
prasanna8585 pushed a commit to prasanna8585/adk-js that referenced this pull request Nov 10, 2026
…#917)

* fix(openapi): scan every 2xx media type for the return schema

An OpenAPI response may declare several media types and only some of
them carry a schema. The parser read the first media type only, so a
return schema declared on a later entry was dropped. adk-python scans
the whole content map and stops at the first entry with a schema.

Extract processReturnValue into a module-level parseReturnValue so the
scan is testable without widening the private returnValue field.

* fix(openapi): keep processReturnValue private, add getReturnValue

Revert the module-level extraction. The loop fix applies inside the
private method, and a public getReturnValue() accessor gives the
write-only returnValue field a reader for the tests to assert through.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge: merged Merged automatically by Foundry after its 24h review window expired with no objection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants