Skip to content

Commit 0d3d548

Browse files
ysavarycarltongibson
authored andcommitted
OpenAPI: Fixed generation when title or version not provided. (#6912)
1 parent 7c3477d commit 0d3d548

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

docs/api-guide/schemas.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ The `get_schema_view()` helper takes the following keyword arguments:
7373

7474
* `title`: May be used to provide a descriptive title for the schema definition.
7575
* `description`: Longer descriptive text.
76-
* `version`: The version of the API. Defaults to `0.1.0`.
76+
* `version`: The version of the API.
7777
* `url`: May be used to pass a canonical base URL for the schema.
7878

7979
schema_view = get_schema_view(

rest_framework/schemas/generators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class BaseSchemaGenerator(object):
151151
# Set by 'SCHEMA_COERCE_PATH_PK'.
152152
coerce_path_pk = None
153153

154-
def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None, version=''):
154+
def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None, version=None):
155155
if url and not url.endswith('/'):
156156
url += '/'
157157

rest_framework/schemas/openapi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
class SchemaGenerator(BaseSchemaGenerator):
2222

2323
def get_info(self):
24+
# Title and version are required by openapi specification 3.x
2425
info = {
25-
'title': self.title,
26-
'version': self.version,
26+
'title': self.title or '',
27+
'version': self.version or ''
2728
}
2829

2930
if self.description is not None:

tests/schemas/test_openapi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,3 +704,16 @@ def test_schema_information(self):
704704
assert schema['info']['title'] == 'My title'
705705
assert schema['info']['version'] == '1.2.3'
706706
assert schema['info']['description'] == 'My description'
707+
708+
def test_schema_information_empty(self):
709+
"""Construction of the top level dictionary."""
710+
patterns = [
711+
url(r'^example/?$', views.ExampleListView.as_view()),
712+
]
713+
generator = SchemaGenerator(patterns=patterns)
714+
715+
request = create_request('/')
716+
schema = generator.get_schema(request=request)
717+
718+
assert schema['info']['title'] == ''
719+
assert schema['info']['version'] == ''

0 commit comments

Comments
 (0)