-
-
Notifications
You must be signed in to change notification settings - Fork 339
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: schema for generic wrapped return types with DTO #3371
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3371 +/- ##
=======================================
Coverage 98.28% 98.28%
=======================================
Files 323 323
Lines 14773 14777 +4
Branches 2345 2347 +2
=======================================
+ Hits 14519 14523 +4
Misses 116 116
Partials 138 138 ☔ View full report in Codecov by Sentry. |
6b3a18d
to
aa57371
Compare
Adds failing test. Closes #2929
Prior behavior of using the `backend.annotation` as the basis for generating the openapi schema for the represented type is not applicable for the case where the DTO supported type is wrapped in a generic outer object. This PR detects the case where we unwrap an outer generic type, and rebuilds the generic annotation in a manner appropriate for schema generation, before generating the schema for the annotation. It does this by substituting the DTOs transfer model for the original model in the original annotations type arguments. This is really treating a symptom of the generic outer type being removed from the annotation before the DTO backend receives it, which is a design flaw that adds quite a bit of complexity. The DTOs should treat annotations at a whole, rebuild the complete annotation substituting out any supported types found within with transfer models. Also, we don't really have a need for a separate backend anymore, now that we are only supporting one serialization library (backend were introduced when we were trying to support either pydantic or msgspec (and attrs?) throughout the whole application.
aa57371
to
8a209c6
Compare
Quality Gate passedIssues Measures |
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3371 |
* fix: Fix schema for generic wrapped return types with DTO Adds failing test. Closes #2929 * fix: remove redundant type var * fix: fix openapi schema for generic return types with dto Prior behavior of using the `backend.annotation` as the basis for generating the openapi schema for the represented type is not applicable for the case where the DTO supported type is wrapped in a generic outer object. This PR detects the case where we unwrap an outer generic type, and rebuilds the generic annotation in a manner appropriate for schema generation, before generating the schema for the annotation. It does this by substituting the DTOs transfer model for the original model in the original annotations type arguments. This is really treating a symptom of the generic outer type being removed from the annotation before the DTO backend receives it, which is a design flaw that adds quite a bit of complexity. The DTOs should treat annotations at a whole, rebuild the complete annotation substituting out any supported types found within with transfer models. Also, we don't really have a need for a separate backend anymore, now that we are only supporting one serialization library (backend were introduced when we were trying to support either pydantic or msgspec (and attrs?) throughout the whole application. * test: add another test. (cherry picked from commit 40a5685)
* fix: Fix schema for generic wrapped return types with DTO Adds failing test. Closes #2929 * fix: remove redundant type var * fix: fix openapi schema for generic return types with dto Prior behavior of using the `backend.annotation` as the basis for generating the openapi schema for the represented type is not applicable for the case where the DTO supported type is wrapped in a generic outer object. This PR detects the case where we unwrap an outer generic type, and rebuilds the generic annotation in a manner appropriate for schema generation, before generating the schema for the annotation. It does this by substituting the DTOs transfer model for the original model in the original annotations type arguments. This is really treating a symptom of the generic outer type being removed from the annotation before the DTO backend receives it, which is a design flaw that adds quite a bit of complexity. The DTOs should treat annotations at a whole, rebuild the complete annotation substituting out any supported types found within with transfer models. Also, we don't really have a need for a separate backend anymore, now that we are only supporting one serialization library (backend were introduced when we were trying to support either pydantic or msgspec (and attrs?) throughout the whole application. * test: add another test. (cherry picked from commit 40a5685)
* fix: Fix schema for generic wrapped return types with DTO Adds failing test. Closes #2929 * fix: remove redundant type var * fix: fix openapi schema for generic return types with dto Prior behavior of using the `backend.annotation` as the basis for generating the openapi schema for the represented type is not applicable for the case where the DTO supported type is wrapped in a generic outer object. This PR detects the case where we unwrap an outer generic type, and rebuilds the generic annotation in a manner appropriate for schema generation, before generating the schema for the annotation. It does this by substituting the DTOs transfer model for the original model in the original annotations type arguments. This is really treating a symptom of the generic outer type being removed from the annotation before the DTO backend receives it, which is a design flaw that adds quite a bit of complexity. The DTOs should treat annotations at a whole, rebuild the complete annotation substituting out any supported types found within with transfer models. Also, we don't really have a need for a separate backend anymore, now that we are only supporting one serialization library (backend were introduced when we were trying to support either pydantic or msgspec (and attrs?) throughout the whole application. * test: add another test. (cherry picked from commit 40a5685)
* fix: Fix schema for generic wrapped return types with DTO Adds failing test. Closes #2929 * fix: remove redundant type var * fix: fix openapi schema for generic return types with dto Prior behavior of using the `backend.annotation` as the basis for generating the openapi schema for the represented type is not applicable for the case where the DTO supported type is wrapped in a generic outer object. This PR detects the case where we unwrap an outer generic type, and rebuilds the generic annotation in a manner appropriate for schema generation, before generating the schema for the annotation. It does this by substituting the DTOs transfer model for the original model in the original annotations type arguments. This is really treating a symptom of the generic outer type being removed from the annotation before the DTO backend receives it, which is a design flaw that adds quite a bit of complexity. The DTOs should treat annotations at a whole, rebuild the complete annotation substituting out any supported types found within with transfer models. Also, we don't really have a need for a separate backend anymore, now that we are only supporting one serialization library (backend were introduced when we were trying to support either pydantic or msgspec (and attrs?) throughout the whole application. * test: add another test. (cherry picked from commit 40a5685)
Changelog
Fix schema generated for DTOs where the supported type is wrapped in a generic outer type.
Description
Prior behavior of using the
backend.annotation
as the basis for generating the openapi schema for the represented type is not applicable for the case where the DTO supported type is wrapped in a generic outer object. In that casebackend.annotation
only represents the type of the attribute on the generic type that holds the DTO supported type annotation.This PR detects the case where we unwrap an outer generic type, and rebuilds the generic annotation in a manner appropriate for schema generation, before generating the schema for the annotation. It does this by substituting the DTOs transfer model for the original model in the original annotations type arguments.
<tangent>
This is really treating a symptom of the generic outer type being removed from the annotation before the DTO backend receives it, which is a design flaw that adds quite a bit of complexity. The DTOs should treat annotations at a whole, rebuild the complete annotation substituting out any supported types found within with transfer models.
Also, we don't really have a need for a separate backend anymore, now that we are only supporting one serialization library (backends were introduced when we were trying to support either pydantic or msgspec (and attrs?)) throughout the whole application.
</tangent>
Closes
Closes #2929