diff --git a/README.rst b/README.rst index 6ff86f9..2101b49 100644 --- a/README.rst +++ b/README.rst @@ -47,8 +47,7 @@ Features `redoc `_ for viewing the generated documentation - schema view is cacheable out of the box - generated Swagger schema can be automatically validated by - `swagger-spec-validator `_ or - `flex `_ + `swagger-spec-validator `_ - supports Django REST Framework API versioning with ``URLPathVersioning`` and ``NamespaceVersioning``; other DRF or custom versioning schemes are not currently supported @@ -166,7 +165,7 @@ a. ``get_schema_view`` parameters - ``patterns`` - passed to SchemaGenerator - ``urlconf`` - passed to SchemaGenerator - ``public`` - if False, includes only endpoints the current user has access to -- ``validators`` - a list of validator names to apply on the generated schema; allowed values are ``flex``, ``ssv`` +- ``validators`` - a list of validator names to apply on the generated schema; only ``ssv`` is currently supported - ``generator_class`` - schema generator class to use; should be a subclass of ``OpenAPISchemaGenerator`` - ``authentication_classes`` - authentication classes for the schema view itself - ``permission_classes`` - permission classes for the schema view itself @@ -213,7 +212,7 @@ caching the schema view in-memory, with some sane defaults: Given the numerous methods to manually customize the generated schema, it makes sense to validate the result to ensure it still conforms to OpenAPI 2.0. To this end, validation is provided at the generation point using python swagger -libraries, and can be activated by passing :python:`validators=['flex', 'ssv']` to ``get_schema_view``; if the generated +libraries, and can be activated by passing :python:`validators=['ssv']` to ``get_schema_view``; if the generated schema is not valid, a :python:`SwaggerValidationError` is raised by the handling codec. **Warning:** This internal validation can slow down your server. diff --git a/requirements/validation.txt b/requirements/validation.txt index 65e9d43..b7eba49 100644 --- a/requirements/validation.txt +++ b/requirements/validation.txt @@ -1,3 +1,2 @@ # requirements for the validation feature -flex>=6.11.1 swagger-spec-validator>=2.1.0 diff --git a/src/drf_yasg/codecs.py b/src/drf_yasg/codecs.py index 2ed6980..03fd1ed 100644 --- a/src/drf_yasg/codecs.py +++ b/src/drf_yasg/codecs.py @@ -15,8 +15,12 @@ logger = logging.getLogger(__name__) def _validate_flex(spec): - from flex.core import parse as validate_flex - from flex.exceptions import ValidationError + try: + from flex.core import parse as validate_flex + from flex.exceptions import ValidationError + except ImportError: + return + try: validate_flex(spec) except ValidationError as ex: diff --git a/src/drf_yasg/views.py b/src/drf_yasg/views.py index 256f26c..9fdbe4a 100644 --- a/src/drf_yasg/views.py +++ b/src/drf_yasg/views.py @@ -57,7 +57,7 @@ def get_schema_view(info=None, url=None, patterns=None, urlconf=None, public=Fal :param patterns: same as :class:`.OpenAPISchemaGenerator` :param urlconf: same as :class:`.OpenAPISchemaGenerator` :param bool public: if False, includes only the endpoints that are accesible by the user viewing the schema - :param list validators: a list of validator names to apply; allowed values are ``flex``, ``ssv`` + :param list validators: a list of validator names to apply; the only allowed value is ``ssv``, for now :param type generator_class: schema generator class to use; should be a subclass of :class:`.OpenAPISchemaGenerator` :param tuple authentication_classes: authentication classes for the schema view itself :param tuple permission_classes: permission classes for the schema view itself diff --git a/tests/conftest.py b/tests/conftest.py index 48180aa..b2df9d8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,10 +57,15 @@ def swagger_dict(swagger, codec_json): @pytest.fixture def validate_schema(): def validate_schema(swagger): - from flex.core import parse as validate_flex + try: + from flex.core import parse as validate_flex + + validate_flex(copy.deepcopy(swagger)) + except ImportError: + pass + from swagger_spec_validator.validator20 import validate_spec as validate_ssv - validate_flex(copy.deepcopy(swagger)) validate_ssv(copy.deepcopy(swagger)) return validate_schema