-
-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple APIs with same base path (#1736)
Fixes #1542 Fixes #1724 Cherry-picked some commits from #1598. --------- Co-authored-by: Leonardo Festa <[email protected]>
- Loading branch information
1 parent
17fcad0
commit 41c525c
Showing
13 changed files
with
215 additions
and
22 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
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
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,48 @@ | ||
import json | ||
|
||
import pytest | ||
|
||
from conftest import TEST_FOLDER | ||
|
||
SPECS = [ | ||
pytest.param( | ||
[ | ||
{"specification": "swagger_greeting.yaml", "name": "greeting"}, | ||
{"specification": "swagger_bye.yaml", "name": "bye"}, | ||
], | ||
id="swagger", | ||
), | ||
pytest.param( | ||
[ | ||
{"specification": "openapi_greeting.yaml", "name": "greeting"}, | ||
{"specification": "openapi_bye.yaml", "name": "bye"}, | ||
], | ||
id="openapi", | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("specs", SPECS) | ||
def test_app_with_multiple_definition( | ||
multiple_yaml_same_basepath_dir, specs, app_class | ||
): | ||
app = app_class( | ||
__name__, | ||
specification_dir=".." | ||
/ multiple_yaml_same_basepath_dir.relative_to(TEST_FOLDER), | ||
) | ||
|
||
for spec in specs: | ||
print(spec) | ||
app.add_api(**spec) | ||
|
||
app_client = app.test_client() | ||
|
||
response = app_client.post("/v1.0/greeting/Igor") | ||
assert response.status_code == 200 | ||
print(response.text) | ||
assert response.json()["greeting"] == "Hello Igor" | ||
|
||
response = app_client.get("/v1.0/bye/Musti") | ||
assert response.status_code == 200 | ||
assert response.text == "Goodbye Musti" |
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
28 changes: 28 additions & 0 deletions
28
tests/fixtures/multiple_yaml_same_basepath/openapi_bye.yaml
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,28 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: '{{title}}' | ||
version: '1.0' | ||
paths: | ||
'/bye/{name}': | ||
get: | ||
summary: Generate goodbye | ||
description: Generates a goodbye message. | ||
operationId: fakeapi.hello.get_bye | ||
responses: | ||
'200': | ||
description: goodbye response | ||
content: | ||
text/plain: | ||
schema: | ||
type: string | ||
default: | ||
description: unexpected error | ||
parameters: | ||
- name: name | ||
in: path | ||
description: Name of the person to say bye. | ||
required: true | ||
schema: | ||
type: string | ||
servers: | ||
- url: /v1.0 |
28 changes: 28 additions & 0 deletions
28
tests/fixtures/multiple_yaml_same_basepath/openapi_greeting.yaml
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,28 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: '{{title}}' | ||
version: '1.0' | ||
paths: | ||
'/greeting/{name}': | ||
post: | ||
summary: Generate greeting | ||
description: Generates a greeting message. | ||
operationId: fakeapi.hello.post_greeting | ||
responses: | ||
'200': | ||
description: greeting response | ||
content: | ||
'application/json': | ||
schema: | ||
type: object | ||
parameters: | ||
- name: name | ||
in: path | ||
description: Name of the person to greet. | ||
required: true | ||
schema: | ||
type: string | ||
|
||
|
||
servers: | ||
- url: /v1.0 |
29 changes: 29 additions & 0 deletions
29
tests/fixtures/multiple_yaml_same_basepath/swagger_bye.yaml
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,29 @@ | ||
swagger: "2.0" | ||
|
||
info: | ||
title: "{{title}}" | ||
version: "1.0" | ||
|
||
basePath: /v1.0 | ||
|
||
paths: | ||
/bye/{name}: | ||
get: | ||
summary: Generate goodbye | ||
description: Generates a goodbye message. | ||
operationId: fakeapi.hello.get_bye | ||
produces: | ||
- text/plain | ||
responses: | ||
'200': | ||
description: goodbye response | ||
schema: | ||
type: string | ||
default: | ||
description: "unexpected error" | ||
parameters: | ||
- name: name | ||
in: path | ||
description: Name of the person to say bye. | ||
required: true | ||
type: string |
25 changes: 25 additions & 0 deletions
25
tests/fixtures/multiple_yaml_same_basepath/swagger_greeting.yaml
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,25 @@ | ||
swagger: "2.0" | ||
|
||
info: | ||
title: "{{title}}" | ||
version: "1.0" | ||
|
||
basePath: /v1.0 | ||
|
||
paths: | ||
/greeting/{name}: | ||
post: | ||
summary: Generate greeting | ||
description: Generates a greeting message. | ||
operationId: fakeapi.hello.post_greeting | ||
responses: | ||
200: | ||
description: greeting response | ||
schema: | ||
type: object | ||
parameters: | ||
- name: name | ||
in: path | ||
description: Name of the person to greet. | ||
required: true | ||
type: string |