Skip to content

Commit b6907bd

Browse files
authored
Add support for tags in routes (#42)
1 parent 44ae03e commit b6907bd

6 files changed

Lines changed: 74 additions & 35 deletions

File tree

openapi_to_fastapi/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def parse_operation(spec: dict, name: str) -> Optional[Operation]:
7070
operation.summary = data.get("summary")
7171
operation.description = data.get("description")
7272
operation.deprecated = data.get("deprecated")
73+
operation.tags = data.get("tags")
7374

7475
request_body_model = get_model_name_from_ref(data.get("requestBody", {}))
7576
if request_body_model:

openapi_to_fastapi/routes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ def _validate_and_parse_specs(self, cleanup=True):
127127
route_info = RouteInfo(
128128
request_model=req_model,
129129
description=post.description,
130-
summary=path_item.post.summary,
131-
headers=path_item.post.headers,
132-
deprecated=path_item.post.deprecated,
130+
tags=post.tags,
131+
summary=post.summary,
132+
headers=post.headers,
133+
deprecated=post.deprecated,
133134
responses={},
134135
)
135136

openapi_to_fastapi/tests/data/definitions/CoffeeBrewer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"summary": "Coffee brewer",
1212
"description": "Coffee brewer",
1313
"operationId": "request_draft_Appliances_CoffeeBrewer",
14+
"tags": ["Coffee"],
1415
"parameters": [
1516
{
1617
"description": "Optional consent token",

openapi_to_fastapi/tests/test_router.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ def test_deprecated(app, specs_root):
216216
assert spec["paths"]["/draft/Appliances/CoffeeBrewer"]["post"]["deprecated"] is True
217217

218218

219+
def test_tags(app, specs_root):
220+
spec_router = SpecRouter(specs_root / "definitions")
221+
222+
router = spec_router.to_fastapi_router()
223+
app.include_router(router)
224+
225+
spec = app.openapi()
226+
assert spec["paths"]["/draft/Appliances/CoffeeBrewer"]["post"]["tags"] == ["Coffee"]
227+
228+
219229
def test_custom_responses(app, specs_root):
220230
brew_spec = "/draft/Appliances/CoffeeBrewer"
221231
spec_router = SpecRouter(specs_root / "definitions")

poetry.lock

Lines changed: 57 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "openapi-to-fastapi"
3-
version = "0.14.0"
3+
version = "0.15.0"
44
description = "Create FastAPI routes from OpenAPI spec"
55
authors = ["IOXIO Ltd"]
66
license = "BSD-3-Clause"

0 commit comments

Comments
 (0)