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
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ def _process_request_body(self):

if schema and schema.type == 'object':
properties = schema.properties or {}
required_properties = set(schema.required or [])
for prop_name, prop_details in properties.items():
self._params.append(
ApiParameter(
original_name=prop_name,
param_location='body',
param_schema=prop_details,
description=prop_details.description,
required=prop_name in required_properties,
py_name=self._get_py_name(prop_name),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ def test_process_request_body(sample_operation):
assert parser._params[1].param_location == 'body'


def test_required_request_body_properties_are_required_parameters():
"""Required body properties appear in the generated parameter schema."""
operation = Operation(
operationId='createSpace',
requestBody=RequestBody(
content={
'application/json': MediaType(
schema=Schema(
type='object',
required=['spaceName'],
properties={
'spaceName': Schema(type='string'),
'description': Schema(type='string'),
},
)
)
}
),
)

parser = OperationParser(operation)

assert parser.get_json_schema()['required'] == ['space_name']


def test_process_request_body_array():
"""Test _process_request_body method with array schema."""
operation = Operation(
Expand Down
Loading