[BUG] Kotlin Spring generates invalid code from examples
Created by: exaV
Description
The plugin generates invalid code when the <swaggerAnnotations>true</swaggerAnnotations>
is used.
Specifically when a schema contains an example which is an array of strings.
Example (api spec):
properties:
actions:
type: array
description: List of available (enabled) actions
example:
- edit
- delete
- print-report
See below for a full example
Actual output (generated model)
/**
* Base model for a resource
* @param actions List of available (enabled) actions
*/
data class Resource(
@ApiModelProperty(example = "["edit","delete","print-report"]", value = "List of available (enabled) actions")
@field:JsonProperty("actions") val actions: kotlin.collections.List<kotlin.String>? = null
) {
}
Expected output:
/**
* Base model for a resource
* @param actions List of available (enabled) actions
*/
data class Resource(
@ApiModelProperty(example = "[edit, delete, print-report]", value = "List of available (enabled) actions")
@field:JsonProperty("actions") val actions: kotlin.collections.List<kotlin.String>? = null
) {
}
openapi-generator version
5.2.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
version: 1.0.0
title: Api Documentation
paths:
/universes:
get:
responses:
'200':
description: A list of resources
content:
application/json:
schema:
$ref: '#/components/schemas/Resource'
components:
schemas:
Resource:
description: Base model for a resource
type: object
properties:
actions:
type: array
description: List of available (enabled) actions
example:
- edit
- delete
- print-report
items:
type: string
Generation Details
maven configuration
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.2.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/contract/robo-advice.yaml
</inputSpec>
<generatorName>kotlin-spring</generatorName>
<generateModels>true</generateModels>
<configOptions>
<exceptionHandler>false</exceptionHandler>>
<serializationLibrary>jackson</serializationLibrary>
<useTags>true</useTags>
<enumPropertyNaming>UPPERCASE</enumPropertyNaming>
<swaggerAnnotations>true</swaggerAnnotations>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
- include the file and the plugin configuration from above in a maven build.
- The problematic configOption is
<swaggerAnnotations>true</swaggerAnnotations>