Skip to content

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

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

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.
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

2 participants