Browse Source

️ Revert usage of custom logic for TypeAdapter JSON Schema, solved on the Pydantic side (#9787)

️ Revert usage of custom logic for TypeAdapter JSON Schema, solved on Pydantic side
pull/9795/head
Sebastián Ramírez 2 years ago
committed by GitHub
parent
commit
9889182d50
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      fastapi/_compat.py

12
fastapi/_compat.py

@ -101,9 +101,6 @@ if PYDANTIC_V2:
self._type_adapter: TypeAdapter[Any] = TypeAdapter(
Annotated[self.field_info.annotation, self.field_info]
)
self._field_info_core_schema = TypeAdapter.model_field_schema(
name=self.name, field=self.field_info
)
def get_default(self) -> Any:
if self.field_info.is_required():
@ -183,7 +180,7 @@ if PYDANTIC_V2:
model_name_map: ModelNameMap,
) -> Dict[str, Any]:
# This expects that GenerateJsonSchema was already used to generate the definitions
json_schema = schema_generator.generate_inner(field._field_info_core_schema)
json_schema = schema_generator.generate_inner(field._type_adapter.core_schema)
if "$ref" not in json_schema:
# TODO remove when deprecating Pydantic v1
# Ref: https://github.com/pydantic/pydantic/blob/d61792cc42c80b13b23e3ffa74bc37ec7c77f7d1/pydantic/schema.py#L207
@ -202,12 +199,7 @@ if PYDANTIC_V2:
model_name_map: ModelNameMap,
) -> Dict[str, Dict[str, Any]]:
inputs = [
(
field,
"validation",
TypeAdapter.model_field_schema(name=field.name, field=field.field_info),
)
for field in fields
(field, "validation", field._type_adapter.core_schema) for field in fields
]
_, definitions = schema_generator.generate_definitions(inputs=inputs) # type: ignore[arg-type]
return definitions # type: ignore[return-value]

Loading…
Cancel
Save