-
-
Notifications
You must be signed in to change notification settings - Fork 402
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: recursive schema generation #2869
Conversation
This PR adopts OpenAPISchemaPlugin for generation of schemas for all supported model types.
This PR modifies the way we generate schemas for objects that should be able to be referenced by other schemas. It adds a new method to `SchemaCreator` called `create_component_schema` that should be used to create a schema that should be able to be referenced by other schemas, and itself. This method takes care to first create the schema in the registry so that it can be immediately referenced. In `SchemaCreator.for_field_definition()`, before we generate a schema for any plugin-supported type, we first check whether a reference can be made to an already existing schema and return that if possible. Closes #2429
8b4de0d
to
33b829a
Compare
Fixes an error where types such as `UnionType` do not have a `__qualname__` by ensuring we handle the union type annotation before we attempt to apply plugin handling to the type.
# Conflicts: # litestar/_openapi/schema_generation/plugins/dataclass.py # litestar/_openapi/schema_generation/plugins/struct.py # litestar/_openapi/schema_generation/plugins/typed_dict.py # litestar/_openapi/schema_generation/schema.py # litestar/plugins/base.py
If we don't do this, then users won't have the chance to add a plugin that might override our handling of a collection type etc.
The condition where the schema type is a sequence is possible accoring to the schema spec, however in the TYPE_MAP, we don't have any types where the schema type is a sequence.
For some reason, sonar is pinging me for coverage lines and conditions that have nothing to do with this PR :/ |
We have this thing called a `SchemaDataContainer` that is untested, and undocumented. Sonar is reporting the missing coverage on this because I've modified the method, but I have no clue what this thing is, or does.
At this point I'm just guessing WTH sonar is asking for.
could you get coverage up a bit? |
|
|
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2869 |
This PR modifies the way we generate schemas for objects that should be able to be referenced by other schemas.
It adds a new method to
SchemaCreator
calledcreate_component_schema
that should be used to create a schema that should be able to be referenced by other schemas, and itself.This method takes care to first create the schema in the registry so that it can be immediately referenced.
In
SchemaCreator.for_field_definition()
, before we generate a schema for any plugin-supported type, we first check whether a reference can be made to an already existing schema and return that if possible.Closes #2429