introduce pydantic config dict

This commit is contained in:
Jakub Miazek 2023-07-24 12:53:57 +02:00
parent 603225a0de
commit 0b2d2e7933
2 changed files with 43 additions and 36 deletions

View File

@ -1,9 +1,12 @@
from uuid import UUID
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, ConfigDict
config = ConfigDict(from_attributes=True)
class NonsenseSchema(BaseModel):
model_config = config
name: str = Field(
title="",
description="",
@ -13,17 +16,18 @@ class NonsenseSchema(BaseModel):
description="",
)
class Config:
from_attributes = True
json_schema_extra = {
"example": {
"name": "Name for Some Nonsense",
"description": "Some Nonsense Description",
}
}
# class Config:
# from_attributes = True
# json_schema_extra = {
# "example": {
# "name": "Name for Some Nonsense",
# "description": "Some Nonsense Description",
# }
# }
class NonsenseResponse(BaseModel):
model_config = config
id: UUID = Field(
title="Id",
description="",
@ -37,12 +41,12 @@ class NonsenseResponse(BaseModel):
description="",
)
class Config:
from_attributes = True
json_schema_extra = {
"example": {
"config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "Name for Some Nonsense",
"description": "Some Nonsense Description",
}
}
# class Config:
# from_attributes = True
# json_schema_extra = {
# "example": {
# "config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
# "name": "Name for Some Nonsense",
# "description": "Some Nonsense Description",
# }
# }

View File

@ -1,6 +1,8 @@
from uuid import UUID
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, ConfigDict
config = ConfigDict(from_attributes=True)
class StuffSchema(BaseModel):
@ -13,17 +15,18 @@ class StuffSchema(BaseModel):
description="",
)
class Config:
from_attributes = True
json_schema_extra = {
"example": {
"name": "Name for Some Stuff",
"description": "Some Stuff Description",
}
}
# class Config:
# from_attributes = True
# json_schema_extra = {
# "example": {
# "name": "Name for Some Stuff",
# "description": "Some Stuff Description",
# }
# }
class StuffResponse(BaseModel):
model_config = config
id: UUID = Field(
title="Id",
description="",
@ -37,12 +40,12 @@ class StuffResponse(BaseModel):
description="",
)
class Config:
from_attributes = True
json_schema_extra = {
"example": {
"config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "Name for Some Stuff",
"description": "Some Stuff Description",
}
}
# class Config:
# from_attributes = True
# json_schema_extra = {
# "example": {
# "config_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
# "name": "Name for Some Stuff",
# "description": "Some Stuff Description",
# }
# }