Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #10046
Closed
Open
Issue created Jul 27, 2021 by Administrator@rootContributor

[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
  1. include the file and the plugin configuration from above in a maven build.
  2. The problematic configOption is <swaggerAnnotations>true</swaggerAnnotations>
Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking