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
When using generic models that override model_generic_name to generate a custom name for their generated concrete classes, the generated schema is invalid: the $refuses the custom name, but schema does not. Script to reproduce:
from typing import Any, Generic, TypeVar
from openapi_pydantic import Info, MediaType, OpenAPI, Operation, PathItem, Response
from openapi_pydantic.util import PydanticSchema, construct_open_api_with_schema_class
from pydantic import BaseModel
T_ = TypeVar("T_")
class Foo(BaseModel):
foo: str
class Bar(BaseModel, Generic[T_]):
data: list[T_]
@classmethod
def model_parametrized_name(cls: type[Any], params: tuple[type[Any], ...]) -> str:
return f"{params[0].__name__}Bar"
Paths = {
"/foo": PathItem(
get=Operation(
operationId="getFoos",
summary="Get all foos",
description="Fetches a paged list of foos",
responses={
"200": Response(
description="List of foos",
content={
"application/json": MediaType(
schema=PydanticSchema(schema_class=Bar[Foo])
)
},
)
},
),
)
}
spec = OpenAPI(info=Info(title="TestSchema", version="1"), paths=Paths)
oas = construct_open_api_with_schema_class(spec)
oas_json = oas.model_dump_json(by_alias=True, exclude_none=True, indent=2)
print(oas_json)
Hey @gorilla-seb - thanks for raising! I think this indeed would better be fixed in Pydantic itself - seems like there is some work already on this in pydantic/pydantic#6304. Going to close this one out for now as that seems like the fix to wait for here 😃
When using generic models that override
model_generic_name
to generate a custom name for their generated concrete classes, the generated schema is invalid: the$ref
uses the custom name, but schema does not. Script to reproduce:Result:
This may be related to pydantic/pydantic#7376 . I've added a quick and dirty workaround here: gorilla-seb@099cbbc
The text was updated successfully, but these errors were encountered: