| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import json |
| 4 |
|
| 5 |
from django.http import HttpRequest, HttpResponse |
| 6 |
from django.utils.decorators import method_decorator |
| 7 |
from django.views.generic import TemplateView, View |
| 8 |
|
| 9 |
from allauth.account.internal.decorators import login_not_required |
| 10 |
from allauth.headless import app_settings |
| 11 |
from allauth.headless.spec.internal.schema import get_schema |
| 12 |
|
| 13 |
|
| 14 |
@method_decorator(login_not_required, name="dispatch") |
| 15 |
class OpenAPIYAMLView(View): |
| 16 |
def get(self, request: HttpRequest) -> HttpResponse: |
| 17 |
import yaml |
| 18 |
|
| 19 |
spec = get_schema() |
| 20 |
content = yaml.dump(spec, Dumper=yaml.Dumper) |
| 21 |
return HttpResponse( |
| 22 |
content, |
| 23 |
content_type="application/vnd.oai.openapi", |
| 24 |
headers={"Content-Disposition": "inline; filename=allauth-openapi.yaml"}, |
| 25 |
) |
| 26 |
|
| 27 |
|
| 28 |
@method_decorator(login_not_required, name="dispatch") |
| 29 |
class OpenAPIJSONView(View): |
| 30 |
def get(self, request: HttpRequest) -> HttpResponse: |
| 31 |
spec = get_schema() |
| 32 |
content = json.dumps(spec) |
| 33 |
return HttpResponse( |
| 34 |
content, |
| 35 |
content_type="application/vnd.oai.openapi+json", |
| 36 |
headers={"Content-Disposition": "inline; filename=allauth-openapi.json"}, |
| 37 |
) |
| 38 |
|
| 39 |
|
| 40 |
@method_decorator(login_not_required, name="dispatch") |
| 41 |
class OpenAPIHTMLView(TemplateView): |
| 42 |
def get_template_names(self) -> list[str]: |
| 43 |
return [app_settings.SPECIFICATION_TEMPLATE_NAME] |