Move Swagger 2 form validation to middleware#1599
Move Swagger 2 form validation to middleware#1599RobbeSneyders merged 2 commits intofeature/form-validationfrom
Conversation
|
|
||
| if collection_formats: | ||
| if len(collection_formats) > 1: | ||
| raise InvalidSpecification( |
There was a problem hiding this comment.
As far as I'm aware, this and the tsv collection format are the only two aspects of the Swagger 2 parameter spec that cannot be translated to the OpenAPI 3 style request body spec.
I think these cases are rare enough that we can decide not to support them so we can unify form validation across versions.
There was a problem hiding this comment.
I'll add an explicit error for the tsv collection format as well though.
There was a problem hiding this comment.
Indeed, I believe you're right. There are just a few exceptions where Swagger 2 and OpenAPI 3:
This instance [tsv], and the case where a parameter has a type of array and a collectionFormat of x (e.g. pipes) and an items.collectionFormat of y (e.g. csv) (giving: a,b|c,d) seem to be the only parts of the 2.0 specification which can't be losslessly converted to 3.0.x
There was a problem hiding this comment.
Ok, so multiple collection formats for a single operation does work, just not multiple collection formats for the same parameter / property. That makes it even more rare. Updated the code to reflect this.
|
No, nothing specific. Some general polishing of the form validation still to do, but I'll do that separately. |
* Move Swagger 2 form validation to middleware * Add unit test for form transformation
* Move Swagger 2 form validation to middleware * Add unit test for form transformation
This PR moves Swagger 2 form validation to the middleware by translating the Swagger 2 form parameter definition into an OpenAPI 3 RequestBody JsonSchema spec. This allows us to use the
FormDataValidatorintroduced in #1595 for Swagger 2 as well instead of the oldParameterValidator.