-
-
Notifications
You must be signed in to change notification settings - Fork 347
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): set default on schema from FieldDefinition
#3280
Conversation
This does raise an interesting condition that we don't currently handle. def get_foo(foo: Annotated[int, Parameter(default=20)] = 12) -> None:
.... In this case, the default in the generated schema would be |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3280 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 320 320
Lines 14448 14450 +2
Branches 2296 2297 +1
=======================================
+ Hits 14193 14195 +2
Misses 114 114
Partials 141 141 ☔ View full report in Codecov by Sentry. |
Good catch! Yeah, that should be an error on startup. I'd go even further as to now allow specifying defaults in two places to begin with. A default in |
Consider the following: ```python def get_foo(foo_id: int = 10) -> None: ... ``` In such cases, no `KwargDefinition` is created since there is no metadata provided via `Annotated`. The default is still parsed, and set on the generated `FieldDefinition`, however the `SchemaCreator` currently only considers defaults that are set on `KwargDefinition`. So in such cases, we should fallback to the default set on the `FieldDefinition` if there is a valid default value.
8f64501
to
35c4825
Compare
|
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3280 |
Consider the following: ```python def get_foo(foo_id: int = 10) -> None: ... ``` In such cases, no `KwargDefinition` is created since there is no metadata provided via `Annotated`. The default is still parsed, and set on the generated `FieldDefinition`, however the `SchemaCreator` currently only considers defaults that are set on `KwargDefinition`. So in such cases, we should fallback to the default set on the `FieldDefinition` if there is a valid default value.
Description
Consider the following:
In such cases, no
KwargDefinition
is created since there is no metadata provided viaAnnotated
. The default is still parsed, and set on the generatedFieldDefinition
, however theSchemaCreator
currently only considers defaults that are set onKwargDefinition
.So in such cases, we should fallback to the default set on the
FieldDefinition
if there is a valid default value.Closes
Fixes #3278.