swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Java codegen doesn't support mustache template engine

Open ShenChen93 opened this issue 5 years ago • 2 comments

Description

It seems java codegen doesn't support mastache as template engine.

Swagger-codegen version

3.0.13

Swagger declaration file content or url
Command line used for generation

java -jar /Users/shench/workplace/shenchen/src/ASKCli/swagger-codegen-cli-3.0.13.jar generate --input-spec /Users/shench/workplace/shenchen/src/ASKCli/swagger3.yaml --lang java --template-engine mustache

Steps to reproduce
  1. get the petstore yaml file
  2. use the latest codegen cli to generate code by using the commands mentioned above
Related issues/PRs
Suggest a fix/enhancement

Here is the error code it reports:

[Thread-1] DEBUG io.swagger.v3.parser.OpenAPIV3Parser - Parsed rootNode: {"openapi":"3.0.0","info":{"version":"1.0.0","title":"Swagger Petstore","license":{"name":"MIT"}},"servers":[{"url":"http://petstore.swagger.io/v1"}],"paths":{"/pets":{"get":{"summary":"List all pets","operationId":"listPets","tags":["pets"],"parameters":[{"name":"limit","in":"query","description":"How many items to return at one time (max 100)","required":false,"schema":{"type":"integer","format":"int32"}}],"responses":{"200":{"description":"A paged array of pets","headers":{"x-next":{"description":"A link to the next page of responses","schema":{"type":"string"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Pets"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PetError"}}}}}},"post":{"summary":"Create a pet","operationId":"createPets","tags":["pets"],"responses":{"201":{"description":"Null response"},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PetError"}}}}}}},"/pets/{petId}":{"get":{"summary":"Info for a specific pet","operationId":"showPetById","tags":["pets"],"parameters":[{"name":"petId","in":"path","required":true,"description":"The id of the pet to retrieve","schema":{"type":"string"}}],"responses":{"200":{"description":"Expected response to a valid request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Pet"}}}},"default":{"description":"unexpected error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PetError"}}}}}}}},"components":{"schemas":{"Pet":{"type":"object","required":["id","name"],"properties":{"id":{"type":"integer","format":"int64"},"name":{"type":"string"},"tag":{"type":"string"}}},"Pets":{"type":"array","items":{"$ref":"#/components/schemas/Pet"}},"PetError":{"type":"object","required":["code","message"],"properties":{"code":{"type":"integer","format":"int32"},"message":{"type":"string"}}}}}}
16:08:52.535 [Thread-1] DEBUG io.swagger.codegen.v3.config.CodegenConfigurator - getClientOptInput - parsed inputSpecURL /Users/shench/workplace/shenchen/src/ASKCli/swagger3.yaml
16:08:52.541 [Thread-1] INFO io.swagger.codegen.v3.ignore.CodegenIgnoreProcessor - No .swagger-codegen-ignore file found.
16:08:52.547 [Thread-1] INFO io.swagger.codegen.v3.generators.DefaultCodegenConfig - Skipped overwriting README.md as the file already exists in /Users/shench/workplace/shenchen/src/ASKCli/.//README.md
Exception in thread "Thread-1" java.lang.RuntimeException: Could not generate model 'Pet'
        at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:455)
        at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:783)
        at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:351)
        at java.lang.Thread.run(Thread.java:748)
Caused by: com.samskivert.mustache.MustacheParseException: Section close tag with mismatched open tag 'is' != 'is this 'enum'' @ line 42
        at com.samskivert.mustache.Mustache$Accumulator.requireSameName(Mustache.java:671)
        at com.samskivert.mustache.Mustache$Accumulator$1.addCloseSectionSegment(Mustache.java:603)
        at com.samskivert.mustache.Mustache$Accumulator.addTagSegment(Mustache.java:629)
        at com.samskivert.mustache.Mustache$Parser.parseChar(Mustache.java:498)
        at com.samskivert.mustache.Mustache$Parser.parse(Mustache.java:396)
        at com.samskivert.mustache.Mustache.compile(Mustache.java:314)
        at com.samskivert.mustache.Mustache$Compiler.compile(Mustache.java:87)
        at com.samskivert.mustache.Mustache$Compiler.compile(Mustache.java:82)
        at io.swagger.codegen.v3.templates.MustacheTemplateEngine.getRendered(MustacheTemplateEngine.java:43)
        at io.swagger.codegen.v3.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:799)
        at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:442)
        ... 3 more

It seems also I choose mustache as template engine, it still use handlebars logic to parse it.

ShenChen93 avatar Oct 28 '19 23:10 ShenChen93