Skip to content

Commit b206e83

Browse files
committed
Merge pull request Yelp#28 from kentwills/validate_model
add validation for model name and id
2 parents 5628cf5 + 951c74c commit b206e83

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

swagger_spec_validator/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
__summary__ = "Validation of Swagger specifications"
88
__uri__ = "http://github.com/Yelp/swagger_spec_validator"
99

10-
__version__ = "1.0.10"
10+
__version__ = "1.0.11"
1111

1212
__author__ = "John Billings"
1313
__email__ = "[email protected]"

swagger_spec_validator/validator12.py

+4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ def validate_model(model, model_name, model_ids):
159159
'Model "%s": required property "%s" not found' %
160160
(model_name, required))
161161

162+
if model_name != model['id']:
163+
error = 'model name: {0} does not match model id: {1}'.format(model_name, model['id'])
164+
raise SwaggerValidationError(error)
165+
162166
for prop_name, prop in six.iteritems(model.get('properties', {})):
163167
try:
164168
validate_data_type(prop, model_ids, allow_refs=True)

tests/validator12/validate_spec_test.py

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
validate_data_type,
1010
validate_spec,
1111
validate_parameter,
12+
validate_model,
1213
)
1314

1415

@@ -67,3 +68,13 @@ def test_validate_data_type_is_model():
6768
obj = {'type': model_id}
6869
# lack of error is success
6970
validate_data_type(obj, model_ids, allow_refs=False)
71+
72+
73+
def test_validate_model_matches_id():
74+
model = {"id": "mysupermodel"}
75+
model_name = "mymodel"
76+
model_ids = ""
77+
78+
with pytest.raises(SwaggerValidationError) as exc:
79+
validate_model(model, model_name, model_ids)
80+
assert 'model name: mymodel does not match model id: mysupermodel' in str(exc)

0 commit comments

Comments
 (0)