snok/drf-openapi-tester

openapi version

Closed this issue · 7 comments

Hi

I have an openapi yaml of version 3.0.1. When I run SchemaTester I get the following failure.

  File "/../venv/lib/python3.9/site-packages/openapi_spec_validator/validation/validators.py", line 75, in validate
    raise err
openapi_spec_validator.validation.exceptions.OpenAPIValidationError: '3.0.1' does not match '^3\\.1\\.\\d+(-.+)?$'

Failed validating 'pattern' in schema['properties']['openapi']:
    {'pattern': '^3\\.1\\.\\d+(-.+)?$', 'type': 'string'}

On instance['openapi']:
    '3.0.1' 

The validator doesn't seem to be picking up that this openapi is of version 3.0.#.
Looking through traceback, it appears that openapi_v31_spec_validator is the set/default validator.
Is it possible to override/address this so it uses openapi_v30_schema_validator

Do you think more granular logic here might solve this?

def validate_schema(schema: dict):

Do you think more granular logic here might solve this?

I think so, how about a regex pattern match on the openapi value here to decide on what schema validator to use?

Sounds sensible to me. Are you able to create a PR?

I don't have bandwidth right now, but I will try to get a PR in soon. Thanks

Version 2.1.2 should be released now. Would you mind testing it when you get a chance @darduf?

Updated 2.1.2 - this OAS validator is working for me now.

Great, thanks again!