From 0b2d2e79338bb564bbb5ecbe2102ab7443573ecf Mon Sep 17 00:00:00 2001 From: Jakub Miazek Date: Mon, 24 Jul 2023 12:53:57 +0200 Subject: [PATCH] introduce pydantic config dict --- app/schemas/nnonsense.py | 40 ++++++++++++++++++++++------------------ app/schemas/stuff.py | 39 +++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/app/schemas/nnonsense.py b/app/schemas/nnonsense.py index 627d72c..2e9d189 100644 --- a/app/schemas/nnonsense.py +++ b/app/schemas/nnonsense.py @@ -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", + # } + # } diff --git a/app/schemas/stuff.py b/app/schemas/stuff.py index 642d4eb..90ddc29 100644 --- a/app/schemas/stuff.py +++ b/app/schemas/stuff.py @@ -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", + # } + # }