diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/validationAttributes.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/validationAttributes.mustache index 7ddff376299f..6dddc042bac0 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/validationAttributes.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/validationAttributes.mustache @@ -25,7 +25,7 @@ export const {{classname}}PropertyValidationAttributesMap: { minLength: {{minLength}}, {{/minLength}} {{#pattern}} - pattern: '{{pattern}}', + pattern: '{{{pattern}}}', {{/pattern}} {{#maximum}} maximum: {{maximum}}, diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java index bb63f62225ea..da183535f3ad 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java @@ -459,6 +459,19 @@ public void testValidationAttributesWithWithoutRuntimeChecks() throws IOExceptio TestUtils.assertFileContains(modelsIndex, "[property: string]:"); } + @Test(description = "Verify pattern is not HTML-escaped in validationAttributes") + public void testValidationAttributesPatternIsNotHtmlEscaped() throws IOException { + Map properties = new HashMap<>(); + properties.put(TypeScriptFetchClientCodegen.VALIDATION_ATTRIBUTES, true); + properties.put(TypeScriptFetchClientCodegen.WITHOUT_RUNTIME_CHECKS, true); + + File output = generate(properties, "src/test/resources/3_0/typescript-fetch/validation-attributes.yaml"); + + Path modelsIndex = Paths.get(output + "/models/index.ts"); + TestUtils.assertFileNotContains(modelsIndex, "pattern: '/^[a-z&]+$/'"); + TestUtils.assertFileContains(modelsIndex, "pattern: '/^[a-z&]+$/'"); + } + @Test(description = "Verify withRequestOptsInInterface=true (default) includes RequestOpts in interface") public void testRequestOptsInInterfaceByDefault() throws IOException { Map properties = new HashMap<>(); diff --git a/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/validation-attributes.yaml b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/validation-attributes.yaml index f8bbf01a83f7..76eb1bb9885c 100644 --- a/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/validation-attributes.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/validation-attributes.yaml @@ -675,6 +675,9 @@ components: maxLength: 256 phone: type: string + nickname: + type: string + pattern: '^[a-z&]+$' userStatus: type: integer format: int32 diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/docs/User.md b/samples/client/petstore/typescript-fetch/builds/validation-attributes/docs/User.md index af455b7cf7b2..4675e2b7b1d0 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/docs/User.md +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/docs/User.md @@ -14,6 +14,7 @@ Name | Type `email` | string `password` | string `phone` | string +`nickname` | string `userStatus` | number ## Example @@ -30,6 +31,7 @@ const example = { "email": null, "password": null, "phone": null, + "nickname": null, "userStatus": null, } satisfies User diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts index fd515e217965..14cdd264cac7 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts @@ -61,6 +61,12 @@ export interface User { * @memberof User */ phone?: string; + /** + * + * @type {string} + * @memberof User + */ + nickname?: string; /** * User Status * @type {number} @@ -87,6 +93,9 @@ export const UserPropertyValidationAttributesMap: { maxLength: 256, minLength: 8, }, + nickname: { + pattern: '/^[a-z&]+$/', + }, userStatus: { maximum: 100, exclusiveMaximum: true, @@ -121,6 +130,7 @@ export function UserFromJSONTyped(json: any, ignoreDiscriminator: boolean): User 'email': json['email'] == null ? undefined : json['email'], 'password': json['password'] == null ? undefined : json['password'], 'phone': json['phone'] == null ? undefined : json['phone'], + 'nickname': json['nickname'] == null ? undefined : json['nickname'], 'userStatus': json['userStatus'] == null ? undefined : json['userStatus'], }; } @@ -143,6 +153,7 @@ export function UserToJSONTyped(value?: User | null, ignoreDiscriminator: boolea 'email': value['email'], 'password': value['password'], 'phone': value['phone'], + 'nickname': value['nickname'], 'userStatus': value['userStatus'], }; }