[BUG][Kotlin] kotlin generator causes warning: 'Unnecessary safe call on a non-null receiver of type ...'
See original GitHub issueDescription
The changes in pull request https://github.com/OpenAPITools/openapi-generator/pull/7341 are forcing paramName
as an nullable. This causes the compiler to return the following warning for non-nullable objects:
Unnecessary safe call on a non-null receiver of type String
This breaks our ability to build our app using -Werror
as a compile option.
openapi-generator version
Version 5.0.0
OpenAPI declaration file content or url
PlayerTokenParam is a required header parameter, so non-nullable:
/emailChange:
post:
description: "Change Email."
operationId: "ChangeEmail"
parameters:
- $ref: '#/components/parameters/PlayerTokenParam'
...
playerTokenParam:
in: header
name: playerToken
description: session token for the current player
required: true
schema:
type: string
This generates (where playerToken? causes the warning):
fun changeEmail(playerToken: kotlin.String, changeEmailRequest: ChangeEmailRequest) : Unit {
val localVariableBody: kotlin.Any? = changeEmailRequest
val localVariableQuery: MultiValueMap = mutableMapOf()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
playerToken?.apply { localVariableHeaders["playerToken"] = this.toString() }
Generation Details
Gradle script task:
task generateApi(type: GenerateTask){
generatorName = "kotlin"
inputSpec = <input-spec-file>
outputDir = <output-dir>
packageName = <package-name>
validateSpec = true
configOptions = [
sourceFolder: <source-folder>,
dateLibrary: "threetenbp",
parcelizeModels: "true",
enumPropertyNaming: "UPPERCASE"
]
}
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/7341
Suggest a fix
I think modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache
should not asume the object is a nullable object: {{{paramName}}}?.apply {
. I’m not sure how to fix it though!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Thanks for the heads up, I assumed wrongly that this was solved.
@4brunu I can confirm that https://github.com/OpenAPITools/openapi-generator/pull/9415 fixes the issue!! 👍