Created
November 25, 2021 18:18
-
-
Save darcwader/d589c12be2468e7b7484d5501c3ee671 to your computer and use it in GitHub Desktop.
swagger documentation for django viewset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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