Skip to content
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

Conversation

javibookline
Copy link

@javibookline javibookline commented Mar 14, 2023

… 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

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @samuelcolvin

@javibookline
Copy link
Author

please review

@dmontagu
Copy link
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.

@dmontagu dmontagu merged commit f99a0e2 into pydantic:1.10.X-fixes Mar 14, 2023
@dmontagu
Copy link
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 added a commit to allenporter/flux-local that referenced this pull request Mar 24, 2023
[![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,
[#&#8203;5223](https://togithub.com/pydantic/pydantic/issues/5223) by
[@&#8203;matejetz](https://togithub.com/matejetz)
- Address bug in mypy plugin caused by explicit_package_bases=True,
[#&#8203;5191](https://togithub.com/pydantic/pydantic/issues/5191) by
[@&#8203;dmontagu](https://togithub.com/dmontagu)
- Add implicit defaults in the mypy plugin for Field with no default
argument,
[#&#8203;5190](https://togithub.com/pydantic/pydantic/issues/5190) by
[@&#8203;dmontagu](https://togithub.com/dmontagu)
- Fix schema generated for Enum values used as Literals in discriminated
unions,
[#&#8203;5188](https://togithub.com/pydantic/pydantic/issues/5188) by
[@&#8203;javibookline](https://togithub.com/javibookline)
- Fix mypy failures caused by the pydantic mypy plugin when users define
`from_orm` in their own classes,
[#&#8203;5187](https://togithub.com/pydantic/pydantic/issues/5187) by
[@&#8203;dmontagu](https://togithub.com/dmontagu)
- Fix `InitVar` usage with pydantic dataclasses, mypy version `1.1.1`
and the custom mypy plugin,
[#&#8203;5162](https://togithub.com/pydantic/pydantic/issues/5162) by
[@&#8203;cdce8p](https://togithub.com/cdce8p)

#### New Contributors

- [@&#8203;javibookline](https://togithub.com/javibookline) made their
first contribution in
[pydantic/pydantic#5188
- [@&#8203;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>
renovate bot added a commit to allenporter/pyrainbird that referenced this pull request Mar 24, 2023
[![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,
[#&#8203;5223](https://togithub.com/pydantic/pydantic/issues/5223) by
[@&#8203;matejetz](https://togithub.com/matejetz)
- Address bug in mypy plugin caused by explicit_package_bases=True,
[#&#8203;5191](https://togithub.com/pydantic/pydantic/issues/5191) by
[@&#8203;dmontagu](https://togithub.com/dmontagu)
- Add implicit defaults in the mypy plugin for Field with no default
argument,
[#&#8203;5190](https://togithub.com/pydantic/pydantic/issues/5190) by
[@&#8203;dmontagu](https://togithub.com/dmontagu)
- Fix schema generated for Enum values used as Literals in discriminated
unions,
[#&#8203;5188](https://togithub.com/pydantic/pydantic/issues/5188) by
[@&#8203;javibookline](https://togithub.com/javibookline)
- Fix mypy failures caused by the pydantic mypy plugin when users define
`from_orm` in their own classes,
[#&#8203;5187](https://togithub.com/pydantic/pydantic/issues/5187) by
[@&#8203;dmontagu](https://togithub.com/dmontagu)
- Fix `InitVar` usage with pydantic dataclasses, mypy version `1.1.1`
and the custom mypy plugin,
[#&#8203;5162](https://togithub.com/pydantic/pydantic/issues/5162) by
[@&#8203;cdce8p](https://togithub.com/cdce8p)

#### New Contributors

- [@&#8203;javibookline](https://togithub.com/javibookline) made their
first contribution in
[pydantic/pydantic#5188
- [@&#8203;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>
@javibookline javibookline deleted the discriminated-union-literal-enum-values branch December 13, 2023 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants