Skip to content

Commit da49af7

Browse files
committed
Update response schemas for pydantic v2
1 parent 9d9fcc9 commit da49af7

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

http_app/routes/api/books.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from fastapi import APIRouter, status
2-
from pydantic import BaseModel
2+
from pydantic import BaseModel, ConfigDict
33

44
from domains.books import Book, BookData, BookService
55

@@ -9,28 +9,29 @@
99

1010
class CreateBookResponse(BaseModel):
1111
book: Book
12-
13-
class Config:
14-
json_schema_extra = {
12+
model_config = ConfigDict(
13+
json_schema_extra={
1514
"example": {
1615
"title": "The Hitchhiker's Guide to the Galaxy",
1716
"author_name": "Douglas Adams",
1817
"book_id": 123,
1918
}
2019
}
20+
)
2121

2222

2323
class CreateBookRequest(BaseModel):
2424
title: str
2525
author_name: str
2626

27-
class Config:
28-
json_schema_extra = {
27+
model_config = ConfigDict(
28+
json_schema_extra={
2929
"example": {
3030
"title": "The Hitchhiker's Guide to the Galaxy",
3131
"author_name": "Douglas Adams",
3232
}
3333
}
34+
)
3435

3536

3637
"""

http_app/routes/ping.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
from fastapi import APIRouter
2-
from pydantic import BaseModel
2+
from pydantic import BaseModel, ConfigDict
33

44
router = APIRouter()
55

66

77
class PingResponse(BaseModel):
88
ping: str
99

10-
class Config:
11-
json_schema_extra = {
10+
model_config = ConfigDict(
11+
json_schema_extra={
1212
"example": {
1313
"ping": "pong!",
1414
}
1515
}
16+
)
1617

1718

1819
@router.get("/ping", response_model=PingResponse)

0 commit comments

Comments
 (0)