Skip to content

OpenAPI: Fixed generation when title or version not provided. #6912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api-guide/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion rest_framework/schemas/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 += '/'

Expand Down
5 changes: 3 additions & 2 deletions rest_framework/schemas/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
class SchemaGenerator(BaseSchemaGenerator):

def get_info(self):
# Title and version are required by openapi specification 3.x
info = {
'title': self.title,
'version': self.version,
'title': self.title or '',
'version': self.version or ''
}

if self.description is not None:
Expand Down
13 changes: 13 additions & 0 deletions tests/schemas/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,16 @@ def test_schema_information(self):
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'] == ''