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

Improve swagger documentation for method-based DRF endpoints #7036

Closed
jonboiser opened this issue Jun 11, 2020 · 3 comments
Closed

Improve swagger documentation for method-based DRF endpoints #7036

jonboiser opened this issue Jun 11, 2020 · 3 comments
Assignees
Labels
TAG: dev experience Build performance, linting, debugging... TAG: developer docs Technical docs and code comments

Comments

@jonboiser
Copy link
Contributor

The ask: more detailed documentation on swagger, like what is done for the more full-featured ModelViewSets

For example, this cleartasks endpoint is implemented as a method on the main viewset....

@action(methods=["post"], detail=False)
def cleartask(self, request):
# Given a single task ID, clear it from the queue
task_id = request.data.get("task_id")
if not task_id:
return Response({})
for _queue in self.queues:
_queue.clear_job(task_id)
return Response({"task_id": task_id})

...The swagger docs will show a comment, but no extra documentation about the parameters

image

Compare to this endpoint, which seems to automatically create documentation on the payload shape

image

@jonboiser jonboiser added TAG: developer docs Technical docs and code comments TAG: dev experience Build performance, linting, debugging... labels Jun 11, 2020
@rtibbles
Copy link
Member

rtibbles commented Jul 1, 2020

Guessing the information is introspected from the serializer - so this will be the case for any endpoint we setup that does not have an explicit serializer associated with it. Will look into alternatives here.

@rtibbles rtibbles self-assigned this Jul 1, 2020
@jonboiser
Copy link
Contributor Author

jonboiser commented Jul 24, 2020

I'm having a hard time finding a newbie-level tutorial on this, but I think if you can somehow provide an OpenAPI schema for these endpoints (maybe in some external YML file?), Swagger will be able to show it on its API explorer.

It might also be beneficial just do the work and making really basic Serializer classes for these endpoints, instead of sending these Response(dictionaryLiteral) type responses.

@rtibbles
Copy link
Member

This was addressed by automatic serializer generation here: #8138 to help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TAG: dev experience Build performance, linting, debugging... TAG: developer docs Technical docs and code comments
Projects
None yet
Development

No branches or pull requests

2 participants