mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 01:20:02 +03:00
Improved my proposition with:
- added version to high level API get_schema_view - updated the documentation
This commit is contained in:
parent
9a94129ed5
commit
cb243989cf
|
@ -60,7 +60,8 @@ urlpatterns = [
|
||||||
# * Provide view name for use with `reverse()`.
|
# * Provide view name for use with `reverse()`.
|
||||||
path('openapi', get_schema_view(
|
path('openapi', get_schema_view(
|
||||||
title="Your Project",
|
title="Your Project",
|
||||||
description="API for all things …"
|
description="API for all things …",
|
||||||
|
version="1.0.0"
|
||||||
), name='openapi-schema'),
|
), name='openapi-schema'),
|
||||||
# ...
|
# ...
|
||||||
]
|
]
|
||||||
|
@ -72,6 +73,7 @@ The `get_schema_view()` helper takes the following keyword arguments:
|
||||||
|
|
||||||
* `title`: May be used to provide a descriptive title for the schema definition.
|
* `title`: May be used to provide a descriptive title for the schema definition.
|
||||||
* `description`: Longer descriptive text.
|
* `description`: Longer descriptive text.
|
||||||
|
* `version`: The version of the API. Defaults to `0.1.0`.
|
||||||
* `url`: May be used to pass a canonical base URL for the schema.
|
* `url`: May be used to pass a canonical base URL for the schema.
|
||||||
|
|
||||||
schema_view = get_schema_view(
|
schema_view = get_schema_view(
|
||||||
|
@ -137,6 +139,7 @@ Arguments:
|
||||||
|
|
||||||
* `title` **required**: The name of the API.
|
* `title` **required**: The name of the API.
|
||||||
* `description`: Longer descriptive text.
|
* `description`: Longer descriptive text.
|
||||||
|
* `version`: The version of the API. Defaults to `0.1.0`.
|
||||||
* `url`: The root URL of the API schema. This option is not required unless the schema is included under path prefix.
|
* `url`: The root URL of the API schema. This option is not required unless the schema is included under path prefix.
|
||||||
* `patterns`: A list of URLs to inspect when generating the schema. Defaults to the project's URL conf.
|
* `patterns`: A list of URLs to inspect when generating the schema. Defaults to the project's URL conf.
|
||||||
* `urlconf`: A URL conf module name to use when generating the schema. Defaults to `settings.ROOT_URLCONF`.
|
* `urlconf`: A URL conf module name to use when generating the schema. Defaults to `settings.ROOT_URLCONF`.
|
||||||
|
|
|
@ -31,7 +31,8 @@ def get_schema_view(
|
||||||
title=None, url=None, description=None, urlconf=None, renderer_classes=None,
|
title=None, url=None, description=None, urlconf=None, renderer_classes=None,
|
||||||
public=False, patterns=None, generator_class=None,
|
public=False, patterns=None, generator_class=None,
|
||||||
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
|
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
|
||||||
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES):
|
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES,
|
||||||
|
version=None):
|
||||||
"""
|
"""
|
||||||
Return a schema view.
|
Return a schema view.
|
||||||
"""
|
"""
|
||||||
|
@ -43,7 +44,7 @@ def get_schema_view(
|
||||||
|
|
||||||
generator = generator_class(
|
generator = generator_class(
|
||||||
title=title, url=url, description=description,
|
title=title, url=url, description=description,
|
||||||
urlconf=urlconf, patterns=patterns,
|
urlconf=urlconf, patterns=patterns, version=version
|
||||||
)
|
)
|
||||||
|
|
||||||
# Avoid import cycle on APIView
|
# Avoid import cycle on APIView
|
||||||
|
|
|
@ -124,7 +124,7 @@ class SchemaGenerator(BaseSchemaGenerator):
|
||||||
# Set by 'SCHEMA_COERCE_METHOD_NAMES'.
|
# Set by 'SCHEMA_COERCE_METHOD_NAMES'.
|
||||||
coerce_method_names = None
|
coerce_method_names = None
|
||||||
|
|
||||||
def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None):
|
def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None, version=None):
|
||||||
assert coreapi, '`coreapi` must be installed for schema support.'
|
assert coreapi, '`coreapi` must be installed for schema support.'
|
||||||
assert coreschema, '`coreschema` must be installed for schema support.'
|
assert coreschema, '`coreschema` must be installed for schema support.'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user