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

[all] allow per-template overloading with Handlerbar (as with Mustache) #9183

Closed
rosbly opened this issue Feb 17, 2019 · 4 comments
Closed
Assignees

Comments

@rosbly
Copy link

rosbly commented Feb 17, 2019

Description

With swagger-codegen 2.0 & mustache templates, I could specify a --template-dir containing only the templates I wanted to overload. swagger-codegen would use my templates when available and otherwise fall back to the default ones.

With Handlerbar templates, swagger-codegen only reads --template-dir so I need to copy the whole original directory and make my changes.

This is very cumbersome when only a slight change in one or a few templates is needed.

Swagger-codegen version

3.0.x

Suggest a fix/enhancement

Some tweaking is needed in HandlebarTemplateEngine, using a handlebars CompositeTemplateLoader would be appropriate. Template path processing looks tricky which is why I don't have a pull request.

Thanks

@sarumont
Copy link

Possibly related to #8904, though that mentions Mustache and Spring specifically. I see this with Mustache templates and -l java -D models, so I believe it is indeed global.

Relevant stack, attempting to only override pojo.mustache:

Exception in thread "Thread-1" java.lang.RuntimeException: Could not generate model 'Connector'
        at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:405)
        at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:719)
        at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:342)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.FileNotFoundException: /Users/richard/dev/nf/connector/templates/java/model.mustache
        at com.github.jknack.handlebars.io.URLTemplateLoader.sourceAt(URLTemplateLoader.java:70)
        at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:357)
        at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:343)
        at io.swagger.codegen.v3.templates.HandlebarTemplateEngine.getHandlebars(HandlebarTemplateEngine.java:48)
        at io.swagger.codegen.v3.templates.HandlebarTemplateEngine.getRendered(HandlebarTemplateEngine.java:24)
        at io.swagger.codegen.v3.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:735)
        at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:392)
        ... 3 more

@tibors13
Copy link

With HandleBarTemplateEngine.getHandlebars(String templateFile) there is a problem with following code

        if (this.config.additionalProperties().get("templateDir") != null) {
            templateLoader = new FileTemplateLoader(templateDir, ".mustache");
        } else {
            templateLoader = new ClassPathTemplateLoader("/" + templateDir, ".mustache");
        }

It relies on templateDir, so when -template-dir is used, it cannot load file from classpath, as it never goes there (without -t it works fine)

@HugoMario HugoMario self-assigned this Aug 14, 2020
@frantuma
Copy link
Member

@HugoMario maybe fixed by #11162?

@HugoMario
Copy link
Contributor

Fixed by #11191

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

No branches or pull requests

5 participants