fix(openapi): Preserve required body properties - #6504
Open
benclarkeio wants to merge 1 commit into
Open
Conversation
- Propagate object schema required names to flattened body parameters. - Cover normalized required fields in generated parameter schemas. Fixes google#6503
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Link to Issue or Description of Change
1. Link to an existing issue:
Problem:
OperationParserflattens object request-body properties into individualApiParameterinstances, but does not propagate the object schemarequiredlist. Generated function declarations therefore advertise mandatory body fields as optional, allowing models to omit them and send invalid requests.Solution:
Build a set from
schema.requiredwhen processing an object request body and set each flattened parameter required when its original property name is in that set. Matching before Python name normalization also preserves requiredness for camelCase OpenAPI properties such asspaceName.Testing Plan
Unit Tests:
The new regression test verifies that a required
spaceNamebody property appears asspace_namein the generated parameter schema required list while an optional property remains optional.Changed-file checks:
Environment limitation:
The full
testextra and multi-versiontoxsuite could not run locally becausegoogle-antigravity==0.1.8has no wheel or source distribution for macOS x86_64. The focused parser suite uses the project base and development dependencies and passes; upstream CI can exercise the remaining platforms.Manual End-to-End (E2E) Test:
Parsed an object request body with required
spaceNameandtmsZoneIdproperties. Before this change both parameters reportedrequired=False; after the change they are included in the generated JSON Schema required list and the optionaldescriptionproperty is excluded.Checklist
Additional context
PR #256 added required-field handling for regular operation parameters. This is the corresponding missing handling for object request-body properties.