Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 of 6 tasks
tamershahin opened this issue Feb 12, 2021 · 2 comments · Fixed by #11166
Closed
4 of 6 tasks

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

tamershahin opened this issue Feb 12, 2021 · 2 comments · Fixed by #11166

Comments

@tamershahin
Copy link

tamershahin commented Feb 12, 2021

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}}
@grzegorz-moto
Copy link
Contributor

grzegorz-moto commented May 12, 2021

+1
it is still present in v5.1.1

@grzegorz-moto
Copy link
Contributor

I've tried to remove "()" from dataClass.mustache as suggested here - and I confirm this helps and looks similar to the code generated by 4.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants