OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-angular] pattern data gets improperly escaped
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
This issue has been raised and fixed years ago for the typescript-axios client:
- BUG: #5973
- PR: #5974
I feel like the problem it is sufficiently described, so not adding any more details here.
Example:
{{{pattern}}}is/^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$/{{{pattern}}}should be/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
openapi-generator version
- LATEST
Steps to reproduce
-
Include this pattern in your OpenAPI spec
{ "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$", } -
Run the
typescript-angulargenerator- NOTE: That the out of the box templates do NOT use the pattern field. For my needs I have adjusted the
mustachetemplates to include them. So to reproduce you might have to do the same.
- NOTE: That the out of the box templates do NOT use the pattern field. For my needs I have adjusted the
-
Actual vs. Expected output:
{{{pattern}}}is/^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$/{{{pattern}}}should be/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
Related issues/PRs
- #5973
- #5974
Suggest a fix
Two options here:
- A patch for
typescript-angularonly- Apply the same patch that was done for typescript-axios and override the
toRegularExpressionmethod inTypeScriptAngularClientCodegen.java
- Apply the same patch that was done for typescript-axios and override the
- A full fix for all
typescriptbased client (as all typescript generators will eventually face the same problem)- Override the
toRegularExpressionmethod in theAbstractTypeScriptClientCodegen.javaabstract base class.
- Override the
The implementation will be the same regardless of the option choosen (just the location would change). Here is that code:
/**
* Overriding toRegularExpression() to avoid escapeText() being called,
* as it would return a broken regular expression if any escaped character / metacharacter were present.
*/
@Override
public String toRegularExpression(String pattern) {
return addRegularExpressionDelimiter(pattern);
}
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 by comparing the existing typescript-axios fix in PR #5974 with TypeScriptAngularClientCodegen.java and AbstractTypeScriptClientCodegen.java. Reproduce the issue with the OpenAPI pattern shown and the typescript-angular generator; done means generated pattern data retains the intended backslashes without improper escaping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100