UPDATE
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
from .types import OpenApiTypes
|
||||
from .utils import (
|
||||
OpenApiExample,
|
||||
OpenApiParameter,
|
||||
OpenApiResponse,
|
||||
extend_schema,
|
||||
extend_schema_view,
|
||||
inline_serializer,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"OpenApiExample",
|
||||
"OpenApiParameter",
|
||||
"OpenApiResponse",
|
||||
"OpenApiTypes",
|
||||
"extend_schema",
|
||||
"extend_schema_view",
|
||||
"inline_serializer",
|
||||
]
|
||||
@@ -0,0 +1,8 @@
|
||||
class OpenApiTypes:
|
||||
STR = str
|
||||
INT = int
|
||||
BOOL = bool
|
||||
UUID = str
|
||||
DATE = str
|
||||
DATETIME = str
|
||||
OBJECT = dict
|
||||
@@ -0,0 +1,60 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
@dataclass
|
||||
class OpenApiExample:
|
||||
name: str
|
||||
value: object = None
|
||||
request_only: bool = False
|
||||
response_only: bool = False
|
||||
summary: str | None = None
|
||||
description: str | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class OpenApiResponse:
|
||||
response: object = None
|
||||
description: str = ""
|
||||
|
||||
|
||||
class OpenApiParameter:
|
||||
QUERY = "query"
|
||||
PATH = "path"
|
||||
HEADER = "header"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
type=None,
|
||||
location=None,
|
||||
required=False,
|
||||
description="",
|
||||
default=None,
|
||||
):
|
||||
self.name = name
|
||||
self.type = type
|
||||
self.location = location
|
||||
self.required = required
|
||||
self.description = description
|
||||
self.default = default
|
||||
|
||||
|
||||
def extend_schema(*args, **kwargs):
|
||||
def decorator(target):
|
||||
return target
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def extend_schema_view(**kwargs):
|
||||
def decorator(target):
|
||||
return target
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def inline_serializer(*, name, fields):
|
||||
serializer_fields = {"__module__": __name__, **fields}
|
||||
return type(name, (serializers.Serializer,), serializer_fields)
|
||||
@@ -0,0 +1,19 @@
|
||||
from django.http import HttpResponseNotFound
|
||||
from django.views import View
|
||||
|
||||
|
||||
class _DisabledSchemaView(View):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return HttpResponseNotFound("Schema endpoint is disabled.")
|
||||
|
||||
|
||||
class SpectacularAPIView(_DisabledSchemaView):
|
||||
pass
|
||||
|
||||
|
||||
class SpectacularSwaggerView(_DisabledSchemaView):
|
||||
pass
|
||||
|
||||
|
||||
class SpectacularRedocView(_DisabledSchemaView):
|
||||
pass
|
||||
Reference in New Issue
Block a user