django-rest-swagger
django-rest-swagger copied to clipboard
Test using http when api is in https
I have a problem when pressing try it out!
button because request is send to http when my api is listen in https.
Is this a bug or a configuration problem? How could change this?
Here is my solution: I redefined a custom OpenAPIRenderer (subclassing the default one) in order to add the "scheme" field. With this, my https request are properly processed. It would be nice to have the possibility to make such customization from the module SETTINGS directly though.
class OpenAPIRenderer(renderers.OpenAPIRenderer):
def get_customizations(self):
data = super(OpenAPIRenderer, self).get_customizations()
data["schemes"] = ["https", "http"]
return data
class SwaggerSchemaView(APIView):
permission_classes = [permissions.IsAuthenticated]
renderer_classes = [
OpenAPIRenderer,
renderers.SwaggerUIRenderer
]
def get(self, request):
generator = SchemaGenerator()
schema = generator.get_schema(request=request)
return Response(schema)
This is a duplicate of #363
I think it's not a duplicate of #363.
For my case with the same symptom (and an proper SSL reverse proxy in front), adding SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
to settings fixed the issue.