Checklist
I noticed that the domain and url within the schema of a response is hard coded (https://github.com/encode/django-rest-framework/blob/master/rest_framework/pagination.py#L240).
I was thinking about making the example string somehow configurable. Not sure how though. Maybe a Django setting?
PAGINATION_EXAMPLE_NEXT= "https://mydomain.com/api/url?{offset_param}=400&{limit_param}=100"
PAGINATION_EXAMPLE_PREV= "https://mydomain.com/api/url??{offset_param}=400&{limit_param}=100"
However, this may not be flexible enough when applying a pagination class to different viewsets.
So maybe we could expand the views by some parameters? Or even getter methods.
class SomeModelViewSet(viewsets.ModelViewSet):
schema_example_domain = "https://mydomain.com"
schema_example_url = reverse_lazy("app:view-name")
def get_schema_example_domain(self):
return self.schema_example_domain
def get_schema_example_url(self):
return self.schema_example_url
It could be passed into get_paginated_response_schema when called (https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas/openapi.py#L665):
response_schema = paginator.get_paginated_response_schema(response_schema, self.view)
This way the domain and the url would be configurable. We could still fallback to the default.
Any thoughts?
Steps to reproduce
Generate a schema with a list view.
Expected behavior
The response should look like this:
responses:
'200':
content:
application/json:
schema:
type: object
properties:
count:
type: integer
example: 123
next:
type: string
nullable: true
format: uri
example: http://my.domain.com/my/url/path/?offset=400&limit=100
previous:
type: string
nullable: true
format: uri
example: http://my.domain.com/my/url/path/?offset=200&limit=100
results:
type: array
items:
$ref: '#/components/schemas/Model'
description: ''
Actual behavior
The response looks somehow like the following:
responses:
'200':
content:
application/json:
schema:
type: object
properties:
count:
type: integer
example: 123
next:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?offset=400&limit=100
previous:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?offset=200&limit=100
results:
type: array
items:
$ref: '#/components/schemas/Model'
description: ''
Checklist
masterbranch of Django REST framework.I noticed that the domain and url within the schema of a response is hard coded (https://github.com/encode/django-rest-framework/blob/master/rest_framework/pagination.py#L240).
I was thinking about making the example string somehow configurable. Not sure how though. Maybe a Django setting?
However, this may not be flexible enough when applying a pagination class to different viewsets.
So maybe we could expand the views by some parameters? Or even getter methods.
It could be passed into
get_paginated_response_schemawhen called (https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas/openapi.py#L665):This way the domain and the url would be configurable. We could still fallback to the default.
Any thoughts?
Steps to reproduce
Generate a schema with a list view.
Expected behavior
The response should look like this:
Actual behavior
The response looks somehow like the following: