-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discriminated union literal enum values #5188
Discriminated union literal enum values #5188
Conversation
… values as literals. Use enum value in schema mapping instead of enum object.
please review |
@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. |
@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) |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](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` | [![age](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/compatibility-slim/1.10.6)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/confidence-slim/1.10.6)](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 [pydantic/pydantic#5188 - [@​matejetz](https://togithub.com/matejetz) made their first contribution in [pydantic/pydantic#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>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](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` | [![age](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/compatibility-slim/1.10.6)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/confidence-slim/1.10.6)](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 [pydantic/pydantic#5188 - [@​matejetz](https://togithub.com/matejetz) made their first contribution in [pydantic/pydantic#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>
… 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>.md
file added describing change(see changes/README.md for details)
Selected Reviewer: @samuelcolvin