Open jriegraf opened 2 years ago
I am also facing the same issue. Looks like there is an issue in dealing with paths on windows environment here - https://github.com/swagger-api/swagger-codegen/blob/v3.0.29/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/templates/CodegenTemplateLoader.java#L32
private String resolveTemplateFile(String templateDir, String templateFile) {
if (templateFile.startsWith(templateDir)) {
templateFile = StringUtils.replaceOnce(templateFile, templateDir, StringUtils.EMPTY);
}
return templateFile;
}
For the example provided by @jriegraf , the arguments should be this: templateDir = "/handlebars/Java"
and templateFile = "/handlebars/Java/C:/dev/fun/swagger-codegen-template-test/src/main/resources/templateDirectory/ApiClient.mustache"
After String replacement, templateFile = "/C:/dev/fun/swagger-codegen-template-test/src/main/resources/templateDirectory/ApiClient.mustache"
which leaves it with a leading /
eventually causing file
path invalid.
cc: @HugoMario
this also occurs when trying to use the language csharp.
Description
The swagger-codegen-maven-plugin throws a runtime exception when using custom templates. This issue only occurs on Windows!
see full buil log: https://github.com/jriegraf/swagger-codegen-template-test/runs/4486888138?check_suite_focus=true#step:4:839
Swagger-codegen version
Swagger declaration file content or url
Petstore Swagger 2.0 Spec (json) from https://petstore.swagger.io/
The templates I used: pojo.mustache, ApiClient.mustache Both copied from https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/Java
Command line used for generation
Steps to reproduce
mvn clean package
Additional: remove the templateDirectory tag from the plugin definition in pom.xml -> build will succeed