Skip to content
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

Add tags to Swagger OpenAPI schemas #7104

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 0 deletions rest_framework/schemas/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ def get_paths(self, request=None):
operation = view.schema.get_operation(path, method)
# Normalise path for any provided mount url.
if path.startswith('/'):
tags = [path.split('/')[1]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phuongtai @carltongibson This will not work for nested resources.

Let's assume a restaurant management system. We have restaurants. Each restaurant has branches and each branch has inspections. To retrieve single inspection for a branch, following might be a URL:

/restaurants/{restaurant_id}/branches/{branch_id}/inspections/{inspection_id}

Ideally, tags for this path will be inspections but your code will generate restaurants

Realtime Example: Retrieve billing information for a sub-account by zoom.us
In case, the path is /accounts/{accountId}/billing and schema tag is billing not accounts

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood your problem, I've just resolved the problem which is putting all of APIs by tags default. I removed it and get default tags is a top level of each APIs. So we have to find the better solutions which may be automatically or manually generated.

Copy link
Contributor

@dhaval-mehta dhaval-mehta Feb 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My Idea is to extract the tags from the view-set. Spring Framework is doing the same.
@phuongtai Are you working on it? We also need this feature.

path = path[1:]
path = urljoin(self.url or '/', path)

result.setdefault(path, {})
result[path][method.lower()] = operation
result[path][method.lower()].update(tags=tags)

return result

Expand Down