chore: add support for non-discriminator, oneOf query parameters#190
Conversation
- Update `model_oneof.mustache` to generate a type alias rather than a container class when a `oneOf` construct does not use a discriminator. This allows additional types to be used for query parameters without breaking backward compatibility. - Update `partial_api_args.mustache` to generate type annotations for parameters that use `oneOf` construct without a discriminator. - Update `api.mustache` to handle query parameters that use a union type when their schema is a `oneOf` construct without a discriminator. - Update `model_doc.mustache` to document that a `oneOf` construct without a discriminator is a type alias.
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified FilesNo covered modified files...
|
There was a problem hiding this comment.
Pull request overview
This PR updates the OpenAPI generator templates to support oneOf query parameters that don't use a discriminator, generating a Python type alias (Union[...]) instead of a container class. This enables expanding accepted parameter types (e.g. allowing both date and date-time for start/end) without breaking backward compatibility.
Changes:
model_oneof.mustachenow emits aUniontype alias for non-discriminatoroneOfschemas.api.mustacheandpartial_api_args.mustachegenerate proper imports, type annotations, and runtime serialization branches (datetime/date/other) for union-typed query parameters.model_doc.mustachedocuments the generated type alias.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| template/model_oneof.mustache | Generate Union type alias instead of model class for non-discriminator oneOf. |
| template/partial_api_args.mustache | Emit Annotated[Optional[...]] type hints for oneOf composed-schema params. |
| template/api.mustache | Add union-imports workaround and runtime serialization branch for oneOf query params. |
| template/model_doc.mustache | Document non-discriminator oneOf as a type alias. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
erayaydin
left a comment
There was a problem hiding this comment.
LGTM. Just added a couple of notes. Looks like the Server API can parse it with or without the colon in the current usage
erayaydin
left a comment
There was a problem hiding this comment.
I think assuming the timezone info could lead to issues, so I submitted a request change. Happy to discuss it further 😇
- Update `model_oneof` template to use AwareDatetime to require oneOf parameters to have a timezone. - Update `api` template to assume a timezone is set on the datetime query parameter.
pnpm exec changesetto create a changeset. |
This PR updates the handling for
oneOfconstructs that do not use a discriminator to allow query parameters to use a union type to expand the accepted types for a parameter without breaking backward compatibility. This functionality will be used for the pending changes to expandstartandendto accept adate-timestring.These template updates do not add JSON serialization and deserialization support for the generated type alias for a union type because that functionality is not yet needed.
Itemized changes:
model_oneof.mustacheto generate a type alias rather than a container class when aoneOfconstruct does not use a discriminator. This allows additional types to be used for query parameters without breaking backward compatibility.partial_api_args.mustacheto generate type annotations for parameters that useoneOfconstruct without a discriminator.api.mustacheto handle query parameters that use a union type when their schema is aoneOfconstruct without a discriminator.model_doc.mustacheto document that aoneOfconstruct without a discriminator is a type alias.See #191 for the code generated after these template updates and the schema is updated to use a
oneOfforstartandend.