django-rest-swagger icon indicating copy to clipboard operation
django-rest-swagger copied to clipboard

Test using http when api is in https

Open ghost opened this issue 6 years ago • 3 comments

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?

ghost avatar Jul 20 '17 12:07 ghost

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)

quertenmont avatar Oct 21 '17 13:10 quertenmont

This is a duplicate of #363

killua8p avatar May 23 '18 02:05 killua8p

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.

hartwork avatar Nov 02 '18 14:11 hartwork