swagger-api / swagger-api/swagger-codegen
Error using templateDirectory due to regex issue
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Specifying templateDirectory in swagger-codegen-maven-plugin in Windows causes a regex issue within DefaultGenerator L:1014. The resulting template path might result in an incorrect regular expression, because of window path-separator "". Hence each following character is treated as a regular-expression escaped character implicitly.
For example a template-Directory "src/main/resources/spec" will be resolved to "C:[project-basedir]\src\main\resource\spec". Now templateFile.replaceFirst is taken a regular expression and "\s" means a whitespace in this context.
Swagger-codegen version
3.0.0-rc1
Suggest a fix/enhancement
Do not use String.replaceFirst, because this uses a regular expression, instead of the real given path. Apache commons-lang StringUtils provides useful ways to strip the first matching path.
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
Inspect DefaultGenerator around line 1014 and the templateFile.replaceFirst call; start by tracing how the Windows templateDirectory path is constructed. Reproduce the issue with a Windows-style path, then verify that the resulting template path is handled literally rather than as a regular expression.
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
- 35/100