Skip to content

Commit

Permalink
Merge pull request #17 from Yelp/internally-dereference-model-definit…
Browse files Browse the repository at this point in the history
…ions

pass internally_dereference_ref flag to bravado and remove manual dereferencing
  • Loading branch information
acoover authored Sep 18, 2019
2 parents c72eb3f + 732c019 commit d85edc8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
27 changes: 0 additions & 27 deletions fuzz_lightyear/fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@

from .datastore import get_user_defined_mapping
from .output.logging import log
from .supplements.abstraction import get_abstraction


def fuzz_parameters(
parameters: List[Tuple[str, Dict[str, Any]]],
) -> SearchStrategy:
output = {}
for name, parameter in parameters:
parameter = _deref(parameter)

output[name] = _fuzz_parameter(parameter)

return st.fixed_dictionaries(output)
Expand All @@ -46,7 +43,6 @@ def _fuzz_parameter(
},
}
"""
parameter = _deref(parameter)
required = parameter.get('required', required)
strategy = None

Expand Down Expand Up @@ -158,8 +154,6 @@ def _fuzz_object(
# TODO: Handle `additionalProperties`
output = {}
for name, specification in parameter['properties'].items():
specification = _deref(specification)

try:
strategy = _get_strategy_from_factory(specification['type'], name)
except KeyError:
Expand Down Expand Up @@ -188,13 +182,6 @@ def _fuzz_object(
return st.fixed_dictionaries(output)


def _deref(parameter: Dict[str, Any]) -> Dict[str, Any]:
while '$ref' in parameter:
parameter = _get_model_definition(parameter['$ref'])

return parameter


def _get_strategy_from_factory(
expected_type: str,
name: Optional[str] = None,
Expand All @@ -217,17 +204,3 @@ def type_cast():
return output

return st.builds(type_cast)


def _get_model_definition(
reference: str,
) -> Dict[str, Any]:
"""
:param reference: e.g. '#/defintions/{ModelName}'
"""
# TODO: Handle multiple files?
try:
model_name = reference.split('/')[-1]
return get_abstraction().client.swagger_spec.definitions[model_name]._model_spec
except (IndexError, KeyError): # pragma: no cover
raise SwaggerValidationError(f'Failed to get model: {reference}')
5 changes: 3 additions & 2 deletions fuzz_lightyear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ def setup_client(
return None

try:
config = {'internally_dereference_refs': True}
if not schema:
client = SwaggerClient.from_url(url)
client = SwaggerClient.from_url(url, config=config)
else:
client = SwaggerClient.from_spec(schema, origin_url=url)
client = SwaggerClient.from_spec(schema, origin_url=url, config=config)
except requests.exceptions.ConnectionError:
return 'Unable to connect to server.'
except (
Expand Down

0 comments on commit d85edc8

Please sign in to comment.