swagger-api / swagger-api/swagger-codegen

Java codegen doesn't support mustache template engine

Open
#9,813 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the documented Java codegen command and the Petstore YAML. Start in io.swagger.codegen.v3.templates.MustacheTemplateEngine and follow the calls from DefaultGenerator to identify why Mustache parsing reports a mismatched section tag. Done means Java generation completes with --template-engine mustache without the reported model-generation exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.