python - How to specify a query parameter serializer in django-rest-swagger? -
i'm using django rest framework django-rest-swagger create browsable interface api. can specify request body serializer using yaml docstring, haven't found way specify serializer request query parameters. view using pretty like:
class listbans(basebanview): def get(self, request): """ list profile bans --- response_serializer: backend_serializers.banserializer request_serializer: moderator_serializers.listbansserializer """ serializer = moderator_serializers.listbansserializer(data=request.query_params) if serializer.is_valid(raise_exception=true): # query profile bans data = [] return apiresponse(status=status.http_200_ok, data=data) class listbansserializer(serializers.serializer): limit = serializers.integerfield(default=10, help_text='query limit') offset = serializers.integerfield(default=0, help_text='query offset')
what trying achieve make django-rest-swagger
create form fields query parameters listbansserializer
wouldn't have specify parameters
section manually in docstring. there way that?
i've created simple decorator automatically appends query parameters docstring. source available @ github. here's usage example:
class listbansserializer(serializers.serializer): limit = serializers.integerfield(default=10, help_text='query limit') offset = serializers.integerfield(default=0, help_text='query offset') class listbans(basebanview): @add_query_parameters(listbansserializer) def get(self, request): """ list profile bans --- response_serializer: backend_serializers.banserializer """ serializer = moderator_serializers.listbansserializer(data=request.query_params) if serializer.is_valid(raise_exception=true): # query profile bans data = [] return apiresponse(status=status.http_200_ok, data=data)
Comments
Post a Comment