You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use pydantic with FastApi and have a model which contains an ImportString field associated with an endpoint and found that the openapi docs generation failed due to ImportString. Underlying issue is that pydantic could not create JsonSchema for the object, the error looks like:
raise PydanticInvalidForJsonSchema(f'Cannot generate a JsonSchema for {error_info}')
pydantic.errors.PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.PlainValidatorFunctionSchema ({'type': 'no-info', 'function': <function import_string at 0x105a2c360>})
A workaround was to create a type-annotated version:
ImportString=Annotated[
pydantic.ImportString, pydantic.WithJsonSchema({'type': 'string', 'description': 'fully qualified class name'})
]
I'm not sure if this is intended, but the docs don't seem to explicitly mention the json schema serialization.
Example Code
# Issue was in FastApi docs generation, but the below produces an error that # looks the sameimportpydanticpydantic.TypeAdapter(pydantic.ImportString).json_schema()
Initial Checks
Description
We use pydantic with FastApi and have a model which contains an
ImportString
field associated with an endpoint and found that the openapi docs generation failed due toImportString
. Underlying issue is that pydantic could not create JsonSchema for the object, the error looks like:A workaround was to create a type-annotated version:
I'm not sure if this is intended, but the docs don't seem to explicitly mention the json schema serialization.
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: