Pattern validation fails with swagger-parser v2
On the v1 branch there is a PatternValidationTest with a request validation with string patterns. That test works.
By adding this test to the v2 (master) branch it fails.
I remember vaguely that the swagger-parser parses the schemas wrongly.
Attached is the ported test with the schemas.
Comments (6)
-
reporter -
I recreated the issue from your test - it looks like the problem is the content type is not being set on the request.
The validator is now (as of v2.0) strict in requiring a content type to be present when validating request bodies - it will no longer “guess” that
application/json
is the intended content type.I added some additional test coverage to demonstrate that the patterns are being validated https://bitbucket.org/atlassian/swagger-request-validator/branch/233-pattern-validation?dest=236-separate-createFor-methods#diff
There is already some (basic) test coverage in https://bitbucket.org/atlassian/swagger-request-validator/src/master/swagger-request-validator-core/src/test/java/com/atlassian/oai/validator/interaction/request/StringParameterValidationTest.java#lines-63 but the actual validation logic is now delegated entirely to the jsonschema validation library.
Please let me know if Ive misunderstood something.
Cheers.
-
reporter Even if I add the right content-type to the PatternValidationTest the “invalid” tests still fail. What is still missing?
The branch you mentioned “233-pattern-validation” is not available.
-
Hmm. Interesting. The branch I linked got merged in https://bitbucket.org/atlassian/swagger-request-validator/pull-requests/143/233-add-additional-test-coverage-for/diff
I’ll try to get some more time to look at this further. Im curious what’s going on.
-
reporter Got it. Some message keys changed from v1 to v2 so my attached tests still failed after adding the mandatory content type. After changing the message key from
validation.schema.pattern
tovalidation.request.body.schema.pattern
my tests are green.Perfect. This issue can be closed.
-
reporter - changed status to invalid
No bug. The attached tests were wrong.
- Log in to comment
On the
OpenAPI
instance the patterns are available. It seems to be parsed correctly. The patterns aren’t simply not be validated.