You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The new jaxrs-spec library of the kotlin-server generator does not support inheritance.
Inheritance can be represented in openapi with a discriminator and allOf. However, the kotlin-server generator gives an error when inheritance is used in an openapi spec:
Exception in thread "main" java.lang.RuntimeException: Could not generate model 'Pet'
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:532)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:888)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:441)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: org.openapitools.codegen.templating.TemplateNotFoundException: interface_req_var
at org.openapitools.codegen.templating.MustacheEngineAdapter.findTemplate(MustacheEngineAdapter.java:79)
at org.openapitools.codegen.templating.MustacheEngineAdapter.lambda$compileTemplate$0(MustacheEngineAdapter.java:61)
at com.samskivert.mustache.Mustache$IncludedTemplateSegment.execute(Mustache.java:756)
at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:870)
at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:866)
at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:881)
at com.samskivert.mustache.Template.executeSegs(Template.java:157)
at com.samskivert.mustache.Mustache$IncludedTemplateSegment.execute(Mustache.java:774)
at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
at com.samskivert.mustache.Mustache$InvertedSegment.execute(Mustache.java:910)
at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
at com.samskivert.mustache.Mustache$InvertedSegment.execute(Mustache.java:906)
at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
at com.samskivert.mustache.Mustache$InvertedSegment.execute(Mustache.java:910)
at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:881)
at com.samskivert.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:845)
at com.samskivert.mustache.Mustache$SectionSegment.execute(Mustache.java:866)
at com.samskivert.mustache.Template.executeSegs(Template.java:157)
at com.samskivert.mustache.Template.execute(Template.java:134)
at com.samskivert.mustache.Template.execute(Template.java:125)
at org.openapitools.codegen.templating.MustacheEngineAdapter.compileTemplate(MustacheEngineAdapter.java:65)
at org.openapitools.codegen.TemplateManager.write(TemplateManager.java:163)
at org.openapitools.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:1034)
at org.openapitools.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:1021)
at org.openapitools.codegen.DefaultGenerator.generateModel(DefaultGenerator.java:388)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:523)
... 4 more
openapi-generator version
Tested with openapi-generator version 5.4.0 and the docker image openapitools/openapi-generator-cli:latest (as of Feb 9th 2022).
OpenAPI declaration file content or url
openapi: 3.0.0info:
description: | kotlin-server jaxrs-spec inheritance issuestitle: inheritance bugversion: 1.0.0paths:
/test:
get:
responses:
'200':
description: okcontent:
application/json:
schema:
$ref: '#/components/schemas/Pet'servers:
- url: http://localhost/components:
schemas:
Pet:
type: objectrequired:
- pet_typeproperties:
pet_type:
type: stringdiscriminator:
propertyName: pet_typemapping:
cachorro: DogCat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object# all other properties specific to a `Cat`properties:
name:
type: stringDog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object# all other properties specific to a `Dog`properties:
bark:
type: stringLizard:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object# all other properties specific to a `Lizard`properties:
lovesRocks:
type: boolean
I am also trying to generate kotlin jaxrs models with no success, has this been accepted as a bug? or is there a workaround?
As a quick workaround, you can add the two mustache templates mentioned above in your open api template directory (See https://openapi-generator.tech/docs/templating/#modifying-templates). This won't really fix inheritance but at least you will be able to generate the code without error.
Bug Report Checklist
Description
The new jaxrs-spec library of the kotlin-server generator does not support inheritance.
Inheritance can be represented in openapi with a discriminator and
allOf
. However, the kotlin-server generator gives an error when inheritance is used in an openapi spec:openapi-generator version
Tested with openapi-generator version 5.4.0 and the docker image
openapitools/openapi-generator-cli:latest
(as of Feb 9th 2022).OpenAPI declaration file content or url
Generation Details
Generator:
kotlin-server
Library:
jaxrs-spec
Was tested with the following command:
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/petstore.yaml -g kotlin-server -o /local/out/kotlin --library jaxrs-spec
where the spec given above is present in the current directory as
petstore.yaml
Steps to reproduce
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/petstore.yaml -g kotlin-server -o /local/out/kotlin --library jaxrs-spec
where the spec given above is present in the current directory as
petstore.yaml
Related issues/PRs
The new kotlin-server jaxrs-spec was introduced in #10830
The missing
interface_req_var
template is not the only problem with inheritance for this generator. Theinterface_opt_var
is also missing.In addition, there also seem to be an issue with the generated code when using multiple levels of inheritance.
Suggest a fix
A good start would be using the templates from the kotlin-client generator:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/kotlin-client/interface_opt_var.mustache
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/kotlin-client/interface_req_var.mustache
Other changes will be needed though, like marking the parent's fields as
override
in the children classes.The text was updated successfully, but these errors were encountered: