mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
introduce pydantic config dict
This commit is contained in:
parent
603225a0de
commit
0b2d2e7933
@ -1,9 +1,12 @@
|
|||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, ConfigDict
|
||||||
|
|
||||||
|
config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
|
||||||
class NonsenseSchema(BaseModel):
|
class NonsenseSchema(BaseModel):
|
||||||
|
model_config = config
|
||||||
name: str = Field(
|
name: str = Field(
|
||||||
title="",
|
title="",
|
||||||
description="",
|
description="",
|
||||||
@ -13,17 +16,18 @@ class NonsenseSchema(BaseModel):
|
|||||||
description="",
|
description="",
|
||||||
)
|
)
|
||||||
|
|
||||||
class Config:
|
# class Config:
|
||||||
from_attributes = True
|
# from_attributes = True
|
||||||
json_schema_extra = {
|
# json_schema_extra = {
|
||||||
"example": {
|
# "example": {
|
||||||
"name": "Name for Some Nonsense",
|
# "name": "Name for Some Nonsense",
|
||||||
"description": "Some Nonsense Description",
|
# "description": "Some Nonsense Description",
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
|
|
||||||
|
|
||||||
class NonsenseResponse(BaseModel):
|
class NonsenseResponse(BaseModel):
|
||||||
|
model_config = config
|
||||||
id: UUID = Field(
|
id: UUID = Field(
|
||||||
title="Id",
|
title="Id",
|
||||||
description="",
|
description="",
|
||||||
@ -37,12 +41,12 @@ class NonsenseResponse(BaseModel):
|
|||||||
description="",
|
description="",
|
||||||
)
|
)
|
||||||
|
|
||||||
class Config:
|
# class Config:
|
||||||
from_attributes = True
|
# from_attributes = True
|
||||||
json_schema_extra = {
|
# json_schema_extra = {
|
||||||
"example": {
|
# "example": {
|
||||||
"config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
# "config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||||
"name": "Name for Some Nonsense",
|
# "name": "Name for Some Nonsense",
|
||||||
"description": "Some Nonsense Description",
|
# "description": "Some Nonsense Description",
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, ConfigDict
|
||||||
|
|
||||||
|
config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
|
||||||
class StuffSchema(BaseModel):
|
class StuffSchema(BaseModel):
|
||||||
@ -13,17 +15,18 @@ class StuffSchema(BaseModel):
|
|||||||
description="",
|
description="",
|
||||||
)
|
)
|
||||||
|
|
||||||
class Config:
|
# class Config:
|
||||||
from_attributes = True
|
# from_attributes = True
|
||||||
json_schema_extra = {
|
# json_schema_extra = {
|
||||||
"example": {
|
# "example": {
|
||||||
"name": "Name for Some Stuff",
|
# "name": "Name for Some Stuff",
|
||||||
"description": "Some Stuff Description",
|
# "description": "Some Stuff Description",
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
|
|
||||||
|
|
||||||
class StuffResponse(BaseModel):
|
class StuffResponse(BaseModel):
|
||||||
|
model_config = config
|
||||||
id: UUID = Field(
|
id: UUID = Field(
|
||||||
title="Id",
|
title="Id",
|
||||||
description="",
|
description="",
|
||||||
@ -37,12 +40,12 @@ class StuffResponse(BaseModel):
|
|||||||
description="",
|
description="",
|
||||||
)
|
)
|
||||||
|
|
||||||
class Config:
|
# class Config:
|
||||||
from_attributes = True
|
# from_attributes = True
|
||||||
json_schema_extra = {
|
# json_schema_extra = {
|
||||||
"example": {
|
# "example": {
|
||||||
"config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
# "config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
||||||
"name": "Name for Some Stuff",
|
# "name": "Name for Some Stuff",
|
||||||
"description": "Some Stuff Description",
|
# "description": "Some Stuff Description",
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user