diff --git a/tests/api/test_bootstrap_multiple_spec.py b/tests/api/test_bootstrap_multiple_spec.py new file mode 100644 index 000000000..96b8af59c --- /dev/null +++ b/tests/api/test_bootstrap_multiple_spec.py @@ -0,0 +1,49 @@ +import json + +import pytest +from connexion import App + +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("spec", SPECS) +def test_app_with_multiple_definition(multiple_yaml_same_basepath_dir, spec): + # Create the app with a relative path and run the test_app testcase below. + app = App( + __name__, + port=5001, + specification_dir=".." + / multiple_yaml_same_basepath_dir.relative_to(TEST_FOLDER), + debug=True, + ) + + for s in spec: + app.add_api(**s) + + app_client = app.app.test_client() + + post_greeting = app_client.post("/v1.0/greeting/jsantos") # type: flask.Response + assert post_greeting.status_code == 200 + greeting_response = json.loads(post_greeting.data.decode("utf-8")) + assert greeting_response["greeting"] == "Hello jsantos" + + get_bye = app_client.get("/v1.0/bye/jsantos") # type: flask.Response + assert get_bye.status_code == 200 + assert get_bye.data == b"Goodbye jsantos" diff --git a/tests/conftest.py b/tests/conftest.py index 92a125def..098526339 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -142,6 +142,11 @@ def json_validation_spec_dir(): return FIXTURES_FOLDER / "json_validation" +@pytest.fixture +def multiple_yaml_same_basepath_dir(): + return FIXTURES_FOLDER / "multiple_yaml_same_basepath" + + @pytest.fixture(scope="session") def json_datetime_dir(): return FIXTURES_FOLDER / "datetime_support" diff --git a/tests/fixtures/multiple_yaml_same_basepath/openapi_bye.yaml b/tests/fixtures/multiple_yaml_same_basepath/openapi_bye.yaml new file mode 100644 index 000000000..1970a9b15 --- /dev/null +++ b/tests/fixtures/multiple_yaml_same_basepath/openapi_bye.yaml @@ -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 diff --git a/tests/fixtures/multiple_yaml_same_basepath/openapi_greeting.yaml b/tests/fixtures/multiple_yaml_same_basepath/openapi_greeting.yaml new file mode 100644 index 000000000..249718068 --- /dev/null +++ b/tests/fixtures/multiple_yaml_same_basepath/openapi_greeting.yaml @@ -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: + '*/*': + schema: + type: object + parameters: + - name: name + in: path + description: Name of the person to greet. + required: true + schema: + type: string + + +servers: + - url: /v1.0 diff --git a/tests/fixtures/multiple_yaml_same_basepath/swagger_bye.yaml b/tests/fixtures/multiple_yaml_same_basepath/swagger_bye.yaml new file mode 100644 index 000000000..2905e126c --- /dev/null +++ b/tests/fixtures/multiple_yaml_same_basepath/swagger_bye.yaml @@ -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 diff --git a/tests/fixtures/multiple_yaml_same_basepath/swagger_greeting.yaml b/tests/fixtures/multiple_yaml_same_basepath/swagger_greeting.yaml new file mode 100644 index 000000000..f3246b530 --- /dev/null +++ b/tests/fixtures/multiple_yaml_same_basepath/swagger_greeting.yaml @@ -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 \ No newline at end of file