swagger-api / swagger-api/swagger-codegen

maven-codegen-plugin Access custom templates from jar

Open
#10,508 1 comment 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

I have following situation

  • customCodegen as jar artifact
  • customized templates as part of the same jar (similar packaging like with (e.g. adaptedTemplate)
  • used customCodegen from swagger-codegen-maven-plugin
  • using copy depen -to extract templates to working directory

If I extract and copy adaptedTemplate directory to build path -> it works OK

Swagger-codegen version

3.0.21

Swagger declaration file content or url
Command line used for generation

swagger-codegen-maven-plugin

Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

Question: is it possible to load modified templates directly from jar file, similar to original swagger-generators ?
Customized codegen code works fine, just to unpack (in many poms is quite tedious :( )

I see problem in https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java
at setTemplate expects local directory, or is there any workaround?
Would it be possible to specify jar file access to load modified templates?
( swagger.yml from jar works nice just as dependency in plugin, similar to custom codegen in customgenerator

  1. option would be to check local directory existence -> if not expect jar access
  2. other - define it alternate ways

(other problems would be to access them in Handlebar, but this I have probably solved, as I had modified HandlebarTemplateEngine search algorithm to access all 4 places, as it was in codegen v2.x )

Overwrite this configurator is neither not so easy, as created in swagger-coden-maven-plugin directly.
Thanks for any hints

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

Start with modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java and the swagger-codegen-maven-plugin entry point; compare how setTemplate handles a local directory with the custom codegen JAR setup described. Done means Maven plugin generation can load customized templates directly from the JAR without copy-dependency extraction.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.