|
|
|
@ -12,7 +12,7 @@ from typing import ( |
|
|
|
cast, |
|
|
|
) |
|
|
|
|
|
|
|
from fastapi._compat import shared |
|
|
|
from fastapi._compat import lenient_issubclass, shared |
|
|
|
from fastapi.openapi.constants import REF_TEMPLATE |
|
|
|
from fastapi.types import IncEx, ModelNameMap, UnionType |
|
|
|
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, create_model |
|
|
|
@ -23,7 +23,6 @@ from pydantic._internal._schema_generation_shared import ( # type: ignore[attr- |
|
|
|
GetJsonSchemaHandler as GetJsonSchemaHandler, |
|
|
|
) |
|
|
|
from pydantic._internal._typing_extra import eval_type_lenient |
|
|
|
from pydantic._internal._utils import lenient_issubclass as lenient_issubclass |
|
|
|
from pydantic.fields import FieldInfo as FieldInfo |
|
|
|
from pydantic.json_schema import GenerateJsonSchema as GenerateJsonSchema |
|
|
|
from pydantic.json_schema import JsonSchemaValue as JsonSchemaValue |
|
|
|
@ -416,10 +415,11 @@ def get_flat_models_from_annotation( |
|
|
|
origin = get_origin(annotation) |
|
|
|
if origin is not None: |
|
|
|
for arg in get_args(annotation): |
|
|
|
if lenient_issubclass(arg, (BaseModel, Enum)) and arg not in known_models: |
|
|
|
known_models.add(arg) |
|
|
|
if lenient_issubclass(arg, BaseModel): |
|
|
|
get_flat_models_from_model(arg, known_models=known_models) |
|
|
|
if lenient_issubclass(arg, (BaseModel, Enum)): |
|
|
|
if arg not in known_models: |
|
|
|
known_models.add(arg) # type: ignore[arg-type] |
|
|
|
if lenient_issubclass(arg, BaseModel): |
|
|
|
get_flat_models_from_model(arg, known_models=known_models) |
|
|
|
else: |
|
|
|
get_flat_models_from_annotation(arg, known_models=known_models) |
|
|
|
return known_models |
|
|
|
|