Bug Report Checklist
Description
The Kotlin generator can't handle type aliases properly, instead generates empty data classes that don't compile.
openapi-generator version
4.0.0-beta2
OpenAPI declaration file content or url
openapi: "3.0.1"
info:
version: 0.0.1
title: broken API
paths:
/test:
put:
summary: No description
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MyParameter'
responses:
200:
description: "Lorem Ipsum"
components:
schemas:
MyParameter:
type: object
properties:
aDescriptionField:
$ref: '#/components/schemas/MyParameterTextField'
MyParameterTextField:
$ref: '#/components/schemas/MyTypeAlias'
MyTypeAlias:
type: string
minLength: 1
maxLength: 50
Command line used for generation
java -jar openapi-generator-cli-4.0.0-beta2.jar generate -i brokenApi.yaml -g kotlin -o out
Steps to reproduce
- Run above command line
- Go to
out\src\main\kotlin\org\openapitools\client\models
- There are two files,
MyParameter.kt and MyParameterTextField.kt, open them in an editor
data class MyParameter (
val aDescriptionField: kotlin.String? = null // should be of type MyParameterTextField?, not String
){}
data class MyParameterTextField () {} //wrong and won't compile
Suggest a fix
This is a no-brainer imo:
typealias MyParameterTextField = MyTypeAlias
For the entirely missingMyTypeAlias.kt there are multiple options:
// Option 1:
typealias MyTypeAlias = String
// Bonus (similar for Option 2&3):
fun MyTypeAlias.validate() = this.length >= 1 && this.length<=50
// ... and invocation (there needs to be some kind of interface containing validate()):
data class MyParameter (val aDescriptionField: kotlin.MyParameterTextField? = null){
init{ aDescriptionField?.validate().let{/*throw maybe?*/} }
}
// Option 2 (more type safety, more overhead):
inline class MyTypeAlias(val value: String){
// ... Bonus as member function
}
// Option 3 (more type safety, most overhead, most extensible):
data class MyTypeAlias(val value: String){
// ... Bonus as member function
}
Bug Report Checklist
Description
The Kotlin generator can't handle type aliases properly, instead generates empty data classes that don't compile.
openapi-generator version
4.0.0-beta2OpenAPI declaration file content or url
Command line used for generation
java -jar openapi-generator-cli-4.0.0-beta2.jar generate -i brokenApi.yaml -g kotlin -o outSteps to reproduce
out\src\main\kotlin\org\openapitools\client\modelsMyParameter.ktandMyParameterTextField.kt, open them in an editorSuggest a fix
This is a no-brainer imo:
For the entirely missing
MyTypeAlias.ktthere are multiple options: