Pattern validation fails with swagger-parser v2

Issue #233 invalid
Sven Döring created an issue

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)

  1. Sven Döring reporter

    On the OpenAPI instance the patterns are available. It seems to be parsed correctly. The patterns aren’t simply not be validated.

    ⁉⁉ ⁉

  2. James Navin

    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.

  3. Sven Döring 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.

  4. Sven Döring 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 to validation.request.body.schema.pattern my tests are green.

    Perfect. This issue can be closed.

  5. Log in to comment