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

fix: map JSONSchema spec naming convention to snake_case when names from schema_extra are not found (#3766) #3767

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

charles-dyfis-net
Copy link
Contributor

…when property names from schema_extra are not found.

Description

Address rejection of schema_extra values using JSONSchema spec-compliant key names by mapping between the relevant naming conventions.

Closes

Fixes #3766

@github-actions github-actions bot added area/private-api This PR involves changes to the privatized API size: small pr/external Triage Required 🏥 This requires triage labels Sep 30, 2024
@charles-dyfis-net charles-dyfis-net changed the title Attempt to map JSONSchema spec naming convention to local naming convention fix: Attempt to map JSONSchema spec naming convention to local naming convention Sep 30, 2024
@charles-dyfis-net charles-dyfis-net changed the title fix: Attempt to map JSONSchema spec naming convention to local naming convention fix: attempt to map JSONSchema spec naming convention to local naming convention Sep 30, 2024
@charles-dyfis-net charles-dyfis-net marked this pull request as ready for review September 30, 2024 03:04
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.34%. Comparing base (1e55ef3) to head (40b0b71).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3767      +/-   ##
==========================================
- Coverage   98.35%   98.34%   -0.02%     
==========================================
  Files         332      332              
  Lines       15460    15472      +12     
  Branches     2460     2464       +4     
==========================================
+ Hits        15206    15216      +10     
- Misses        112      113       +1     
- Partials      142      143       +1     

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

Copy link
Member

@provinzkraut provinzkraut left a comment

Choose a reason for hiding this comment

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

Thanks for reporting this and submitting a fix @charles-dyfis-net!

I'm not a fan of these regex based renaming solutions, as they can be tricky to maintain in some cases. I would prefer a more explicit approach. We could use dataclasses.field to provide an alias via metadata (e.g. multiple_of: float | None = field(metadata={"alias": "multipleOf"})

@charles-dyfis-net
Copy link
Contributor Author

Thanks for reporting this and submitting a fix @charles-dyfis-net!

I'm not a fan of these regex based renaming solutions, as they can be tricky to maintain in some cases. I would prefer a more explicit approach. We could use dataclasses.field to provide an alias via metadata (e.g. multiple_of: float | None = field(metadata={"alias": "multipleOf"})

A wise objection -- going through the items one-at-a-time, there are some fixups (like schema_not) that the regex wouldn't have handled correctly.

@provinzkraut provinzkraut changed the title fix: attempt to map JSONSchema spec naming convention to local naming convention fix: map JSONSchema spec naming convention to snake_case when names from schema_extra are not found (#3766) Oct 3, 2024
@provinzkraut provinzkraut enabled auto-merge (squash) October 3, 2024 17:05
@provinzkraut provinzkraut merged commit e7dfc7a into litestar-org:main Oct 3, 2024
25 checks passed
Copy link

github-actions bot commented Oct 3, 2024

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3767

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/private-api This PR involves changes to the privatized API pr/external pr/internal size: small Triage Required 🏥 This requires triage type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: schema_extra does not recognize upstream JSONSchema property/key names
2 participants