Skip to content

[BUG] [typescript-angular] pattern data gets improperly escaped #21283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 of 6 tasks
spunzmann opened this issue May 15, 2025 · 0 comments
Open
5 of 6 tasks

[BUG] [typescript-angular] pattern data gets improperly escaped #21283

spunzmann opened this issue May 15, 2025 · 0 comments

Comments

@spunzmann
Copy link

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:

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
  1. Include this pattern in your OpenAPI spec

    {
        "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$",
    }
  2. Run the typescript-angular generator

    • NOTE: That the out of the box templates do NOT use the pattern field. For my needs I have adjusted the mustache templates to include them. So to reproduce you might have to do the same.
  3. 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
Suggest a fix

Two options here:

  1. A patch for typescript-angular only
    • Apply the same patch that was done for typescript-axios and override the toRegularExpression method in TypeScriptAngularClientCodegen.java
  2. A full fix for all typescript based client (as all typescript generators will eventually face the same problem)
    • Override the toRegularExpression method in the AbstractTypeScriptClientCodegen.java abstract base class.

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);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant