Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags to RouteInfo #42

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading