diff --git a/swagger_parser/swagger_parser.py b/swagger_parser/swagger_parser.py index a0c4d35..09aaef9 100755 --- a/swagger_parser/swagger_parser.py +++ b/swagger_parser/swagger_parser.py @@ -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. @@ -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): @@ -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']) diff --git a/tests/swagger.yaml b/tests/swagger.yaml index abfe5a4..0979244 100644 --- a/tests/swagger.yaml +++ b/tests/swagger.yaml @@ -441,7 +441,7 @@ paths: description: Updated user object required: false schema: - $ref: "#/definitions/User" + type: string responses: "200": description: Created diff --git a/tests/test_swagger_parser.py b/tests/test_swagger_parser.py index a7e7739..f883f48 100755 --- a/tests/test_swagger_parser.py +++ b/tests/test_swagger_parser.py @@ -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'