GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix optional bodies by dbanty · Pull Request #1365 · openapi-generators/openapi-python-client

Conversation

@dbanty

@dbanty dbanty commented Nov 25, 2025

Copy link
Copy Markdown
Collaborator

Reopening #1357

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dbanty
dbanty force-pushed the fix-optional-bodies branch 2 times, most recently from 6c9c6dd to a94f570 Compare November 30, 2025 00:00
@dbanty
Fix optional bodies
fefc780
@dbanty
dbanty force-pushed the fix-optional-bodies branch from a94f570 to fefc780 Compare November 30, 2025 00:41
@dbanty
dbanty requested a review from Copilot November 30, 2025 00:42
Copilot started reviewing on behalf of dbanty November 30, 2025 00:42
View session
Copilot finished reviewing on behalf of dbanty November 30, 2025 00:46
Copilot AI reviewed Nov 30, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the handling of optional request bodies in the OpenAPI Python client generator. Previously, optional bodies were incorrectly treated as required, causing them to always be included in requests. The fix ensures that optional bodies (where requestBody.required is false or missing) are properly typed with Unset, default to UNSET, and are only included in requests when explicitly provided.

Key Changes:

  • Modified body parsing to respect the required field from request body definitions
  • Updated all property transform templates to support a skip_unset parameter for conditional UNSET initialization
  • Added deduplication of union types to prevent duplicate type members
  • Generated code now properly handles optional bodies across different content types (JSON, multipart, octet-stream, etc.)

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
openapi_python_client/parser/bodies.py Passes the actual body.required value instead of hardcoding True
openapi_python_client/parser/properties/union.py Adds deduplication logic to remove duplicate types from unions and uses Iterator for better memory efficiency
openapi_python_client/templates/property_templates/*.py.jinja Adds skip_unset parameter to transform macros to conditionally skip UNSET initialization
openapi_python_client/templates/endpoint_macros.py.jinja Updates body handling to check if bodies are optional and conditionally include them in requests
openapi_python_client/templates/endpoint_module.py.jinja Uses no_optional=True for isinstance checks with multiple bodies
end_to_end_tests/golden-record/* Updated golden records showing correct handling of optional bodies with Unset types
end_to_end_tests/baseline_openapi_. Added test cases for optional bodies and duplicate union types
tests/test_parser/test_properties/test_union.py Updated test to verify different property types in unions
.changeset/fix_optional_bodies.md Documents the fix for optional bodies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread openapi_python_client/templates/property_templates/file_property.py.jinja Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread openapi_python_client/templates/property_templates/enum_property.py.jinja Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread openapi_python_client/templates/endpoint_macros.py.jinja Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread openapi_python_client/templates/property_templates/literal_enum_property.py.jinja Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread openapi_python_client/templates/property_templates/list_property.py.jinja Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/bodies/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@dbanty
dbanty merged commit b827e3e into main Dec 3, 2025
28 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@dbanty
dbanty deleted the fix-optional-bodies branch December 3, 2025 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@dbanty
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.