url(r'^matching/ztest/', views.IrisMatching.as_view({'post': 'post'}))
I do get a Swagger endpoint now, but it says “No Parameters” (which I suppose makes sense from a certain perspective). It looks like this…
What do I need to do so that the Swagger page shows a field for the user to enter JSON on this endpoint? Preferrably populated with a correct JSON example of what I want the user to submit?
Thank you - I’m an old Java dev and just inherited this app written by folks who are no longer with the company.
I should add - the data I want to submit has nothing to do with any models or database rows. It is, instead, some strings and a list of Id’s to be consumed by a custom query to do a bit of housekeeping in Prod when there is a certain data issue that comes up regularly…
OK. I can partially answer my question.
I added a serializer to my class above and there is now space for submitting JSON that matches the Serializer’s return from “to_representation”
My concern now is that all the examples I have for Serializers depend on Models. Can I add a Model that does NOT exist in the database? Is there another / better way?
So- this solved it for me:
class FixStaffingChangeReportHireFlagsSerializer(JSONSerializer):
affected_fields = serializers.CharField(max_length=10)
boolean_to_set = serializers.CharField(max_length=5)
list_of_ids = serializers.ListField()
And resulted in this:
You can also try this, here request_body
specifies what data should be POST for the create()
and what kind of responses
will be returned via this URL endpoint. swagger_auto_schema
is a decorator for any method in your viewsets.
from drf_yasg.utils import swagger_auto_schema
from drf_yasg import openapi
class ChangePasswordViewSet(viewsets.ViewSet):
@swagger_auto_schema(
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"email": openapi.Schema(
type=openapi.TYPE_STRING, description="Email Address"
"old_password": openapi.Schema(
type=openapi.TYPE_STRING, description="Previous Password"
"new_password": openapi.Schema(
type=openapi.TYPE_STRING, description="New Password"
responses={
status.HTTP_202_ACCEPTED: openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"status": openapi.Schema(type=openapi.TYPE_NUMBER),
"message": openapi.Schema(type=openapi.TYPE_STRING),
status.HTTP_401_UNAUTHORIZED: openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"status": openapi.Schema(type=openapi.TYPE_NUMBER),
"message": openapi.Schema(type=openapi.TYPE_STRING),
def create(self, request):