OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
With a spec that has an enum inside of a property of an application/x-www-form-urlencoded body, the generated Kotlin code does not compile:
> Task :compileKotlin FAILED
e: file:///run/user/1000/s/out/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt:112:51 Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type DefaultApi.VariantWatPost?
FAILURE: Build failed with an exception.
because of the unchecked .value access to a nullable ? parameter
fun watPostRequestConfig(variant: VariantWatPost?) : RequestConfig<Map<String, PartConfig<*>>> {
val localVariableBody = mapOf(
"variant" to PartConfig(body = variant.value, headers = mutableMapOf()),)
val localVariableQuery: MultiValueMap = mutableMapOf()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf("Content-Type" to "application/x-www-form-urlencoded")
openapi-generator version
7747cc93e0a6f01715b8f267f91c5aa83fe23a0b
OpenAPI declaration file content or url
openapi: '3.0.0'
info:
version: 1.0.0
title: test
paths:
/wat:
post:
responses:
'200':
description: OK
headers: {}
content:
text/html:
schema:
type: string
requestBody:
required: true
content:
"application/x-www-form-urlencoded":
schema:
type: object
properties:
variant:
type: string
enum:
- one
- two
Generation Details
java -jar /home/val/.m2/repository/org/openapitools/openapi-generator-cli/7.7.0-SNAPSHOT/openapi-generator-cli-7.7.0-SNAPSHOT.jar generate -i spec.yaml -o out -g kotlin
Steps to reproduce
sh gradlew check that example
Related issues/PRs
Suggest a fix
Should be a simple template fix to generate the ?. safe access, will look into doing it myself
Description
With a spec that has an
enum
inside of a property of anapplication/x-www-form-urlencoded
body, the generated Kotlin code does not compile:because of the unchecked
.value
access to a nullable?
parameteropenapi-generator version
7747cc93e0a6f01715b8f267f91c5aa83fe23a0b
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
sh gradlew check
that exampleRelated issues/PRs
Suggest a fix
Should be a simple template fix to generate the
?.
safe access, will look into doing it myself