Skip to content

Commit

Permalink
Add support for tags in routes (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
omarudolley authored Apr 8, 2024
1 parent 44ae03e commit b6907bd
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 35 deletions.
1 change: 1 addition & 0 deletions openapi_to_fastapi/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def parse_operation(spec: dict, name: str) -> Optional[Operation]:
operation.summary = data.get("summary")
operation.description = data.get("description")
operation.deprecated = data.get("deprecated")
operation.tags = data.get("tags")

request_body_model = get_model_name_from_ref(data.get("requestBody", {}))
if request_body_model:
Expand Down
7 changes: 4 additions & 3 deletions openapi_to_fastapi/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ def _validate_and_parse_specs(self, cleanup=True):
route_info = RouteInfo(
request_model=req_model,
description=post.description,
summary=path_item.post.summary,
headers=path_item.post.headers,
deprecated=path_item.post.deprecated,
tags=post.tags,
summary=post.summary,
headers=post.headers,
deprecated=post.deprecated,
responses={},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"summary": "Coffee brewer",
"description": "Coffee brewer",
"operationId": "request_draft_Appliances_CoffeeBrewer",
"tags": ["Coffee"],
"parameters": [
{
"description": "Optional consent token",
Expand Down
10 changes: 10 additions & 0 deletions openapi_to_fastapi/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def test_deprecated(app, specs_root):
assert spec["paths"]["/draft/Appliances/CoffeeBrewer"]["post"]["deprecated"] is True


def test_tags(app, specs_root):
spec_router = SpecRouter(specs_root / "definitions")

router = spec_router.to_fastapi_router()
app.include_router(router)

spec = app.openapi()
assert spec["paths"]["/draft/Appliances/CoffeeBrewer"]["post"]["tags"] == ["Coffee"]


def test_custom_responses(app, specs_root):
brew_spec = "/draft/Appliances/CoffeeBrewer"
spec_router = SpecRouter(specs_root / "definitions")
Expand Down
88 changes: 57 additions & 31 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openapi-to-fastapi"
version = "0.14.0"
version = "0.15.0"
description = "Create FastAPI routes from OpenAPI spec"
authors = ["IOXIO Ltd"]
license = "BSD-3-Clause"
Expand Down

0 comments on commit b6907bd

Please sign in to comment.