Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To add GET parameters in Swagger

Use django rest framework and django-rest-swagger in documentation of the methods it is not showing available GET parameters and the question is how can I set?

code:

# views.py
@api_view(['GET'])
def tests_api(request):
    """

    :param request:
    :return:
    """
    id = request.query_params.get('id')
    name = request.query_params.get('name')

    return Response({'user': name, 'text': 'Hello world'})

# urls.py
urlpatterns = [
    url(r"^api/v1/tests_api/$", tests_api),
]

http api:

GET https://127.0.0.1/api/v1/tests_api/?name=Denis&id=3

HTTP/1.1 200 OK
...
{
    "user": "Denis",
    "text": "Hello world"
}

now: enter image description here example: enter image description here

Russian version.

like image 762
devnull Avatar asked Sep 13 '25 19:09

devnull


1 Answers

Declare schema manually and specify fields there with location query

  schema = ManualSchema(fields=[
        coreapi.Field(
            "name",
            required=True,
            location="query",
            schema=coreschema.String()
        ),
    ]
  )

See doc for details

like image 70
fo2rist Avatar answered Sep 15 '25 09:09

fo2rist