Skip to content
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

[BUG][typescript-axios] pattern data gets improperly escaped #5973

Closed
5 tasks done
n0idea opened this issue Apr 17, 2020 · 1 comment · Fixed by #5974
Closed
5 tasks done

[BUG][typescript-axios] pattern data gets improperly escaped #5973

n0idea opened this issue Apr 17, 2020 · 1 comment · Fixed by #5974

Comments

@n0idea
Copy link
Contributor

n0idea commented Apr 17, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue? Check below

  • Have you validated the input using an OpenAPI validator (example)? Yes

  • What's the version of OpenAPI Generator used? 4.3.1

  • Have you search for related issues/PRs? Yes

  • What's the actual output vs expected output?

  • Example
    {{{pattern}}} is /\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+/
    {{{pattern}}} should be /\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+/

Description

While generating a typescript-axios client, pattern property gets improperly escaped, resulting in a non-valid regular expression. This seems to be caused by toRegularExpression(String pattern)method calling escapeText(String input): overriding the method for TypeScriptAxiosClientCodegen and removing escapeText() call fixes it (I'm raising a PR for this).

openapi-generator version

openapi-generator-cli 4.3.1-SNAPSHOT
commit : cb50ad5
built : 2020-04-17T20:52:08+02:00
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/

OpenAPI declaration file content or url

Here's a minimal spec to reproduce the issue:

{
  "openapi": "3.0.1",
  "info": {
    "title": "[...]",
    "version": "1.0.0"
  },
  "paths": {
    "/account/register": {
      "post": {
        "tags": [
          "Account"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Register"
              }
            },
            "text/json": {
              "schema": {
                "$ref": "#/components/schemas/Register"
              }
            },
            "application/*+json": {
              "schema": {
                "$ref": "#/components/schemas/Register"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Register": {
        "required": [
          "Email",
          "Password"
        ],
        "type": "object",
        "properties": {
          "Email": {
            "pattern": "\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+",
            "type": "string"
          },
          "Password": {
            "pattern": "(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[#$^+=!*()@%&]).{6,}",
            "type": "string"
          }
        }
      }
    }
  }
}

Command line used for generation

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i <...> -g typescript-axios -o test/client -t ./

@auto-labeler
Copy link

auto-labeler bot commented Apr 17, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant