Skip to content

fix(openapi): Preserve required body properties - #6504

Open
benclarkeio wants to merge 1 commit into
google:mainfrom
benclarkeio:fix/openapi-required-body-properties
Open

fix(openapi): Preserve required body properties#6504
benclarkeio wants to merge 1 commit into
google:mainfrom
benclarkeio:fix/openapi-required-body-properties

Conversation

@benclarkeio

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue:

Problem:

OperationParser flattens object request-body properties into individual ApiParameter instances, but does not propagate the object schema required list. 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.required when 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 as spaceName.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • The complete OpenAPI parser unit-test directory passes locally.
$ pytest tests/unittests/tools/openapi_tool/openapi_spec_parser -q
128 passed, 26 warnings in 3.79s

The new regression test verifies that a required spaceName body property appears as space_name in the generated parameter schema required list while an optional property remains optional.

Changed-file checks:

ruff, isort, pyink, addlicense, ADK Compliance Checks, and codespell: passed

Environment limitation:

The full test extra and multi-version tox suite could not run locally because google-antigravity==0.1.8 has 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 spaceName and tmsZoneId properties. Before this change both parameters reported required=False; after the change they are included in the generated JSON Schema required list and the optional description property is excluded.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • The implementation is self-explanatory and does not require an additional comment.
  • I have added tests that prove the fix is effective.
  • New and existing OpenAPI parser unit tests pass locally with my changes.
  • I have manually tested the parser behavior end-to-end.
  • There are no dependent downstream changes required.

Additional context

PR #256 added required-field handling for regular operation parameters. This is the corresponding missing handling for object request-body properties.

- Propagate object schema required names to flattened body parameters.
- Cover normalized required fields in generated parameter schemas.

Fixes google#6503
@google-cla

google-cla Bot commented Jul 28, 2026

Copy link
Copy Markdown

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.

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.

OpenAPIToolset drops required request body properties

1 participant