Skip to content

Move Swagger 2 form validation to middleware#1599

Merged
RobbeSneyders merged 2 commits intofeature/form-validationfrom
feature/swagger-form-validation
Oct 7, 2022
Merged

Move Swagger 2 form validation to middleware#1599
RobbeSneyders merged 2 commits intofeature/form-validationfrom
feature/swagger-form-validation

Conversation

@RobbeSneyders
Copy link
Copy Markdown
Member

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 FormDataValidator introduced in #1595 for Swagger 2 as well instead of the old ParameterValidator.

@RobbeSneyders RobbeSneyders requested a review from Ruwann October 4, 2022 17:39
Comment thread tests/decorators/test_validation.py
Comment thread connexion/operations/swagger2.py
Comment thread connexion/operations/swagger2.py
Comment thread connexion/operations/swagger2.py Outdated

if collection_formats:
if len(collection_formats) > 1:
raise InvalidSpecification(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add an explicit error for the tsv collection format as well though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

OAI/OpenAPI-Specification#1046 (comment)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@RobbeSneyders RobbeSneyders added this to the Connexion 3.0 milestone Oct 4, 2022
Copy link
Copy Markdown
Member

@Ruwann Ruwann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one is good to go - anything you want to still get double checked?

@RobbeSneyders
Copy link
Copy Markdown
Member Author

No, nothing specific. Some general polishing of the form validation still to do, but I'll do that separately.

@RobbeSneyders RobbeSneyders merged commit 7dab993 into feature/form-validation Oct 7, 2022
@RobbeSneyders RobbeSneyders deleted the feature/swagger-form-validation branch October 7, 2022 06:02
RobbeSneyders added a commit that referenced this pull request Nov 3, 2022
* Move Swagger 2 form validation to middleware

* Add unit test for form transformation
RobbeSneyders added a commit that referenced this pull request Nov 4, 2022
* Move Swagger 2 form validation to middleware

* Add unit test for form transformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants