Skip to content

Commit

Permalink
Added tests for parsing External Documentation objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorthu committed Nov 10, 2022
1 parent edd230a commit 6e598ed
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
33 changes: 33 additions & 0 deletions tests/fixtures/with-external-docs.yaml
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions tests/parsing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 6e598ed

Please sign in to comment.