Closed yuvalishay closed 4 years ago
+1 looks like it's still present in 4.2.2 as well
This is still an issue. Adding the --debug option to Maven seems to pick up the template directory
Any news?
same thing with Homebrew and npm installations
Still present in 4.3.0
Also have this issue, but from the cli side. Using 4.3.0 and trying to generate java. Tried using the -t
and --template
options.
i'm using 4.0.1
and this works for me
generator.sh
openapi-generator generate \
-i <input file> \
-g csharp-netcore \
-t <template directory>/csharp-netcore \
-o <output directory> \
-c <config file>
@adin234 please try the latest version (4.3.0) to see if it works for you.
I did some tests with the latest version of the CLI and the -t
option works fine for me
<templateDirectory>${project.basedir}/src/main/resources</templateDirectory>
You need to provide the folder with the customized templates instead. e.g.
<templateDirectory>${project.basedir}/src/main/resources/JavaSpring</templateDirectory>
The issue is not with the CLI. This issue is with the MAVEN plugin.
I did provide also the specific folder but it still doesn't work.
Same here, but with templateResourcePath
. The config parameter is picked up by the plugin and printed to the console, but generator seems to ignore it.
CLI works fine.
There is a bug under windows concerning the '/' and '\' in JAR resource paths since a classpath resource path with '\' does not work. It happened to me the same using the maven plugin. I configured a dependency to my own project containing my mustache templates (a simple maven project with the files inside src/main/resources/templates/JavaSpring
) and wanted to reference those.
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<dependencies>
<dependency>
<groupId>my.company</groupId>
<artifactId>my-generator-templates</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
...
<configuration>
...
<templateResourcePath>templates/JavaSpring</templateResourcePath>
...
</configuration>
...
</plugin>
When I configured templateResourcePath
as "JavaSpring", the plugin would not complain because coincidentally the embedded mustache template folder is also named "JavaSpring", thus during the check it finds that one.
Then I changed the path to be sure it's different, and again no complains as long as it's a single-part path, e.g. "foobar", and not "foo\bar".
These classpath URLs have to be compiled always with the slash ('/') instead of File.separator
which bugs out under windows, e.g. tries to find "templates\JavaSpring\pojo.mustache" which is not a valid resource path, but is found using '/', e.g. "templates/JavaSpring/pojo.mustache". I tried it out locally and it works when using '/' consistently regardless of OS.
Concerned methods: openapi-generator/org.openapitools.codegen.AbstractGenerator.getFullTemplateFile() and openapi-generator-core/org.openapitools.codegen.config.WorkflowSettings.withTemplateDir()
It seems in the original fix it worked because there was a replacement of the file-separator in case it was NOT '/' using the method getCPResourcePath(). After a refactoring in this class AbstractGenerator
it broke.
What's the status on this ? It seems I have the same issue (Maven plugin, v4.3.0, using templateDirectory)
Edit: turns out I didn't, I just had an incorrect configuration. This part of the doc is important and was relevant to my problem:
OpenAPI Generator will lookup templates in this order:
- User customized library path (e.g. custom_template/libraries/feign/model.mustache)
- User customized generator top-level path (e.g. custom_template/model.mustache)
- Embedded library path (e.g. resources/Java/libraries/feign/model.mustache)
- Embedded top-level path (e.g. resources/Java/model.mustache)
- Common embedded path (e.g. resources/_common/model.mustache)
@jimschubert this bug is still open and directly corresponds to our conversation here: https://github.com/OpenAPITools/openapi-generator/pull/6357#discussion_r449851055
Have you had another look into it?
@DenisKnoepfle thanks for bumping this. I never got your comment last month from the linked issue for some reason.
I was having trouble reproducing the issue you'd described. I'd found it was because I was testing using git bash in Windows so I guess it uses linux file separators and was never hitting the file separator issue you'd described. When I had tested the maven plugin, I was testing templateDirectory
rather than templateResourcePath
as is discussed in this issue.
I should have a fix shortly. I just need to get my Windows 10 VM to update successfully so I can test this in Windows Terminal, since I assume that's what most Windows developers would be using. I also want to be sure to test both templateDirectory
and templateResourcePath
options a few times in private CI and local builds to be sure the issue is resolved.
A workaround for anyone affected may be to switch to templateDirectory like:
<templateDirectory>${project.basedir}/templates</templateDirectory>
However, since this bug was reported 7 months before my refactor, I can't say for sure why the original implementation was failing.
I'm running mvn install with the following configuration - but the looks like the is ignored and Template directory always defaults to embedded dir.
Here is the maven plugin section in which the templateDirectory is ignored:
openapi-generator version
I tried also earlier from 4.0.0 and above - but still the same.
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/3364 I see this issue was closed. ( but it wasn't open on the Maven plugin from the beginning )
Thanks, Yuval Ishay