Privileged issue
Issue Content
Using arbitrary_types_allowed=True with custom types that define their serialization and JSON Schema breaks when generating OpenAPI.
Originally reported in: #14184
Extracting the minimal reproducible example from the comments:
from typing import Annotated
import numpy as np
from fastapi import FastAPI
from pydantic import BaseModel, ConfigDict, WithJsonSchema, TypeAdapter
type MyNumpyArray = Annotated[
np.ndarray, WithJsonSchema(TypeAdapter(list[float]).json_schema(), mode="serialization"),
]
class MyModel(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
custom_field: MyNumpyArray
app = FastAPI()
@app.get("/")
def test() -> MyModel:
raise NotImplementedError()
print(app.openapi())
# {'openapi': '3.1.0', 'info': {'title': 'FastAPI', 'version': '0.1.0'}, 'paths': {'/': {'get': {'summary': 'Test', 'operationId': 'test__get', 'responses': {'200': {'description': 'Successful Response', 'content': {'application/json': {'schema': {'$ref': '#/components/schemas/MyModel'}}}}}}}}, 'components': {'schemas': {'MyModel': {'properties': {'custom_field': {'$ref': '#/components/schemas/MyNumpyArray'}}, 'type': 'object', 'required': ['custom_field'], 'title': 'MyModel'}, 'MyNumpyArray': {'items': {'type': 'number'}, 'type': 'array'}}}}
Should be solved by: #14482
Privileged issue
Issue Content
Using
arbitrary_types_allowed=Truewith custom types that define their serialization and JSON Schema breaks when generating OpenAPI.Originally reported in: #14184
Extracting the minimal reproducible example from the comments:
Should be solved by: #14482