change check for pydantic list in outer type

This commit is contained in:
collerek
2021-05-02 15:03:02 +02:00
parent 18706d884c
commit 1f0ceb3f48
2 changed files with 10 additions and 8 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: collerek

View File

@ -11,6 +11,7 @@ except ImportError: # pragma: no cover
import json # type: ignore import json # type: ignore
import pydantic import pydantic
from pydantic.fields import SHAPE_LIST
from pydantic.main import SchemaExtraCallable from pydantic.main import SchemaExtraCallable
import ormar # noqa: I100, I202 import ormar # noqa: I100, I202
@ -184,11 +185,11 @@ def generate_pydantic_example(
""" """
example: Dict[str, Any] = dict() example: Dict[str, Any] = dict()
exclude = exclude or set() exclude = exclude or set()
for name in pydantic_model.__fields__: name_to_check = [name for name in pydantic_model.__fields__ if name not in exclude]
if name not in exclude: for name in name_to_check:
field = pydantic_model.__fields__[name] field = pydantic_model.__fields__[name]
type_ = field.type_ type_ = field.type_
if getattr(field.outer_type_, "_name", None) == "List": if field.shape == SHAPE_LIST:
example[name] = [get_pydantic_example_repr(type_)] example[name] = [get_pydantic_example_repr(type_)]
else: else:
example[name] = get_pydantic_example_repr(type_) example[name] = get_pydantic_example_repr(type_)