add also basic examples for native pydantic fields including models to not skip them
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from typing import List
|
||||
import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
import databases
|
||||
import pydantic
|
||||
@ -35,6 +36,17 @@ class LocalMeta:
|
||||
database = database
|
||||
|
||||
|
||||
class PTestA(pydantic.BaseModel):
|
||||
c: str
|
||||
d: bytes
|
||||
e: datetime.datetime
|
||||
|
||||
|
||||
class PTestP(pydantic.BaseModel):
|
||||
a: int
|
||||
b: Optional[PTestA]
|
||||
|
||||
|
||||
class Category(ormar.Model):
|
||||
class Meta(LocalMeta):
|
||||
tablename = "categories"
|
||||
@ -49,6 +61,8 @@ class Item(ormar.Model):
|
||||
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=100)
|
||||
pydantic_int: Optional[int]
|
||||
test_P: Optional[List[PTestP]]
|
||||
categories = ormar.ManyToMany(Category)
|
||||
|
||||
|
||||
@ -126,16 +140,27 @@ def test_schema_modification():
|
||||
)
|
||||
assert schema["properties"]["categories"]["title"] == "Categories"
|
||||
assert schema["example"] == {
|
||||
"categories": [{"id": 0, "name": "string"}],
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
"categories": [{"id": 0, "name": "string"}],
|
||||
"pydantic_int": 0,
|
||||
"test_P": [{"a": 0, "b": {"c": "string", "d": "string", "e": "string"}}],
|
||||
}
|
||||
|
||||
schema = Category.schema()
|
||||
assert schema["example"] == {
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
"items": [{"id": 0, "name": "string"}],
|
||||
"items": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
"pydantic_int": 0,
|
||||
"test_P": [
|
||||
{"a": 0, "b": {"c": "string", "d": "string", "e": "string"}}
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user