-
Notifications
You must be signed in to change notification settings - Fork 98
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
Allow null option for properties #64
Conversation
+1 |
Thanks for the PR. Haven't had time to review yet so it will probably be next week. |
@patch('jsonschema._validators.type_draft4') | ||
def test_skip_when_nullable_property_schema_and_value_is_None( | ||
m_draft4_type_validator, minimal_swagger_spec): | ||
param_schema = {'name': 'foo', 'x-nullable': True, 'type': 'string'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean for this to be prop_schema
with no name
key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I'll change that.
What is your interpretation of |
My understanding of the spec is that
I'm not sure if this is possible because |
While searching for a good solution, I discovered that JSON Schema allows a list of types - e.g. |
This would be a really nice feature to have! There is a long thread on the OpenAPI-Specification (formerly The Swagger Specification) repository discussing how they want to solve this and leaning towards the Unfortunately it seems from the discussion that using arrays for type is not intended with the 2.0 spec (which seems to be indicated as feature frozen) OAI/OpenAPI-Specification#229 (comment) Are there things I can do to help get this PR finished? |
As @wasbazi says, this would be a nice feature to have! |
The CR has an outstanding issue, see #64 (comment) |
Can we merge this? people are eager to see it released. |
2e60f00
to
a6c1382
Compare
The schema passed to type_validator is a prop_schema in these test cases. Yelp#64 (diff)
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
The schema passed to type_validator is a prop_schema in these test cases. Yelp#64 (diff)
a6c1382
to
2a438d6
Compare
The tests show that unmarshaling is not affected by the null option.
2a438d6
to
c581aab
Compare
Finally found some time to continue with this.
The good news is that unmarshaling doesn't seem to be affected (see matrix in https://github.com/andreashug/bravado-core/blob/c581aaba8924afe340f124375015afc9f5743762/tests/unmarshal/unmarshal_nullable_test.py) The not so good news however is, I'm not sure how marshaling should behave in combination with bravado-core/bravado_core/marshal.py Lines 129 to 130 in 7d13d25
x-nullable is True . Or we could say that x-nullable is only for properties and not accounted in parameter specs.
Any opinions on that? |
Great stuff @andreashug! I'm still travelling, I'll take a closer look at the patch on Tuesday. |
m_draft4_type_validator, minimal_swagger_spec): | ||
prop_schema = {'x-nullable': False, 'type': 'string'} | ||
args = (None, prop_schema['type'], None, prop_schema) | ||
list(type_validator(minimal_swagger_spec, *args)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use keyword arguments here as well, just like you did in the test above. It's more readable. I know it makes the test a bit longer since you have to repeat the arguments below, but I think that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because assert_called_once_with()
expects the arguments without keywords. The existing tests in this file do it this way so I aligned with them ;-)
Reduce test complexity by splitting up in multiple tests, suggested in Yelp#64 (comment)
Regarding |
This is great! Could you please create another paste? I didn't manage to open it in time. 😁 |
Sure: http://pastebin.com/U3xeA48R (Seems like there is a bug in expiration settings on dpaste.de) |
Thanks again @andreashug! While I think we could even ship this without fixing the edge case about a required x-nullable parameter, I think the fix is not that difficult:
With it the test you wrote (which is in your dpaste) passes. We might want to handle the other cases (nullable primitives etc.) as well, but honestly I think it's not that important, since the use case for x-nullable are model properties in responses. You're welcome to incorporate this small change as well as the test in the branch though. I'm going to find some time to test this with bravado and make sure it does what we want. 😊 |
An manual test using bravado to query an endpoint that returns a model with an x-nullable field worked perfectly! I'm going to merge this in and work on a second pull request that will contain my above change, a version bump and a big thank you to @andreashug in the changelog. 😊 |
Yay, thanks \o/ |
Proposal for solving #47
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'.