Skip to content

Commit 20ca1b0

Browse files
committed
Fixed BaseModel as a GET - method params. Added Quart.
1 parent 3492353 commit 20ca1b0

File tree

22 files changed

+383
-5
lines changed

22 files changed

+383
-5
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
source = fastopenapi
33
omit =
44
*/site-packages/*
5-
branch = False
5+
branch = True
66

77
[report]
88
show_missing = True

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to FastOpenAPI are documented in this file.
44

55
FastOpenAPI follows the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.
66

7+
## [0.3.0] - Unreleased
8+
9+
### Added
10+
- `QuartRouter` for integration with the `Quart` framework.
11+
12+
### Fixed
13+
- Fixed retrieving parameters for BaseModel as arguments in GET routes.
14+
715
## [0.2.1] - 2025-03-12
816

917
### Fixed

examples/flask/app/services/posts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import falcon
1+
from http import HTTPStatus
2+
3+
from flask import abort
24

35
from ..schemas.posts import (
46
CreatePostSchema,
@@ -14,7 +16,7 @@ def create_post(self, body: CreatePostSchema) -> PostSchema:
1416
post_counter = len(posts)
1517
author = authors.get(body.author_id)
1618
if not author:
17-
raise falcon.HTTPNotFound(description="Author not found")
19+
abort(HTTPStatus.NOT_FOUND)
1820

1921
data = {
2022
"id": post_counter,

examples/flask/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
router = FlaskRouter(
99
app=app,
10-
title="MyFalconApp",
10+
title="MyFlaskApp",
1111
version="0.0.1",
1212
docs_url="/docs/",
1313
openapi_version="3.0.0",

examples/quart/app/__init__.py

Whitespace-only changes.

examples/quart/app/api/__init__.py

Whitespace-only changes.

examples/quart/app/api/routes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from fastopenapi.routers.quart import QuartRouter
2+
3+
from .v1 import v1_router
4+
5+
api_router = QuartRouter()
6+
api_router.include_router(v1_router, prefix="/v1")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from fastopenapi.routers.quart import QuartRouter
2+
3+
from .authors import router as authors_router
4+
from .posts import router as posts_router
5+
6+
v1_router = QuartRouter()
7+
v1_router.include_router(authors_router)
8+
v1_router.include_router(posts_router)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from http import HTTPStatus
2+
3+
from quart import abort
4+
5+
from fastopenapi.routers.quart import QuartRouter
6+
7+
from ...schemas.authors import (
8+
AuthorSchema,
9+
CreateAuthorSchema,
10+
FilterAuthorSchema,
11+
UpdateAuthorSchema,
12+
)
13+
from ...services.authors import AuthorService
14+
15+
author_service = AuthorService()
16+
17+
router = QuartRouter()
18+
19+
20+
@router.post("/authors", tags=["Authors"], status_code=201, response_model=AuthorSchema)
21+
async def create_author(body: CreateAuthorSchema) -> AuthorSchema:
22+
return author_service.create_author(body)
23+
24+
25+
@router.get("/authors/{author_id}", tags=["Authors"], response_model=AuthorSchema)
26+
async def get_author(author_id: int) -> AuthorSchema:
27+
author = author_service.get_author(author_id)
28+
if not author:
29+
abort(HTTPStatus.NOT_FOUND)
30+
return author
31+
32+
33+
@router.get("/authors/", tags=["Authors"], response_model=list[AuthorSchema])
34+
async def get_authors(body: FilterAuthorSchema) -> list[AuthorSchema]:
35+
return author_service.get_authors(body)
36+
37+
38+
@router.delete("/authors/{author_id}", tags=["Authors"], status_code=204)
39+
async def delete_author(author_id: int) -> None:
40+
author = author_service.delete_author(author_id)
41+
if not author:
42+
abort(HTTPStatus.NOT_FOUND)
43+
return None
44+
45+
46+
@router.patch("/authors/{author_id}", tags=["Authors"], response_model=AuthorSchema)
47+
async def update_author(author_id: int, body: UpdateAuthorSchema) -> AuthorSchema:
48+
author = author_service.update_author(author_id, body)
49+
if not author:
50+
abort(HTTPStatus.NOT_FOUND)
51+
return author

examples/quart/app/api/v1/posts.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from http import HTTPStatus
2+
3+
from quart import abort
4+
5+
from fastopenapi.routers.quart import QuartRouter
6+
7+
from ...schemas.posts import (
8+
CreatePostSchema,
9+
FilterPostSchema,
10+
PostSchema,
11+
UpdatePostSchema,
12+
)
13+
from ...services.posts import PostService
14+
15+
post_service = PostService()
16+
router = QuartRouter()
17+
18+
19+
@router.post("/posts", tags=["Posts"], status_code=201, response_model=PostSchema)
20+
async def create_post(body: CreatePostSchema) -> PostSchema:
21+
return post_service.create_post(body)
22+
23+
24+
@router.get("/posts/{post_id}", tags=["Posts"], response_model=PostSchema)
25+
async def get_post(post_id: int) -> PostSchema:
26+
post = post_service.get_post(post_id)
27+
if not post:
28+
abort(HTTPStatus.NOT_FOUND)
29+
return post
30+
31+
32+
@router.get("/posts/", tags=["Posts"], response_model=list[PostSchema])
33+
async def get_posts(body: FilterPostSchema) -> list[PostSchema]:
34+
return post_service.get_posts(body)
35+
36+
37+
@router.delete("/posts/{post_id}", tags=["Posts"], status_code=204)
38+
async def delete_post(post_id: int) -> None:
39+
post = post_service.delete_post(post_id)
40+
if not post:
41+
abort(HTTPStatus.NOT_FOUND)
42+
43+
44+
@router.patch("/posts/{post_id}", tags=["Posts"], response_model=PostSchema)
45+
async def update_post(post_id: int, body: UpdatePostSchema) -> PostSchema:
46+
post = post_service.update_post(post_id, body)
47+
if not post:
48+
abort(HTTPStatus.NOT_FOUND)
49+
return post

0 commit comments

Comments
 (0)