forked from Yelp/bravado-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Swagger specification in version 2 doesn't support 'null' as property value. This adds a vendor extension 'x-nullable' which allows properties to be 'null' if set to 'true'. See OAI/OpenAPI-Specification#229
- Loading branch information
1 parent
c3b7e74
commit bd39cf0
Showing
4 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from bravado_core.schema import is_prop_nullable | ||
from bravado_core.spec import Spec | ||
|
||
|
||
def test_true(minimal_swagger_spec): | ||
prop_spec = { | ||
'type': 'string', | ||
'x-nullable': True, | ||
} | ||
assert is_prop_nullable(minimal_swagger_spec, prop_spec) | ||
|
||
|
||
def test_false(minimal_swagger_spec): | ||
prop_spec = { | ||
'type': 'string', | ||
} | ||
assert not is_prop_nullable(minimal_swagger_spec, prop_spec) | ||
|
||
|
||
def test_false_explicit(minimal_swagger_spec): | ||
prop_spec = { | ||
'type': 'string', | ||
'x-nullable': False, | ||
} | ||
assert not is_prop_nullable(minimal_swagger_spec, prop_spec) | ||
|
||
|
||
def test_ref_true(minimal_swagger_dict): | ||
minimal_swagger_dict['definitions'] = { | ||
'Pet': { | ||
'type': 'object', | ||
'x-nullable': True, | ||
} | ||
} | ||
param_spec = {'$ref': '#/definitions/Pet'} | ||
swagger_spec = Spec.from_dict(minimal_swagger_dict) | ||
assert is_prop_nullable(swagger_spec, param_spec) | ||
|
||
|
||
def test_ref_false(minimal_swagger_dict): | ||
minimal_swagger_dict['definitions'] = { | ||
'Pet': { | ||
'type': 'object', | ||
} | ||
} | ||
param_spec = {'$ref': '#/definitions/Pet'} | ||
swagger_spec = Spec.from_dict(minimal_swagger_dict) | ||
assert not is_prop_nullable(swagger_spec, param_spec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters