Skip to content

Instantly share code, notes, and snippets.

@brunomichetti
Created August 21, 2023 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunomichetti/0626aaf41b2abc0b42e5fefbaa73227d to your computer and use it in GitHub Desktop.
Save brunomichetti/0626aaf41b2abc0b42e5fefbaa73227d to your computer and use it in GitHub Desktop.
from drf_spectacular.utils import OpenApiParameter, extend_schema, OpenApiExample, inline_serializer
# Add this to the action in the UserViewSet
@extend_schema(
responses=inline_serializer(
name="Empty serializer for example (Ignore this).",
fields={"example": serializers.CharField()},
),
examples=[
OpenApiExample(
"Example of metrics response.",
value={"metric_1": 88.5, "metric_2": 25.0, "metric_3": 100.0},
request_only=False,
response_only=True,
),
],
)
@action(detail=False, methods=("GET",))
def metrics(self, request):
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment