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
  • #8687
Closed
Open
Issue created Feb 12, 2021 by Administrator@rootContributor4 of 6 checklist items completed4/6 checklist items

[BUG] [kotlin-spring] generator doesn't create proper inheritance hierarchy

Created by: tamershahin

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The hierarchy in chase of inheritance is not created properly for kotlin language. after I fixed the mustache files the generated code is compiling.

annotations are not allowed nor necessary in the interface:

image

the interface is called, which is wrong:

image

openapi-generator version

5.0.1

OpenAPI declaration file content or url
 BaseFileManagerObject:
      type: object
      required:
        - id
        - name
        - self
        - objectType
      properties:
        self:
          type: string
        name:
          type: string
        parent:
          type: string
        id:
          type: string
          format: uuid
        objectType:
          type: string
      discriminator:
        propertyName: objectType
        mapping:
          FolderObject: '#/components/schemas/FolderObject'
          FileObject: '#/components/schemas/FileObject'
    FolderObject:
      type: object
      allOf:
        - $ref: '#/components/schemas/BaseFileManagerObject'
        - type: object
      required:
        - files
        - updatedAt
      properties:
        files:
          type: string
        updatedAt:
          type: string
          format: date-time
    FileObject:
      allOf:
        - $ref: '#/components/schemas/BaseFileManagerObject'
        - type: object
      required:
        - contentType
        - downloadUrl
        - scanStatus
        - size
        - updatedAt
      type: object
      properties:
        contentType:
          type: string
        size:
          type: integer
          format: int32
        downloadUrl:
          type: string
        scanStatus:
          type: string
        updatedAt:
          type: string
          format: date-time
Generation Details

I'm using the gradle plugin. this is the config:

tasks.named<GenerateTask>("openApiGenerate") {
  setProperty("generatorName", "kotlin-spring")
  setProperty("inputSpec", "$rootDir/swagger/swagger.yaml")
  setProperty("outputDir", "$buildDir/generated/kotlin")
//  setProperty("templateDir", "$rootDir/swagger/template/")
  setProperty("apiPackage", "io.tenera.filemanager.generated.api")
  setProperty("modelPackage", "io.tenera.filemanager.generated.model")
  setProperty("skipValidateSpec", true)
  setProperty("configOptions", mapOf(
    Pair("tile", "File Manager Api"),
    Pair("dateLibrary", "java8"),
    Pair("useBeanValidation", "true"),
    Pair("hideGenerationTimestamp", "false"),
    Pair("swaggerAnnotations", "true"),
    Pair("useTags", "true"),
    Pair("delegatePattern", "false"),
    Pair("interfaceOnly", "false"),
    Pair("serviceInterface", "true"),
    Pair("serviceImplementation", "false"),
    Pair("reactive", "false")
  ))
  setProperty("globalProperties", mapOf(
    Pair("apis", ""), //no value or comma-separated
    Pair("apiTests", "false"),
    Pair("models", ""),
    Pair("modelTests", "false"),
    Pair("invoker", "false")
  ))
}
Steps to reproduce

just run the generator for kotlin-spring with any spec with inheritance.

Related issues/PRs
Suggest a fix

the following are my version of the templates:

dataClass.mustache (removed () in {{{parent}}}{{/parent}} )

/**
* {{{description}}}
{{#vars}}
    * @param {{name}} {{{description}}}
{{/vars}}
*/{{#discriminator}}
    {{>typeInfoAnnotation}}{{/discriminator}}
{{#discriminator}}interface {{classname}}{{/discriminator}}{{^discriminator}}{{#hasVars}}data {{/hasVars}}class {{classname}}(
{{#requiredVars}}
    {{>dataClassReqVar}}{{^-last}},
    {{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}},
{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>dataClassOptVar}}{{^-last}},
{{/-last}}{{/optionalVars}}
) {{/discriminator}}{{#parent}}: {{{parent}}}{{/parent}}{
{{#discriminator}}
    {{#requiredVars}}
        {{>interfaceReqVar}}
    {{/requiredVars}}
    {{#optionalVars}}
        {{>interfaceOptVar}}
    {{/optionalVars}}
{{/discriminator}}
{{#hasEnums}}{{#vars}}{{#isEnum}}
    /**
    * {{{description}}}
    * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
    */
    enum class {{nameInCamelCase}}(val value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}) {
    {{#allowableValues}}{{#enumVars}}
        @JsonProperty({{{value}}}) {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
    {{/enumVars}}{{/allowableValues}}
    }
{{/isEnum}}{{/vars}}{{/hasEnums}}
}

interfaceReqVar.mustache (added ^discriminator)

{{^discriminator}}
    {{#swaggerAnnotations}}
        @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
{{/discriminator}}
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}

interfaceOptVar.mustache

{{^discriminator}}
    {{#swaggerAnnotations}}
        @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
{{/discriminator}}
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}{{/discriminator}}
Assignee
Assign to
Time tracking