Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openapi3/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _parse_data(self):
"""
self.examples = self._get("examples", ["Example", "Reference"], is_map=True)
self.parameters = self._get("parameters", ["Parameter", "Reference"], is_map=True)
self.requestBodies = self._get("requestBody", ["RequestBody", "Reference"], is_map=True)
self.requestBodies = self._get("requestBodies", ["RequestBody", "Reference"], is_map=True)
self.responses = self._get("responses", ["Response", "Reference"], is_map=True)
self.schemas = self._get("schemas", ["Schema", "Reference"], is_map=True)
self.securitySchemes = self._get("securitySchemes", ["SecurityScheme", "Reference"], is_map=True)
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,10 @@ def with_deeply_nested_allof():
Provides a spec with a $ref under a schema defined in an allOf
"""
yield _get_parsed_yaml("deeply-nested-allOf.yaml")

@pytest.fixture
def ref_request_bodies():
"""
Provides a spec with a $ref to a requestBodies definition
"""
yield _get_parsed_yaml("ref-request-bodies.yaml")
47 changes: 47 additions & 0 deletions tests/fixtures/ref-request-bodies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
termsOfService: http://swagger.io/terms/
contact:
name: Swagger API Team
email: apiteam@swagger.io
url: http://swagger.io
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
- url: http://petstore.swagger.io/api
paths:
/pets:
post:
summary: Add a new pet
requestBody:
$ref: "#/components/requestBodies/PetBody"
responses:
"200":
description: pet response
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
components:
schemas:
Pet:
type: object
required:
- name
properties:
name:
type: string
tag:
type: string
requestBodies:
PetBody:
description: A JSON object containing pet information
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
10 changes: 10 additions & 0 deletions tests/parsing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,13 @@ def test_schema_default_types(with_all_default_types):
assert schema.properties["str"].default == "test"
assert schema.properties["bool"].default == True
assert schema.properties["float"].default == 0.1


def test_request_bodies_ref(ref_request_bodies):
"""
Tests that refs to components/requestBodies can be resolved
"""
spec = OpenAPI(ref_request_bodies, validate=True)
error_messages = [getattr(error, "message") for error in spec.errors()]
found_errors = bool(error_messages)
assert not found_errors, error_messages