Skip to content

Instantly share code, notes, and snippets.

@darcwader
Created November 25, 2021 18:18
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 darcwader/d589c12be2468e7b7484d5501c3ee671 to your computer and use it in GitHub Desktop.
Save darcwader/d589c12be2468e7b7484d5501c3ee671 to your computer and use it in GitHub Desktop.
swagger documentation for django viewset
class PlanViewset(viewsets.ModelViewSet):
class Schema(AutoSchema):
def get_operation(self, path, method):
op = super().get_operation(path, method)
if method == "GET" and path.split('/')[-2] != '{id}':
op['parameters'].append({
"name": "time_window_id",
"in": "query",
"required": False,
"description": "filters plans based on time_window_id",
'schema': {'type': 'int'}
})
return op
schema = Schema(tags=['courier'])
#... usual code below
queryset = Plan.objects.all()
serializer_class = PlanSerializer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment