diff --git a/tests/conftest.py b/tests/conftest.py index e360518..bf3491b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -202,3 +202,10 @@ def empty_contact(): Provides a spec with an empty contact section in info """ yield _get_parsed_yaml("empty_contact.yaml") + +@pytest.fixture +def with_external_docs(): + """ + Provides a spec with externalDocs objects in all valid places + """ + yield _get_parsed_yaml("with-external-docs.yaml") diff --git a/tests/fixtures/with-external-docs.yaml b/tests/fixtures/with-external-docs.yaml new file mode 100644 index 0000000..1d7130f --- /dev/null +++ b/tests/fixtures/with-external-docs.yaml @@ -0,0 +1,33 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: With External Docs +externalDocs: + url: http://example.org/openapi +tags: +- name: Example + description: Example + externalDocs: + url: http://example.org/tags +paths: + /example: + get: + operationId: example + externalDocs: + description: Example external docs + url: http://example.org/operation + responses: + '200': + description: example + content: + application/json: + schema: + properties: + name: + type: string + description: example + example: something + externalDocs: + url: http://example.org/schema + description: External docs reference + diff --git a/tests/parsing_test.py b/tests/parsing_test.py index eae6990..d20d6a1 100644 --- a/tests/parsing_test.py +++ b/tests/parsing_test.py @@ -148,3 +148,14 @@ def test_empty_contact(empty_contact): """ spec = OpenAPI(empty_contact, validate=True) assert len(spec.errors()) == 0 + + +def test_external_docs(with_external_docs): + """ + Tests that ExternalDocumentation objects are parsed as expected + """ + spec = OpenAPI(with_external_docs) + assert spec.externalDocs.url == "http://example.org/openapi" + assert spec.tags[0].externalDocs.url == "http://example.org/tags" + assert spec.paths["/example"].get.externalDocs.url == "http://example.org/operation" + assert spec.paths["/example"].get.responses['200'].content['application/json'].schema.externalDocs.url == "http://example.org/schema"