Skip to content

Swagger: add summary on method documentation #637

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion flask_restx/reqparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ def __schema__(self):
param["type"] = "array"
param["collectionFormat"] = "csv"
if self.choices:
param["enum"] = self.choices
if param.get("collectionFormat", None) == "csv" or param.get("collectionFormat", None) == "multi":
param["items"]["enum"] = self.choices
else:
param["enum"] = self.choices
return param


Expand Down
14 changes: 13 additions & 1 deletion flask_restx/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def serialize_resource(self, ns, resource, url, route_doc=None, **kwargs):
def serialize_operation(self, doc, method):
operation = {
"responses": self.responses_for(doc, method) or None,
"summary": doc[method]["docstring"]["summary"],
"summary": self.summary_for( doc, method) or None,
"description": self.description_for(doc, method) or None,
"operationId": self.operation_id_for(doc, method),
"parameters": self.parameters_for(doc[method]) or None,
Expand Down Expand Up @@ -523,6 +523,18 @@ def vendor_fields(self, doc, method):
for k, v in doc[method].get("vendor", {}).items()
)

def summary_for(self, doc, method):
"""Extract the summay metadata and fallback on the whole docstring"""
parts = []
if "summary" in doc:
parts.append(doc["summary"] or "")
if method in doc and "summary" in doc[method]:
parts.append(doc[method]["summary"])
if doc[method]["docstring"]["summary"]:
parts.append(doc[method]["docstring"]["summary"])

return "\n".join(parts).strip()

def description_for(self, doc, method):
"""Extract the description metadata and fallback on the whole docstring"""
parts = []
Expand Down