Repository: Yelp/swagger_spec_validator

Issue:
validator errors when `additionalProperties: false`
#134 introduces a new code path that validates `additionalProperties`. However, it assumes that additionalProperties, if exists, is an  object

jsonschema allows for boolean values: https://json-schema.org/understanding-json-schema/reference/object.html
> The additionalProperties keyword may be either a boolean or an object. If additionalProperties is a boolean and set to false, no additional properties will be allowed.

Existing schemas with boolean values for additionalProperties are failing validation with:
` 'bool' object has no attribute 'get`

v2.5.0 validates successfully. v2.7.0 fails.
[swagger.txt](https://github.com/Yelp/swagger_spec_validator/files/4748947/swagger.txt)

Discussion:

Patch:
diff --git a/swagger_spec_validator/validator20.py b/swagger_spec_validator/validator20.py
index 69f9be5..118b676 100644
--- a/swagger_spec_validator/validator20.py
+++ b/swagger_spec_validator/validator20.py
@@ -512,12 +512,13 @@ def validate_definition(definition, deref, def_name=None, visited_definitions_id
             )
 
     if 'additionalProperties' in definition:
-        validate_definition(
-            definition=definition.get('additionalProperties'),
-            deref=deref,
-            def_name='{}/{}'.format(def_name, 'additionalProperties'),
-            visited_definitions_ids=visited_definitions_ids,
-        )
+        if definition.get('additionalProperties') not in (True, False):
+            validate_definition(
+                definition=definition.get('additionalProperties'),
+                deref=deref,
+                def_name='{}/additionalProperties'.format(def_name),
+                visited_definitions_ids=visited_definitions_ids,
+            )
 
     if 'discriminator' in definition:
         required_props, not_required_props = get_collapsed_properties_type_mappings(definition, deref)


Test patch:
diff --git a/tests/validator20/validate_spec_test.py b/tests/validator20/validate_spec_test.py
index 2d57f05..e9c006f 100644
--- a/tests/validator20/validate_spec_test.py
+++ b/tests/validator20/validate_spec_test.py
@@ -427,8 +427,6 @@ def test_highlight_inconsistent_schema_object_validation(minimal_swagger_dict, s
 
 def test_additional_properties_validated(minimal_swagger_dict, default_checks_spec_dict):
     invalid_spec = {'type': 'object', 'required': ['foo']}
-    minimal_swagger_dict['definitions']['injected_definition'] = invalid_spec
-
     minimal_swagger_dict['definitions']['injected_definition'] = {
         'type': 'object', 'additionalProperties': invalid_spec
     }
@@ -437,10 +435,16 @@ def test_additional_properties_validated(minimal_swagger_dict, default_checks_sp
         validate_spec(minimal_swagger_dict)
 
 
+def test_additional_properties_bool(minimal_swagger_dict, default_checks_spec_dict):
+    minimal_swagger_dict['definitions']['injected_definition'] = {
+        'type': 'object', 'additionalProperties': False,
+    }
+
+    validate_spec(minimal_swagger_dict)
+
+
 def test_array_items_validated(minimal_swagger_dict, default_checks_spec_dict):
     invalid_spec = {'type': 'object', 'required': ['foo']}
-    minimal_swagger_dict['definitions']['injected_definition'] = invalid_spec
-
     minimal_swagger_dict['definitions']['injected_definition'] = {
         'type': 'array', 'items': invalid_spec
     }