swagger-api / swagger-api/swagger-codegen
[JaxRS] Code generator does not honor implFolder on windows platform
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When using jaxrs-cxf-cdi and other JaxRS generators, the implFolder config is not honored by hte generator on windows.
The issue is due to file path manipulations in AbstractJavaJAXRSServerCodegen:apiFilename that uses '/' as a separator, while DefaultCodeGen:apiFilename uses File.separator since e7f4fb3c453e08582c9b955d64321fce8cb1e539 introduced for #7808
Swagger-codegen version
Tested on 2.3.1 and 2.4.0-SNAPSHOT, and this is a regression w.r.t. 2.2.2
Related issues/PRs
The issue that seemingly introduced the regression: https://github.com/swagger-api/swagger-codegen/issues/6443
Suggest a fix/enhancement
Use File.separator in AbstractJavaJAXRSServerCodegen:apiFilename
@Override
public String apiFilename(String templateName, String tag) {
String result = super.apiFilename(templateName, tag);
if ( templateName.endsWith("Impl.mustache") ) {
int ix = result.lastIndexOf(File.separator);
result = result.substring(0, ix) + "/impl" + result.substring(ix, result.length() - 5) + "ServiceImpl.java";
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
} else if ( templateName.endsWith("Factory.mustache") ) {
int ix = result.lastIndexOf(File.separator);
result = result.substring(0, ix) + "/factories" + result.substring(ix, result.length() - 5) + "ServiceFactory.java";
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
} else if ( templateName.endsWith("Service.mustache") ) {
int ix = result.lastIndexOf('.');
result = result.substring(0, ix) + "Service.java";
}
return result;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in AbstractJavaJAXRSServerCodegen.apiFilename and compare its path handling with DefaultCodeGen.apiFilename, particularly for Impl.mustache and Factory.mustache templates. Verify the change with a Windows JaxRS generator configuration using implFolder, and confirm generated implementation files are placed in that folder as they were in version 2.2.2.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100