Skip to content

fix(openapi): handle request body media types with no schema - #7848

Closed
ninglinLiu wants to merge 14 commits into
google:mainfrom
ninglinLiu:fix/7838-rest-api-tool-null-schema
Closed

ninglinLiu wants to merge 14 commits into
google:mainfrom
ninglinLiu:fix/7838-rest-api-tool-null-schema

Conversation

@ninglinLiu

Copy link
Copy Markdown
Contributor

Description

Fixes #7838

RestApiTool._prepare_request_params read media_type_object.schema_.type unconditionally. OpenAPI allows a media type with no schema (e.g. content: {application/octet-stream: {}}). OperationParser already normalizes that via _schema_from_openapi, so the tool is generated and offered to the model, but every call crashed with AttributeError: 'NoneType' object has no attribute 'type'.

Treat a missing schema like a non-object body and send the single body parameter as raw data with the declared Content-Type.

Test plan

  • Unit test: application/octet-stream MediaType with no schema sends bytes and Content-Type
  • CI

This PR was prepared with AI assistance and reviewed/tested by the author.

RestApiTool._prepare_request_params read media_type_object.schema_.type
unconditionally. OpenAPI allows content entries with an empty MediaType
(no schema), which made every call raise AttributeError. Treat a missing
schema like a non-object and send the single body parameter as raw data.

Fixes google#7838

This PR was prepared with AI assistance and reviewed/tested by the author.
@GWeale GWeale self-assigned this Nov 4, 2026
@GWeale
GWeale self-requested a review November 4, 2026 18:41
@GWeale

GWeale commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

thanks for sending this, @ninglinLiu. #7839 came in a few hours earlier for the same bug and is already under review, so i'm closing this one in favor of that. if it's still happening after that lands, please open a new issue.

@GWeale GWeale closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RestApiTool crashes on a request body media type that has no schema

3 participants