mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 08:59:54 +03:00
- title and version are required by openapi specification 3.x
- fixed my mistake with default parameter - reverted my documentation change after tomchristie default version change to ''
This commit is contained in:
parent
89ac0a1c7e
commit
c90bc0af4d
|
@ -73,7 +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.
|
||||
* `description`: Longer descriptive text.
|
||||
* `version`: The version of the API. Defaults to `0.1.0`.
|
||||
* `version`: The version of the API.
|
||||
* `url`: May be used to pass a canonical base URL for the schema.
|
||||
|
||||
schema_view = get_schema_view(
|
||||
|
|
|
@ -151,7 +151,7 @@ class BaseSchemaGenerator(object):
|
|||
# Set by 'SCHEMA_COERCE_PATH_PK'.
|
||||
coerce_path_pk = None
|
||||
|
||||
def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None, version=''):
|
||||
def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None, version=None):
|
||||
if url and not url.endswith('/'):
|
||||
url += '/'
|
||||
|
||||
|
|
|
@ -21,6 +21,14 @@ from .utils import get_pk_description, is_list_view
|
|||
|
||||
class SchemaGenerator(BaseSchemaGenerator):
|
||||
|
||||
def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None, version=None):
|
||||
# Title and version are required by openapi specification 3.x
|
||||
if title is None:
|
||||
title = ''
|
||||
if version is None:
|
||||
version = ''
|
||||
super().__init__(title, url, description, patterns, urlconf, version)
|
||||
|
||||
def get_info(self):
|
||||
info = {
|
||||
'title': self.title,
|
||||
|
|
|
@ -570,3 +570,16 @@ class TestGenerator(TestCase):
|
|||
assert schema['info']['title'] == 'My title'
|
||||
assert schema['info']['version'] == '1.2.3'
|
||||
assert schema['info']['description'] == 'My description'
|
||||
|
||||
def test_schema_information_empty(self):
|
||||
"""Construction of the top level dictionary."""
|
||||
patterns = [
|
||||
url(r'^example/?$', views.ExampleListView.as_view()),
|
||||
]
|
||||
generator = SchemaGenerator(patterns=patterns)
|
||||
|
||||
request = create_request('/')
|
||||
schema = generator.get_schema(request=request)
|
||||
|
||||
assert schema['info']['title'] == ''
|
||||
assert schema['info']['version'] == ''
|
||||
|
|
Loading…
Reference in New Issue
Block a user