api.v2 package

The second version of the API.

Submodules

api.v2.apps module

App configuration.

class api.v2.apps.ApiV2Config(app_name, app_module)[source]

Bases: django.apps.AppConfig

Configuration for the api.v2 app.

name = 'api.v2'

str – The name of the app.

api.v2.auth module

Authentication & authorization utilities.

class api.v2.auth.ApiKeyAuthentication[source]

Bases: rest_framework.authentication.TokenAuthentication

API key authentication class.

keyword = 'X-API-Key'
model

alias of users.models.ApiKey

authenticate(request)[source]

Authenticate the request and return a two-tuple of (user, token).

Parameters

request (Request) –

Return type

Optional[Tuple]

class api.v2.auth.ScanlatorPermissions[source]

Bases: rest_framework.permissions.DjangoObjectPermissions

Authorization class for scanlators.

authenticated_users_only = False

api.v2.mixins module

API mixin classes.

class api.v2.mixins.CORSMixin[source]

Bases: object

cors_headers = {'Access-Control-Allow-Headers': 'X-API-Key', 'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS', 'Access-Control-Allow-Origin': '*'}

dict – Mixin that sets CORS headers.

property default_response_headers
Return type

Dict

classmethod decorator(func)[source]

Use the CORS headers as a view decorator.

Parameters

func (Callable) –

Return type

Callable

api.v2.pagination module

Pagination utilities.

class api.v2.pagination.DummyPagination[source]

Bases: rest_framework.pagination.BasePagination

Dummy pagination class that simply wraps results.

to_html()[source]
Return type

str

paginate_queryset(*args, **kwargs)[source]
Return type

List

get_paginated_response(data)[source]
Parameters

data (Any) –

Return type

Response

get_paginated_response_schema(schema)[source]
Parameters

schema (Dict) –

Return type

Dict

class api.v2.pagination.PageLimitPagination[source]

Bases: rest_framework.pagination.PageNumberPagination

Pagination class that allows the user to limit the page size.

page_size_query_param = 'limit'
get_paginated_response(data)[source]
Parameters

data (Any) –

Return type

Response

get_paginated_response_schema(schema)[source]
Parameters

schema (Dict) –

Return type

Dict

get_schema_operation_parameters(view)[source]
Parameters

view (Any) –

Return type

Dict

api.v2.schema module

Schema utilities.

class api.v2.schema.OpenAPISchema(tags=None, operation_id_base=None, component_name=None)[source]

Bases: rest_framework.schemas.openapi.AutoSchema

Custom OpenAPI schema class.

header_regex = re.compile('^\\* [a-z]+:')
variable_regex = re.compile('{([^}]+)}')
map_field(field)[source]
Parameters

field (Any) –

Return type

Dict

map_field_validators(field, schema)[source]

map field validators

Parameters
  • field (Any) –

  • schema (Dict) –

map_serializer(serializer)[source]
Parameters

serializer (BaseSerializer) –

Return type

Dict

get_operation(path, method)[source]
Parameters
  • path (str) –

  • method (str) –

Return type

Dict

get_path_parameters(path, method)[source]

Return a list of parameters from templated path variables.

Parameters
  • path (str) –

  • method (str) –

Return type

List[Dict]

allows_filters(path, method)[source]

Determine whether to include filter Fields in schema.

Default implementation looks for ModelViewSet or GenericAPIView actions/methods that cause filtering on the default implementation.

Parameters
  • path (str) –

  • method (str) –

Return type

bool

class api.v2.schema.OpenAPISchemaGenerator(title=None, url=None, description=None, patterns=None, urlconf=None, version=None)[source]

Bases: rest_framework.schemas.openapi.SchemaGenerator

Custom OpenAPI generator class.

get_info()[source]
Return type

Dict

get_schema(*args, **kwargs)[source]

Generate a OpenAPI schema.

Return type

Dict

coerce_path(*args)[source]

Coerce {pk} path arguments into the name of the model field, where possible. This is cleaner for an external representation. (Ie. “this is an identifier”, not “this is a database primary key”)

Return type

str

api.v2.urls module

The URLconf of the api.v2 app.

api.v2.urls.app_name = 'v2'

The URL namespace of the api.v2 app.

api.v2.urls.urlpatterns = [<URLResolver <URLPattern list> (None:None) ''>, <URLPattern 'profile'>, <URLPattern 'openapi.json' [name='schema']>, <URLPattern 'redoc/' [name='redoc']>, <URLPattern 'swagger/' [name='swagger']>]

The URL patterns of the api.v2 app.

api.v2.views module

The custom views of the api.v2 app.

api.v2.views.openapi(self, request, *args, **kwargs)

The generated OpenAPI schema as a view.

api.v2.views.redoc_redirect(request)[source]

Redirect to the ReDoc demo with our schema.

Parameters

request (HttpRequest) –

Return type

HttpResponsePermanentRedirect

api.v2.views.swagger_redirect(request)[source]

Redirect to the Swagger generator with our schema.

Parameters

request (HttpRequest) –

Return type

HttpResponsePermanentRedirect