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

refactor(schema): support properly Literal in generated JSON schema #2348

Merged
merged 6 commits into from
Feb 25, 2021

Conversation

PrettyWood
Copy link
Member

@PrettyWood PrettyWood commented Feb 12, 2021

Change Summary

Currently we don't support properly Literal with multi values
Following this comment I feel like it could be good to support them properly.
Using enum even with one value should not have any impact and work everywhere since const is just syntactic sugar for enum with a single element (see ref)

ReDoc

BEFORE AFTER
q: Literal["pika"] redoc_one_literal_before Screen Shot 2021-02-14 at 12 13 52 AM
q: Literal["pika", Literal["chu"]] redoc_many_literals_before redoc_many_literals_after

Swagger

BEFORE AFTER
q: Literal["pika"] swagger_one_literal_before swagger_one_literal_after
q: Literal["pika", Literal["chu"]] swagger_many_literals_before swagger_many_literals_after

Related issue number

Closes #1350

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)

@codecov
Copy link

codecov bot commented Feb 12, 2021

Codecov Report

Merging #2348 (cd49fa9) into master (b7a8ef2) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #2348   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         4485      4489    +4     
  Branches       909       910    +1     
=========================================
+ Hits          4485      4489    +4     
Impacted Files Coverage Δ
pydantic/typing.py 100.00% <ø> (ø)
pydantic/schema.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b7a8ef2...c78e37b. Read the comment docs.

'a': {'title': 'A', 'type': 'integer', 'enum': [1]},
'b': {'title': 'B', 'type': 'string', 'enum': ['a']},
'c': {'title': 'C', 'anyOf': [{'type': 'string', 'enum': ['a']}, {'type': 'integer', 'enum': [1]}]},
'd': {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth comparing with the first commit 3a14c72 😉

@samuelcolvin samuelcolvin merged commit ededd3e into pydantic:master Feb 25, 2021
@samuelcolvin
Copy link
Member

great, thank you. 🙇 🐗

@PrettyWood PrettyWood deleted the literal-schema branch February 25, 2021 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-value Literal isn't compliant with OpenAPI
2 participants