Skip to content

Commit

Permalink
Fix schema with only a type field
Browse files Browse the repository at this point in the history
  • Loading branch information
cyprieng committed Feb 3, 2016
1 parent 33523f8 commit d1990e2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions swagger_parser/swagger_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def _example_from_complex_def(self, prop_spec):
else:
definition_name = self.get_definition_name_from_ref(prop_spec['schema']['items']['$ref'])
return [self.definitions_example[definition_name]]
else:
return self.get_example_from_prop_spec(prop_spec['schema'])

def _example_from_array_spec(self, prop_spec):
"""Get an example from a property specification of an array.
Expand Down Expand Up @@ -509,6 +511,10 @@ def _check_body_parameters(self, body, action_spec):
definition_name = self.get_definition_name_from_ref(param_spec['schema']['items']['$ref'])
if len(body) > 0 and not self.validate_definition(definition_name, body[0]):
return False
elif 'type' in param_spec['schema'].keys():
# Type but not array
if not self.check_type(body, param_spec['schema']['type']):
return False
else:
definition_name = self.get_definition_name_from_ref(param_spec['schema']['$ref'])
if not self.validate_definition(definition_name, body):
Expand Down Expand Up @@ -584,6 +590,9 @@ def get_send_request_correct_body(self, path, action):
# Get value from definition
definition_name = self.get_definition_name_from_ref(spec['schema']['items']['$ref'])
return [self.definitions_example[definition_name]]
elif 'type' in spec['schema'].keys():
# Type but not array
return self.get_example_from_prop_spec(spec['schema'])
else:
# Get value from definition
definition_name = self.get_definition_name_from_ref(spec['schema']['$ref'])
Expand Down
2 changes: 1 addition & 1 deletion tests/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ paths:
description: Updated user object
required: false
schema:
$ref: "#/definitions/User"
type: string
responses:
"200":
description: Created
Expand Down
1 change: 1 addition & 0 deletions tests/test_swagger_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ def test_get_request_data(swagger_parser, pet_definition_example):
def test_get_send_request_correct_body(swagger_parser, pet_definition_example):
assert swagger_parser.get_send_request_correct_body('/pets', 'post') == pet_definition_example
assert swagger_parser.get_send_request_correct_body('/pets/findByStatus', 'get') is None
assert swagger_parser.get_send_request_correct_body('/users/username', 'put') == 'string'

0 comments on commit d1990e2

Please sign in to comment.