swagger-gradle-codegen icon indicating copy to clipboard operation
swagger-gradle-codegen copied to clipboard

securityDefinitions are not added to the headers

Open chathudan opened this issue 5 years ago • 3 comments

Thank you for the great plugin.

It seems security definitions are not added to the headers and generated code has empty headers which giving runtime errors. Please see below swagger example.


"/login": {
            "post": {

                "security": [
                    {
                        "apiKey": []
                    }
                ] 
            }
        }

"securityDefinitions": {
        "apiKey": {
            "type": "apiKey",
            "name": "x-api-key",
            "in": "header"
        },
        "accessToken": {
            "type": "apiKey",
            "name": "x-access-token",
            "in": "header",
            "description": "Unique user authentication token"
        }
    }

chathudan avatar Apr 15 '19 04:04 chathudan

Hey @chathudan (Sorry for the late answer but I missed this issue)

That's intentional.

We decided to strip out all the securityDefinitions and handle the auth at the OkHttp/Interceptor level. This works really well when you have hundreds on authenticated endpoints and you don't want to pass the x-access-token every time.

I'll keep this as a feature request and would love to be know if someone else is interested in having this feature.

cortinico avatar Jun 04 '19 08:06 cortinico

@cortinico Thank you for your message and awesome plugin, I already added Interceptor and did the job. Please consider a callback for Authenticator to handle 401 and interact user to re-authenticate.

chathudan avatar Jul 07 '19 23:07 chathudan

Please consider a callback for Authenticator to handle 401 and interact user to re-authenticate.

I don't think this is in the scope of the Gradle plugin but should be configured on the OkHttpClient. It's up to the client to take care of authentication (either with an Interceptor or with an Authenticator). The Gradle plugin is just generating Retrofit interfaces.

cortinico avatar Jul 08 '19 12:07 cortinico