-
Notifications
You must be signed in to change notification settings - Fork 252
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
Document how to use drf-spectacular with function-based views #635
Comments
For those that might stumble upon this. Here is an example that could help: @extend_schema(responses=MyConfigSerializer)
@api_view()
@permission_classes([AllowAny])
def my_configuration(request: Request) -> Response:
"""My Docs."""
instance = MyConfig.get_solo() # Using django-solo in this example.
serializer = MyConfigurationSerializer(instance)
return Response(serializer.data) Register the function to a URL: urlpatterns = [
...
# Function-based view.
path("api/my-configuration/", my_configuration, name="my-configuration"),
] |
Hey @johnthagen, I assumed this was kind of obvious. Explaining how Maybe a FAQ entry? not sure where to put this ideally. |
@tfranzel Yes, as I worked through this, a big part of the issue is actually what I perceive as a lack of documentation within DRF itself as well for function-based views. Yeah, perhaps a FAQ entry is enough? I think just the fact that there weren't any examples was what made it harder to get started. Worst case, I thought this issue's existence and my short example could be something someone else could find in the future. |
Perhaps point users to the tests if that is the best source of examples? |
Added a FAQ entry that may help. Generally, virtually every (intended) usage pattern is covered in the tests. I tried making them compact, but finding a specific usage pattern in hundreds of tests is tricky in itself. Needle in a haystack you might say. I cannot really judge if people besides me are able to navigate the tests in meaningful way. I know where to look because I've written most of them. Have you used the tests like this? |
@tfranzel That FAQ entry is great! I think we can call this issue closed now. Thanks! |
The docs say:
https://github.com/tfranzel/drf-spectacular/blob/fb4c8410357b8a987991888d026167496165e95a/README.rst#drf-spectacular
But currently the documentation doesn't have any examples for how to use it with function-based views. This has led to stack overflow questions like:
It would be helpful for this use case to document some basic function-based examples, and if there are any supported ways to reduce manual boilerplate (like type hints?).
The text was updated successfully, but these errors were encountered: