Skip to content

Detect swagger vs openapi and auto-select appropriate backend #133

@jayvdb

Description

@jayvdb

Expected Behaviour

When flex is installed, it should not be the default unless the input document is swagger.

Minimal Example Spec

n/a

Actual Behaviour

When flex is installed, prance validate my_openapi3.yaml will emit

prance validate my_openapi3.yaml 
Processing "my_openapi3.yaml"...
 -> Resolving external references.
ERROR in "my_openapi3.yaml" [ValidationError]: ErrorDict(<class 'flex.exceptions.ErrorList'>, {'required': [ErrorDict(<class 'flex.exceptions.ErrorList'>, {'swagger': ['This value is required']})]})

The {'swagger': ['This value is required']} in there is reasonably informative if you know/remember what flex is looking for.
But it isnt a great UX for people using openapi3, which is going to be an increasing percentage of users as openapi v3 replaces swagger.

The easiest approach is to re-organise the imports in

def validation_backends():
, so that openapi_spec_validator is first, and IMO flex should be last it has seen releases recently at https://pypi.org/project/flex/, while swagger_spec_validator is better maintained.

If there is some backwards compatibility reason for keeping flex first, it should be possible for it to only be first if the context is a swagger input.

Steps to Reproduce

  1. Install flex
  2. Run prance validate any_openapi3_schema.yaml

Environment

  • OS: Linux
  • Python version: 3.10
  • Swagger/OpenAPI version used: 3.0
  • Backend: flex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions