Discriminated union literal enum values#5188
Merged
dmontagu merged 4 commits intopydantic:1.10.X-fixesfrom Mar 14, 2023
Merged
Conversation
… values as literals. Use enum value in schema mapping instead of enum object.
Author
|
please review |
Contributor
|
@javibookline this looks great. I also added your test to v2 and it seems to do the right thing there already (the schema looks a bit different but I think should still work properly with OpenAPI), so I think we can close #4337 after merging this. |
Contributor
|
@javibookline for what it's worth, you can see the schema produced in v2 in this commit, where I've added your test with appropriate modifications: 14e9b2f (This is as part of #5051) |
renovate Bot
referenced
this pull request
in allenporter/flux-local
Mar 24, 2023
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [pydantic](https://togithub.com/pydantic/pydantic) | `==1.10.6` -> `==1.10.7` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>pydantic/pydantic</summary> ### [`v1.10.7`](https://togithub.com/pydantic/pydantic/releases/tag/v1.10.7): 2023-03-22 [Compare Source](https://togithub.com/pydantic/pydantic/compare/v1.10.6...v1.10.7) #### What's Changed - Fix creating schema from model using `ConstrainedStr` with `regex` as dict key, [#​5223](https://togithub.com/pydantic/pydantic/issues/5223) by [@​matejetz](https://togithub.com/matejetz) - Address bug in mypy plugin caused by explicit_package_bases=True, [#​5191](https://togithub.com/pydantic/pydantic/issues/5191) by [@​dmontagu](https://togithub.com/dmontagu) - Add implicit defaults in the mypy plugin for Field with no default argument, [#​5190](https://togithub.com/pydantic/pydantic/issues/5190) by [@​dmontagu](https://togithub.com/dmontagu) - Fix schema generated for Enum values used as Literals in discriminated unions, [#​5188](https://togithub.com/pydantic/pydantic/issues/5188) by [@​javibookline](https://togithub.com/javibookline) - Fix mypy failures caused by the pydantic mypy plugin when users define `from_orm` in their own classes, [#​5187](https://togithub.com/pydantic/pydantic/issues/5187) by [@​dmontagu](https://togithub.com/dmontagu) - Fix `InitVar` usage with pydantic dataclasses, mypy version `1.1.1` and the custom mypy plugin, [#​5162](https://togithub.com/pydantic/pydantic/issues/5162) by [@​cdce8p](https://togithub.com/cdce8p) #### New Contributors - [@​javibookline](https://togithub.com/javibookline) made their first contribution in [https://github.com/pydantic/pydantic/pull/5188](https://togithub.com/pydantic/pydantic/pull/5188) - [@​matejetz](https://togithub.com/matejetz) made their first contribution in [https://github.com/pydantic/pydantic/pull/5223](https://togithub.com/pydantic/pydantic/pull/5223) **Full Changelog**: pydantic/pydantic@v1.10.6...v1.10.7 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/allenporter/flux-local). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNy4xIiwidXBkYXRlZEluVmVyIjoiMzUuMTcuMSJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate Bot
referenced
this pull request
in allenporter/pyrainbird
Mar 24, 2023
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [pydantic](https://togithub.com/pydantic/pydantic) | `==1.10.6` -> `==1.10.7` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>pydantic/pydantic</summary> ### [`v1.10.7`](https://togithub.com/pydantic/pydantic/releases/tag/v1.10.7): 2023-03-22 [Compare Source](https://togithub.com/pydantic/pydantic/compare/v1.10.6...v1.10.7) #### What's Changed - Fix creating schema from model using `ConstrainedStr` with `regex` as dict key, [#​5223](https://togithub.com/pydantic/pydantic/issues/5223) by [@​matejetz](https://togithub.com/matejetz) - Address bug in mypy plugin caused by explicit_package_bases=True, [#​5191](https://togithub.com/pydantic/pydantic/issues/5191) by [@​dmontagu](https://togithub.com/dmontagu) - Add implicit defaults in the mypy plugin for Field with no default argument, [#​5190](https://togithub.com/pydantic/pydantic/issues/5190) by [@​dmontagu](https://togithub.com/dmontagu) - Fix schema generated for Enum values used as Literals in discriminated unions, [#​5188](https://togithub.com/pydantic/pydantic/issues/5188) by [@​javibookline](https://togithub.com/javibookline) - Fix mypy failures caused by the pydantic mypy plugin when users define `from_orm` in their own classes, [#​5187](https://togithub.com/pydantic/pydantic/issues/5187) by [@​dmontagu](https://togithub.com/dmontagu) - Fix `InitVar` usage with pydantic dataclasses, mypy version `1.1.1` and the custom mypy plugin, [#​5162](https://togithub.com/pydantic/pydantic/issues/5162) by [@​cdce8p](https://togithub.com/cdce8p) #### New Contributors - [@​javibookline](https://togithub.com/javibookline) made their first contribution in [https://github.com/pydantic/pydantic/pull/5188](https://togithub.com/pydantic/pydantic/pull/5188) - [@​matejetz](https://togithub.com/matejetz) made their first contribution in [https://github.com/pydantic/pydantic/pull/5223](https://togithub.com/pydantic/pydantic/pull/5223) **Full Changelog**: pydantic/pydantic@v1.10.6...v1.10.7 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/allenporter/pyrainbird). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNy4xIiwidXBkYXRlZEluVmVyIjoiMzUuMTcuMSJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.
… values as literals. Use enum value in schema mapping instead of enum object.
Change Summary
Fix an issue where schema for discriminated unions using Literal Enum values where not generated properly. Enum reprs where used where Enum values should be used.
Related issue number
Issue #4337 - not sure if it should be closed as it was added to Version 2 Milestone.
Checklist
changes/<pull request or issue id>-<github username>.mdfile added describing change(see changes/README.md for details)
Selected Reviewer: @samuelcolvin