Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect models will not create models for not models objects #246

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion bravado_core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def collect_models(container, key, path, models, swagger_spec):
:type swagger_spec: :class:`bravado_core.spec.Spec`
"""
deref = swagger_spec.deref
if key == MODEL_MARKER:
if key == MODEL_MARKER and is_object(swagger_spec, container):
model_spec = container
model_name = deref(model_spec.get(MODEL_MARKER))
models[model_name] = create_model_type(
Expand Down
20 changes: 20 additions & 0 deletions tests/model/collect_models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,23 @@ def test_simple(minimal_swagger_dict, pet_model_spec):
models=models,
swagger_spec=swagger_spec)
assert 'Pet' in models


def test_not_model(minimal_swagger_dict, pet_model_spec):
minimal_swagger_dict['definitions']['Pet'] = pet_model_spec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a docstring explaining why we this is not a model, although it has the x-model marker?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added docstring and updated documentation

minimal_swagger_dict['definitions']['Pets'] = {
'type': 'array',
'items': {
'$ref': '#/definitions/Pet'
},
'x-model': 'Pets'
}
swagger_spec = Spec(minimal_swagger_dict)
models = {}
collect_models(
minimal_swagger_dict['definitions']['Pet'],
MODEL_MARKER,
['definitions', 'Pet', 'x-model'],
models=models,
swagger_spec=swagger_spec)
assert 'Pets' not in models
13 changes: 13 additions & 0 deletions tests/spec/Spec/build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,16 @@ def test_build_with_internally_dereference_refs(petstore_dict, internally_derefe
config={'internally_dereference_refs': internally_dereference_refs}
)
assert (spec.deref == spec._force_deref) == (not internally_dereference_refs)


def test_not_object_x_models_are_not_generating_models(minimal_swagger_dict):
minimal_swagger_dict['definitions']['Pets'] = {
'type': 'array',
'items': {
'type': 'string'
},
'x-model': 'Pets'
}
swagger_spec = Spec(minimal_swagger_dict)
swagger_spec.build()
assert not swagger_spec.definitions