-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Open
Labels
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: [BUG][typescript-axios] pattern data gets improperly escaped #5973
- PR: [typescript-axios] fixed pattern data integrity #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
- [BUG][typescript-axios] pattern data gets improperly escaped #5973
- [typescript-axios] fixed pattern data integrity #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);
}