Enhance Open API schema generation for pydantic response models #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Enhance pydantic model schema generation
model_schema
function inquart-schema/src/quart-schema/conversion.py
calledschema_mode
that will execute the TypeAdapter schema generation in the selected mode. Keep the same default of "validation".Added tests that demonstrate a very simple use case where you are using computed fields on a pydantic model:
The last assert (
assert "fullName" in response_properties
) will fail in the current version of quart schema as computed fields are only added to the JSON schema when the mode is set to "serialization" and the default for the pydanticTypeAdapter
is "validation". This makes sense for data models being sent to the server where we can just re-generate the computed field so there is no need to include these fields in the incoming JSON. For responses however, it makes sense to include the computed field value as there may be custom serialization occurring that is non-trivial to re-implement on the client side.