Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated code produces Kotlin warnings when using @Query #464

Open
ricardorlg opened this issue Oct 19, 2023 · 4 comments
Open

Generated code produces Kotlin warnings when using @Query #464

ricardorlg opened this issue Oct 19, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@ricardorlg
Copy link

Ktorfit version

1.8.1

What happened and how can we reproduce this issue?

I use @query in some of my API interfaces, but unfortunately, the generated code produces Kotlin warnings. I had to turn off warningsAsErrors in our Gradle build, but ideally, I would like to have it enabled.

API Example:

 @GET("/oauth2/default/v1/authorize")
    fun getToken(
        @Query("response_type") responseType: String,
        @Query("scope") scope: String,
        @Query("state") state: String,
        @Query("nonce") nonce: String,
        @Query("client_id") clientId: String,
        @Query("sessionToken") sessionToken: String,
        @Query("redirect_uri") redirectUri: String,
    ): Response<OktaResponse>

Warning:

Unnecessary safe call on a non-null receiver of type String

Generated code:

  override fun getToken(
    responseType: String,
    scope: String,
    state: String,
    nonce: String,
    clientId: String,
    sessionToken: String,
    redirectUri: String,
  ): Response<OktaResponse> {
    val _ext: HttpRequestBuilder.() -> Unit = {
        method = HttpMethod.parse("GET")
        url{
        takeFrom(ktorfitClient.baseUrl + "/oauth2/default/v1/authorize")
        responseType?.let{ parameter("response_type", "$it") }
        scope?.let{ parameter("scope", "$it") }
        state?.let{ parameter("state", "$it") }
        nonce?.let{ parameter("nonce", "$it") }
        clientId?.let{ parameter("client_id", "$it") }
        sessionToken?.let{ parameter("sessionToken", "$it") }
        redirectUri?.let{ parameter("redirect_uri", "$it") }
        } 
        }
    val _requestData = RequestData(ktorfitRequestBuilder = _ext,
        returnTypeName = "de.jensklingenberg.ktorfit.Response<OktaResponse>",
        returnTypeInfo = typeInfo<Response<OktaResponse>>()) 

    return ktorfitClient.request<Response<OktaResponse>, OktaResponse>(_requestData)!!
  }

What did you expect to happen?

I would expect no warnings, if possible or at least generated code with suppress warnings annotations.

Is there anything else we need to know about?

Is related to #460

@ricardorlg ricardorlg added the bug Something isn't working label Oct 19, 2023
@Foso
Copy link
Owner

Foso commented Oct 19, 2023

This will be fixed in the next version

@Foso Foso self-assigned this Oct 19, 2023
@Foso
Copy link
Owner

Foso commented Oct 23, 2023

Hi, with Ktorfit 1.9.1 the warnings are suppressed. It's still planned to optimize the code, but that will come later.

@ricardorlg
Copy link
Author

Perfect, I can contribute with a better code for Query parameters, I will see if I can open a PR this week.

@Foso
Copy link
Owner

Foso commented Oct 23, 2023

Great :)

@Foso Foso assigned ricardorlg and unassigned Foso Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants