Repository navigation
fix(tools): build RestApiTool bodies from the parser's normalized schema - #7839
Open
adityasingh2400 wants to merge 1 commit into
Open
adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
OperationParser normalizes a request-body media type that has no schema
(e.g. application/octet-stream: {}) to an empty Schema and exposes one
body parameter, but _prepare_request_params read the raw schema_ and
raised AttributeError on None. Normalize it the same way so the generated
tool can actually be called. This also clears the two mypy union-attr
errors on that line.
Fixes google#7838
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
OperationParsernormalizes each request-body media type's schema with_schema_from_openapi, so a media type declared without a schema (e.g.application/octet-stream: {}) becomesSchema()and gets a singlebodyparameter.RestApiTool._prepare_request_paramsreadmedia_type_object.schema_raw and called.typeon it. A schema-less body therefore produced a tool that crashed withAttributeError: 'NoneType' object has no attribute 'type'on every call.Solution:
Normalize the schema in
_prepare_request_paramswith the same_schema_from_openapicall the parser makes, so the request is built from the schema the parameters were derived from. Object bodies and other schemas behave as before. The two mypy errors on that line (Item "None"/"Reference" of "Schema | Reference | Any | None" has no attribute "type") go away, and no new ones appear.Testing Plan
Unit Tests:
Added
test_prepare_request_params_media_type_without_schematotest_rest_api_tool.py. It builds the parameters withOperationParser, asOpenAPIToolsetdoes, and asserts that the bytes are sent asdatawithContent-Type: application/octet-stream.pre-commit runpasses on the changed files.mypyonrest_api_tool.pygoes from 25 errors onmainto 23; the two removed are theunion-attrerrors on this line.Manual End-to-End (E2E) Tests:
Reproduced through the parser-built parameters, the same path
OpenAPIToolsetuses:Checklist
Additional context
None.