Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Kubant committed Nov 9, 2020
1 parent f40e2ed commit 292ee0e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions swagger_parser/swagger_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def get_example_from_prop_spec(self, prop_spec):
# From definition
if '$ref' in prop_spec.keys():
return self._example_from_definition(prop_spec)
# Process AllOf section
if 'allOf' in prop_spec.keys():
return self._example_from_allof(prop_spec)
# Complex type
if 'type' not in prop_spec:
return self._example_from_complex_def(prop_spec)
Expand Down Expand Up @@ -324,6 +327,22 @@ def _example_from_definition(self, prop_spec):
example = dict((example_name, example_value) for example_name, example_value in example_dict.items())
return example

def _example_from_allof(self, prop_spec):
"""Get the examples from an allOf section.
Args:
prop_spec: property specification you want an example of.
Returns:
An example dict
"""
example_dict = {}
for definition in prop_spec['allOf']:
update = self.get_example_from_prop_spec(definition)
print(update)
if isinstance(update, list):
update = update[0]
example_dict.update(update)
return example_dict

def _example_from_complex_def(self, prop_spec):
"""Get an example from a property specification.
Expand Down
3 changes: 0 additions & 3 deletions tests/swagger-parser/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def get_path_data():
'description': u'successful \xb5-\xf8per\xe4tio\xf1',
'schema': {
'$ref': '#/definitions/Pet',
'x-scope': ['']
}
},
'400': {'description': 'Invalid ID supplied'},
Expand All @@ -103,7 +102,6 @@ def post_put_path_data():
'required': False,
'schema': {
'$ref': '#/definitions/Pet',
'x-scope': ['']
}
}
pet_put = pet_post.copy()
Expand All @@ -112,7 +110,6 @@ def post_put_path_data():
'description': 'Created',
'schema': {
'$ref': '#/definitions/Pet',
'x-scope': ['']
}
}
expected_post_put_paths = {
Expand Down
3 changes: 3 additions & 0 deletions tests/swagger-parser/test_swagger_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ def test_validate_definition(swagger_parser, pet_definition_example):
def test_get_paths_data(swagger_parser, post_put_path_data, get_path_data):
swagger_parser.get_paths_data()
assert len(swagger_parser.paths) == 13
print()
print(f'____________{post_put_path_data}')
print(f"______________{swagger_parser.paths['v2/pets']}")
assert swagger_parser.paths['v2/pets'] == post_put_path_data
assert swagger_parser.paths['v2/pets/{petId}']['get'] == get_path_data
post_pet_id = swagger_parser.paths['v2/pets/{petId}']['post']['parameters']['petId']
Expand Down

0 comments on commit 292ee0e

Please sign in to comment.