Beispiel #1
0
 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(
         {'schema_url': schema_url},
         template_name=self.template_name
     )
Beispiel #2
0
 def get(self, request, *args, **kwargs):
     if request.GET.get('script') is not None:
         schema_url = self.url or get_relative_url(reverse(self.url_name, request=request))
         return Response(
             data={
                 'schema_url': set_query_parameters(
                     url=schema_url,
                     lang=request.GET.get('lang')
                 ),
                 'settings': json.dumps(spectacular_settings.SWAGGER_UI_SETTINGS),
             },
             template_name=self.template_name_js,
             content_type='application/javascript',
         )
     else:
         script_url = self.url_self or request.get_full_path()
         return Response(
             data={
                 'dist': spectacular_settings.SWAGGER_UI_DIST,
                 'favicon_href': spectacular_settings.SWAGGER_UI_FAVICON_HREF,
                 'script_url': set_query_parameters(
                     url=script_url,
                     lang=request.GET.get('lang'),
                     script=''  # signal to deliver init script
                 )
             },
             template_name=self.template_name,
         )
Beispiel #3
0
 def get(self, request, *args, **kwargs):
     if request.GET.get("script") is not None:
         schema_url = self.url or get_relative_url(
             reverse(self.url_name, request=request)
         )
         return Response(
             data={
                 "schema_url": set_query_parameters(
                     url=schema_url, lang=request.GET.get("lang")
                 ),
                 "settings": json.dumps(spectacular_settings.SWAGGER_UI_SETTINGS),
             },
             template_name=self.template_name_js,
             content_type="application/javascript",
         )
     else:
         script_url = self.url_self or request.get_full_path()
         return Response(
             data={
                 "dist": spectacular_settings.SWAGGER_UI_DIST,
                 "favicon_href": spectacular_settings.SWAGGER_UI_FAVICON_HREF,
                 "script_url": set_query_parameters(
                     url=script_url,
                     lang=request.GET.get("lang"),
                     script="",  # signal to deliver init script
                 ),
             },
             template_name=self.template_name,
         )
Beispiel #4
0
 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={
         'dist': spectacular_settings.REDOC_DIST,
         'schema_url': schema_url,
     },
                     template_name=self.template_name)
Beispiel #5
0
 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,
         lan=request.GET.get("lang"),
         # Default in drf-spectacular here is `version=request.GET.get("version")`, which assumes that the
         # query parameter to both views is called "version".
         # 1. We should use `request.version` instead of `request.GET.get("version") as that also allows
         # for accept-header versioning in the initial request, not just query-parameter versioning
         # 2. We need to pass `api_version` rather than `version` as the query parameter since that's what
         # Nautobot API versioning expects.
         api_version=request.version,
     )
Beispiel #6
0
 def get(self, request, *args, **kwargs):
     schema_url = self.url or get_relative_url(reverse(self.url_name, request=request))
     return Response(
         data={
             'dist': spectacular_settings.SWAGGER_UI_DIST,
             'favicon_href': spectacular_settings.SWAGGER_UI_FAVICON_HREF,
             'schema_url': set_query_parameters(
                 url=schema_url,
                 lang=request.GET.get('lang')
             ),
             'settings': json.dumps(spectacular_settings.SWAGGER_UI_SETTINGS),
             'template_name_js': self.template_name_js
         },
         template_name=self.template_name,
     )
Beispiel #7
0
 def get(self, request, *args, **kwargs):
     schema_url = self.url or get_relative_url(
         reverse(
             self.url_name,
             request=request,
             kwargs={"tenant": request.tenant.schema_name},
         )
     )
     return Response(
         data={
             "dist": spectacular_settings.SWAGGER_UI_DIST,
             "favicon_href": spectacular_settings.SWAGGER_UI_FAVICON_HREF,
             "schema_url": set_query_parameters(
                 url=schema_url, lang=request.GET.get("lang")
             ),
             "settings": json.dumps(spectacular_settings.SWAGGER_UI_SETTINGS),
             "template_name_js": self.template_name_js,
         },
         template_name=self.template_name,
     )