fix: #1530 support discriminator with multiple mappings of same schema#1789
fix: #1530 support discriminator with multiple mappings of same schema#1789mgabeler-lee-6rs wants to merge 14 commits into
Conversation
|
Maintainers / @mgabeler-lee-6rs what is the plan for this PR? |
|
I've been using this PR in my production app for some time now with good results. It's not perfect, it's vulnerable to GIGO if you have an invalid OAS spec, but no worse than the released code. Contribution guidelines explicitly request not tagging maintainers directly 🤷♂️ |
|
would like to see this merged |
|
this PR would solve my problems 😸 |
I haven't seen that issue personally, so I can't say for sure. Probably the easiest way to find out is to just try it 🙂 |
|
I have the same issue as @lukasbash and this PR doesn't fix the issue for me |
|
@champtar or @lukasbash can you share a repro for the issue you're seeing? |
|
@mgabeler-lee-6rs here a minimal reproducer that break with v2.4.1 |
|
@champtar I tried adding that as a test case on this branch and it produces compiling code not showing the pattern lukasbash reported. This seems to be in part because your example didn't include a definition for the Assigning an untyped string constant to a type that is defined as a string ... is not an error. Do you have some more complex setup outside your minimal repro where the discriminator field type is generated as something other than Edited to add: Your example is additionally invalid because you are defining a discriminator property on an (implicitly) object schema, but the two discriminator possibilities both then say that it is not an object, so your schema is unsatisfiable. |
|
I've pushed up an adapted version of your example case, with the valid code it creates. If you can find further adjustments that show it producing invalid code, I'm happy to improve the PR :) |
|
@mgabeler-lee-6rs my example might be invalid, but it pass online validators like https://editor.swagger.io/ :( I was trying to construct a minimal example and not share 5k lines of spec, here a better one actually closer to the spec I'm trying to deal with Basically the spec I'm dealing with is missing the https://spec.openapis.org/oas/v3.1.0.html#fixed-fields-20 |
|
Aah, a schema with the discriminator field optional. So the issue isn't about using an untyped string constant, but rather using a string instead of a pointer to a string ✔️ I'll see if I can update this PR to handle that better. However it might be necessary to simply add |
|
How I read the spec (https://spec.openapis.org/oas/v3.1.0.html#fixed-fields-20) the field MUST be present, is there a notion of implicit |
|
It certainly reads kinda like it's an implicit required, but I'm not completely clear on that. I've got something half-way working to process this, but the challenge I'm running into is that the point at which we are rendering the code that needs to know the type of e.g. I've pushed up what I can do to make this better without invasive surgery, and the test example now shows the two options for how to get your example schema to generate valid code. |
|
@mgabeler-lee-6rs FYI in 3.1.1 it's clearer https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.1.md#fixed-fields-22
|
|
even more clear definition of said behavior will be available in the upcoming OAS 3.2 minor release slated for Summer '25. That doesn't fix the older versions, but it definitely provides direction for implementations which is backwards compatible with earlier versions. |
Kusari Analysis ResultsAnalysis for commit: 2fef48e, performed at: 2025-07-16T14:00:57Z • • Recommendation✅ PROCEED with this Pull Request Summary✅ No Flagged Issues Detected All values appear to be within acceptable risk parameters. No pinned version dependency changes, code issues or exposed secrets detected! Found this helpful? Give it a 👍 or 👎 reaction! |
|
Thank you for submitting this PR, @mgabeler-lee-6rs — but we need to close it because the core fix landed independently via #2071 (commit Thanks for the contribution and for diagnosing the root cause. |

This is an improved version of @jKiler's #1534. Credit to them for getting this started.
My main addition is getting the codegen for
FromFooandMergeFooto work better in this situation.