Fix/invalid union return type #3
Merged
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.
This pull request introduces several enhancements and bug fixes to the OpenAPI Python generator, focusing on improved support for discriminated unions, import handling, and client code generation. The most significant changes include the addition of named aliases for discriminated response unions, improved propagation and deduplication of import statements, better handling of nullable and map types, and updates to client templates for compatibility with Pydantic v2. Below are the most important changes grouped by theme:
Discriminated Union and Response Alias Support:
generate_response_union_alias_modelsfunction inmodel_generator.py. This includes common suffix detection for alias naming. (Fe7c6952L333R333)client_generator.pyto prefer named aliases for discriminated unions of referenced response schemas, improving type clarity in generated clients.Import Handling Improvements:
type_converterinmodel_generator.pyto propagate and deduplicate all import statements from nested schemas, ensuring correct imports for unions, arrays, and map types. [1] [2]Client Template Updates for Pydantic v2:
TypeAdapterfor model validation, ensuring compatibility with Pydantic v2 and simplifying response parsing logic. [1] [2]TypeAdapterimport to client templates. [1] [2]Schema Property Enhancements:
Literal[...]types with defaults in model properties for improved type safety and clarity.Debugging and Template Configuration:
operation_is_sseto aid debugging of response status conversion issues.select_autoescape, improving template safety.These changes collectively improve the robustness and clarity of generated Python clients and models, particularly for OpenAPI schemas with complex union and discriminated types.