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(OpenAPI): Ensure default values are always represented in schema for dataclasses and msgspec.Structs #3285

Merged
merged 3 commits into from Mar 29, 2024

Conversation

provinzkraut
Copy link
Member

Fix a bug that would prevent default values for dataclasses and msgspec.Struct`s to be included in the OpenAPI schema.

@dataclass
class SomeModel:
    field_a: str = "default_a"
    field_b: str = dataclasses.field(default="default_b")

and

class SomeModel(msgspec.Struct, kw_only=True):
    field_a: str = "default_a"
    field_b: str = msgspec.field(default="default_b")

now generate correct schemas in all cases.

Fix #3201.

@provinzkraut provinzkraut requested review from a team as code owners March 29, 2024 14:33
@provinzkraut provinzkraut force-pushed the fix-dataclasses-and-struct-schema-defaults branch from d5f83e3 to 074d73f Compare March 29, 2024 14:41
Copy link

codecov bot commented Mar 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.23%. Comparing base (62f2cee) to head (074d73f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3285   +/-   ##
=======================================
  Coverage   98.23%   98.23%           
=======================================
  Files         320      320           
  Lines       14451    14454    +3     
  Branches     2297     2297           
=======================================
+ Hits        14196    14199    +3     
  Misses        114      114           
  Partials      141      141           

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

@provinzkraut provinzkraut enabled auto-merge (squash) March 29, 2024 14:46
Copy link

sonarcloud bot commented Mar 29, 2024

@provinzkraut provinzkraut merged commit 8867429 into main Mar 29, 2024
21 checks passed
@provinzkraut provinzkraut deleted the fix-dataclasses-and-struct-schema-defaults branch March 29, 2024 14:47
Copy link

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

cofin pushed a commit that referenced this pull request Apr 1, 2024
…for dataclasses and `msgspec.Struct`s (#3285)

* Fix dataclass and struct default value support
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.

Bug: default not generated in OpenAPI schema for body as models
3 participants