[BUG][typescript-axios] pattern data gets improperly escaped
Created by: n0idea
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 : cb50ad59 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 ./