Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const {{classname}}PropertyValidationAttributesMap: {
minLength: {{minLength}},
{{/minLength}}
{{#pattern}}
pattern: '{{pattern}}',
pattern: '{{{pattern}}}',
{{/pattern}}
{{#maximum}}
maximum: {{maximum}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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&amp;]+$/'");
TestUtils.assertFileContains(modelsIndex, "pattern: '/^[a-z&]+$/'");
}

@Test(description = "Verify withRequestOptsInInterface=true (default) includes RequestOpts in interface")
public void testRequestOptsInInterfaceByDefault() throws IOException {
Map<String, Object> properties = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ components:
maxLength: 256
phone:
type: string
nickname:
type: string
pattern: '^[a-z&]+$'
userStatus:
type: integer
format: int32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Name | Type
`email` | string
`password` | string
`phone` | string
`nickname` | string
`userStatus` | number

## Example
Expand All @@ -30,6 +31,7 @@ const example = {
"email": null,
"password": null,
"phone": null,
"nickname": null,
"userStatus": null,
} satisfies User

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export interface User {
* @memberof User
*/
phone?: string;
/**
*
* @type {string}
* @memberof User
*/
nickname?: string;
/**
* User Status
* @type {number}
Expand All @@ -87,6 +93,9 @@ export const UserPropertyValidationAttributesMap: {
maxLength: 256,
minLength: 8,
},
nickname: {
pattern: '/^[a-z&]+$/',
},
userStatus: {
maximum: 100,
exclusiveMaximum: true,
Expand Down Expand Up @@ -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'],
};
}
Expand All @@ -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'],
};
}
Expand Down
Loading