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

Customize JSON schema generation for Literal fields of Pydantic models #227

Closed
wants to merge 2 commits into from

Conversation

candleindark
Copy link
Member

This PR adds customization to the generation of JSON schema for the fields of Pydantic models that are of Literal type. Basically, this customization ensures that the JSON schema for a Literal field of a Pydantic model has a type key.

This customization revert change 3v entailed by Pydantic V2 listed in the top post of #203. Hopefully, it will also satisfy @satra's request at dandi/dandi-archive@b3db231#commitcomment-138484018.

So that `Literal` types of a single value will also
have a JSON schema that has a `"type"` key with
the value of the type of the single value.
This behavior is the one exhibited in Pydantic V1.
@candleindark candleindark requested a review from satra February 10, 2024 06:18
Copy link

codecov bot commented Feb 10, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (08d92c8) 97.66% compared to head (8e24b33) 91.57%.

Files Patch % Lines
dandischema/utils.py 47.05% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #227      +/-   ##
==========================================
- Coverage   97.66%   91.57%   -6.10%     
==========================================
  Files          18       18              
  Lines        1799     1816      +17     
==========================================
- Hits         1757     1663      -94     
- Misses         42      153     +111     
Flag Coverage Δ
unittests 91.57% <50.00%> (-6.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

candleindark referenced this pull request in dandi/dandi-archive Feb 12, 2024
Pydantic 2.0's JSON schema export no longer specifies a `type` field for
the `schemaKey` property, and leaves it undefined instead. This change
makes it so an undefined type also delegates it as a "basic schema",
meaning it will not be rendered as its own tab in the meditor.
@candleindark
Copy link
Member Author

As stated in dandi/dandi-archive@b3db231#commitcomment-138536168, this PR is really not needed at all if the UI is able to construed the type of the value from the expression of the value in JSON.

@candleindark
Copy link
Member Author

This PR is not needed per dandi/dandi-archive@b3db231#commitcomment-138536466.

@candleindark candleindark deleted the literal-type branch February 12, 2024 16:07
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.

1 participant