Remove recommandations for unmaintained flex library

Fixes #285
master
Cristi Vijdea 2019-01-29 09:04:10 +02:00
parent 7c5a0b7176
commit df82fe59d7
5 changed files with 17 additions and 10 deletions

View File

@ -47,8 +47,7 @@ Features
`redoc <https://github.com/Rebilly/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 <https://github.com/Yelp/swagger_spec_validator>`_ or
`flex <https://github.com/pipermerriam/flex>`_
`swagger-spec-validator <https://github.com/Yelp/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.

View File

@ -1,3 +1,2 @@
# requirements for the validation feature
flex>=6.11.1
swagger-spec-validator>=2.1.0

View File

@ -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:

View File

@ -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

View File

@ -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