-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(event_handler): support richer Tags on OpenAPI object
- Loading branch information
1 parent
cedb5c9
commit 26ca413
Showing
3 changed files
with
62 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from aws_lambda_powertools.event_handler import APIGatewayRestResolver | ||
from aws_lambda_powertools.event_handler.openapi.models import Tag | ||
|
||
|
||
def test_openapi_with_tags(): | ||
app = APIGatewayRestResolver() | ||
|
||
@app.get("/users") | ||
def handler(): | ||
raise NotImplementedError() | ||
|
||
schema = app.get_openapi_schema(tags=["Orders"]) | ||
assert schema.tags is not None | ||
assert len(schema.tags) == 1 | ||
|
||
tag = schema.tags[0] | ||
assert tag.name == "Orders" | ||
|
||
|
||
def test_openapi_with_object_tags(): | ||
app = APIGatewayRestResolver() | ||
|
||
@app.get("/users") | ||
def handler(): | ||
raise NotImplementedError() | ||
|
||
schema = app.get_openapi_schema(tags=[Tag(name="Orders", description="Order description tag")]) | ||
assert schema.tags is not None | ||
assert len(schema.tags) == 1 | ||
|
||
tag = schema.tags[0] | ||
assert tag.name == "Orders" | ||
assert tag.description == "Order description tag" | ||
|
||
|
||
def test_openapi_operation_with_tags(): | ||
app = APIGatewayRestResolver() | ||
|
||
@app.get("/users", tags=["Users"]) | ||
def handler(): | ||
raise NotImplementedError() | ||
|
||
schema = app.get_openapi_schema() | ||
assert schema.paths is not None | ||
assert len(schema.paths.keys()) == 1 | ||
|
||
get = schema.paths["/users"].get | ||
assert get is not None | ||
assert get.tags is not None | ||
assert len(get.tags) == 1 | ||
|
||
tag = get.tags[0] | ||
assert tag == "Users" |