[WIP] Fix generated schemas for oneOf types to preserve type discriminators#3296
Closed
[WIP] Fix generated schemas for oneOf types to preserve type discriminators#3296
Conversation
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
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.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original prompt
This section details on the original issue you should resolve
<issue_title>Write schemas generated for oneOf types override type discriminator values</issue_title>
<issue_description>### Description
When
@hey-api/openapi-tsgenerates TypeScript types from an OpenAPI spec containing polymorphic types withreadOnlyproperties, it creates "Writable" variants with incorrecttypeDiscriminatorvalues.The generated types use a PascalCase discriminator derived from the type name (e.g.,
'DogPayloadWritable') instead of preserving the discriminator value from the OpenAPI spec (e.g.,'dog').This causes deserialization failures in the backend that still expects the original type discriminators it has defined.
Interestingly enough, this issue wasn't present in @hey-api/openapi-ts 0.84.4, which I suppose might have been due to writable types not being generated properly with polymorphic types so this bug never surfaced itself because of that.
Reproducible example or configuration
Environment
@hey-api/openapi-ts: v0.90.10Reproduction
.NET models
Generated TS Read types (correct)
Generated TS Writable types (incorrect):
OpenAPI specification (optional)
OpenAPI Schema (Backend)
System information (optional)
No response</issue_description>
Comments on the Issue (you are @copilot in this section)
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.