Skip to content

Commit

Permalink
Use schema_url in SpectacularElementsView (#1067)
Browse files Browse the repository at this point in the history
* Use schema_url in SpectacularElementsView

* Add _get_schema_url

* remove schema_url var

* Add _get_schema_url to RapidocView
  • Loading branch information
q0w authored Sep 6, 2023
1 parent 3b028c2 commit 949ad85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions docs/blueprints/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class SpectacularElementsView(APIView):

@extend_schema(exclude=True)
def get(self, request, *args, **kwargs):
schema_url = self.url or get_relative_url(reverse(self.url_name, request=request))
schema_url = set_query_parameters(schema_url, lang=request.GET.get('lang'), version=request.GET.get('version'))
return Response(
data={
'title': self.title,
Expand All @@ -31,3 +29,11 @@ def get(self, request, *args, **kwargs):
},
template_name=self.template_name
)

def _get_schema_url(self, request):
schema_url = self.url or get_relative_url(reverse(self.url_name, request=request))
return set_query_parameters(
url=schema_url,
lang=request.GET.get('lang'),
version=request.GET.get('version')
)
12 changes: 9 additions & 3 deletions docs/blueprints/rapidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ class SpectacularRapiDocView(APIView):

@extend_schema(exclude=True)
def get(self, request, *args, **kwargs):
schema_url = self.url or get_relative_url(reverse(self.url_name, request=request))
schema_url = set_query_parameters(schema_url, lang=request.GET.get('lang'))
return Response(
data={
'title': self.title,
'dist': 'https://cdn.jsdelivr.net/npm/rapidoc@latest',
'schema_url': schema_url,
'schema_url': self._get_schema_url(request),
},
template_name=self.template_name,
)

def _get_schema_url(self, request):
schema_url = self.url or get_relative_url(reverse(self.url_name, request=request))
return set_query_parameters(
url=schema_url,
lang=request.GET.get('lang'),
version=request.GET.get('version')
)

0 comments on commit 949ad85

Please sign in to comment.