Skip to content

Commit

Permalink
Merge pull request #482 from dandi/enh-1line-docstring
Browse files Browse the repository at this point in the history
ENH(UX): overload @swagger_auto_schema to show one-line docstrings as summary
  • Loading branch information
dchiquito committed Aug 24, 2021
2 parents c9d4629 + c2fef6b commit feed928
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dandiapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def before_binding(configuration: Type[ComposedConfiguration]):
#
# When Brian Helba is able to resolve this problem upstream (in
# django-composed-configuration) we can remove this setting.
SWAGGER_SETTINGS = {}
SWAGGER_SETTINGS = {
'DEFAULT_AUTO_SCHEMA_CLASS': 'dandiapi.swagger.DANDISwaggerAutoSchema',
}


class DevelopmentConfiguration(DandiMixin, DevelopmentBaseConfiguration):
Expand Down
19 changes: 19 additions & 0 deletions dandiapi/swagger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Separate from settings.py due to being a somewhat of a premature import there.
# See https://github.com/dandi/dandi-api/pull/482#issuecomment-901250541 .
from drf_yasg.inspectors import SwaggerAutoSchema


class DANDISwaggerAutoSchema(SwaggerAutoSchema):
"""Custom class for @swagger_auto_schema to provide summary from one line docstrings.
See https://github.com/axnsan12/drf-yasg/issues/205 and
https://github.com/axnsan12/drf-yasg/issues/265 for more information on why it is not
a default behavior.
"""

def split_summary_from_description(self, description):
summary, description = super().split_summary_from_description(description)
if summary is None:
return description, None
else:
return summary, description

0 comments on commit feed928

Please sign in to comment.