parent
7c5a0b7176
commit
df82fe59d7
|
|
@ -47,8 +47,7 @@ Features
|
||||||
`redoc <https://github.com/Rebilly/ReDoc>`_ for viewing the generated documentation
|
`redoc <https://github.com/Rebilly/ReDoc>`_ for viewing the generated documentation
|
||||||
- schema view is cacheable out of the box
|
- schema view is cacheable out of the box
|
||||||
- generated Swagger schema can be automatically validated by
|
- generated Swagger schema can be automatically validated by
|
||||||
`swagger-spec-validator <https://github.com/Yelp/swagger_spec_validator>`_ or
|
`swagger-spec-validator <https://github.com/Yelp/swagger_spec_validator>`_
|
||||||
`flex <https://github.com/pipermerriam/flex>`_
|
|
||||||
- supports Django REST Framework API versioning with ``URLPathVersioning`` and ``NamespaceVersioning``; other DRF
|
- supports Django REST Framework API versioning with ``URLPathVersioning`` and ``NamespaceVersioning``; other DRF
|
||||||
or custom versioning schemes are not currently supported
|
or custom versioning schemes are not currently supported
|
||||||
|
|
||||||
|
|
@ -166,7 +165,7 @@ a. ``get_schema_view`` parameters
|
||||||
- ``patterns`` - passed to SchemaGenerator
|
- ``patterns`` - passed to SchemaGenerator
|
||||||
- ``urlconf`` - passed to SchemaGenerator
|
- ``urlconf`` - passed to SchemaGenerator
|
||||||
- ``public`` - if False, includes only endpoints the current user has access to
|
- ``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``
|
- ``generator_class`` - schema generator class to use; should be a subclass of ``OpenAPISchemaGenerator``
|
||||||
- ``authentication_classes`` - authentication classes for the schema view itself
|
- ``authentication_classes`` - authentication classes for the schema view itself
|
||||||
- ``permission_classes`` - permission 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
|
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
|
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.
|
schema is not valid, a :python:`SwaggerValidationError` is raised by the handling codec.
|
||||||
|
|
||||||
**Warning:** This internal validation can slow down your server.
|
**Warning:** This internal validation can slow down your server.
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,2 @@
|
||||||
# requirements for the validation feature
|
# requirements for the validation feature
|
||||||
flex>=6.11.1
|
|
||||||
swagger-spec-validator>=2.1.0
|
swagger-spec-validator>=2.1.0
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,12 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _validate_flex(spec):
|
def _validate_flex(spec):
|
||||||
|
try:
|
||||||
from flex.core import parse as validate_flex
|
from flex.core import parse as validate_flex
|
||||||
from flex.exceptions import ValidationError
|
from flex.exceptions import ValidationError
|
||||||
|
except ImportError:
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
validate_flex(spec)
|
validate_flex(spec)
|
||||||
except ValidationError as ex:
|
except ValidationError as ex:
|
||||||
|
|
|
||||||
|
|
@ -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 patterns: same as :class:`.OpenAPISchemaGenerator`
|
||||||
:param urlconf: 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 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 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 authentication_classes: authentication classes for the schema view itself
|
||||||
:param tuple permission_classes: permission classes for the schema view itself
|
:param tuple permission_classes: permission classes for the schema view itself
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,15 @@ def swagger_dict(swagger, codec_json):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def validate_schema():
|
def validate_schema():
|
||||||
def validate_schema(swagger):
|
def validate_schema(swagger):
|
||||||
|
try:
|
||||||
from flex.core import parse as validate_flex
|
from flex.core import parse as validate_flex
|
||||||
from swagger_spec_validator.validator20 import validate_spec as validate_ssv
|
|
||||||
|
|
||||||
validate_flex(copy.deepcopy(swagger))
|
validate_flex(copy.deepcopy(swagger))
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
from swagger_spec_validator.validator20 import validate_spec as validate_ssv
|
||||||
|
|
||||||
validate_ssv(copy.deepcopy(swagger))
|
validate_ssv(copy.deepcopy(swagger))
|
||||||
|
|
||||||
return validate_schema
|
return validate_schema
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue