Skip to content
Open
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
@@ -1,3 +1,6 @@
{{#validationAttributes}}
import type { PropertyValidationAttributes } from '../runtime{{importFileExtension}}';
{{/validationAttributes}}
/**
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,21 @@ export class TextApiResponse {
return await this.raw.text();
};
}
{{#validationAttributes}}

export interface PropertyValidationAttributes {
Comment thread
devtobi marked this conversation as resolved.
dataType?: string,
required?: boolean,
maxLength?: number,
minLength?: number,
pattern?: string,
maximum?: number,
exclusiveMaximum?: boolean,
minimum?: number,
exclusiveMinimum?: boolean,
multipleOf?: number,
maxItems?: number,
minItems?: number,
uniqueItems?: boolean
}
{{/validationAttributes}}
Comment thread
devtobi marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
{{#validationAttributes}}

export const {{classname}}PropertyValidationAttributesMap: {
[property: string]: {
dataType?: string,
required?: boolean,
maxLength?: number,
minLength?: number,
pattern?: string,
maximum?: number,
exclusiveMaximum?: boolean,
minimum?: number,
exclusiveMinimum?: boolean,
multipleOf?: number,
maxItems?: number,
minItems?: number,
uniqueItems?: boolean
}
} = {
export const {{classname}}PropertyValidationAttributesMap = {
{{#vars}}
{{#hasValidation}}
{{name}}: {
Expand Down Expand Up @@ -58,7 +42,7 @@ export const {{classname}}PropertyValidationAttributesMap: {
},
{{/hasValidation}}
{{/vars}}
}
} satisfies Record<string, PropertyValidationAttributes>;
{{#isAdditionalPropertiesTrue}}

export const {{classname}}AdditionalPropertiesValidationAttributes: { maxProperties?: number, minProperties?: number } = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void toVarName() {
codegen.processOpts();
Assert.assertEquals(codegen.toVarName("valid_var"), "valid_var");
}

@Test
public void toVarNameWithAtSign() {
TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen();
Expand Down Expand Up @@ -577,7 +577,31 @@ public void testValidationAttributesWithWithoutRuntimeChecks() throws IOExceptio
Path modelsIndex = Paths.get(output + "/models/index.ts");
TestUtils.assertFileExists(modelsIndex);
TestUtils.assertFileContains(modelsIndex, "PetPropertyValidationAttributesMap");
TestUtils.assertFileContains(modelsIndex, "[property: string]:");
TestUtils.assertFileContains(modelsIndex, "satisfies Record<string, PropertyValidationAttributes>");
TestUtils.assertFileContains(modelsIndex, "import type { PropertyValidationAttributes } from '../runtime';");

Path runtime = Paths.get(output + "/runtime.ts");
TestUtils.assertFileExists(runtime);
TestUtils.assertFileContains(runtime, "export interface PropertyValidationAttributes");
}

@Test(description = "Verify validationAttributes not exist with validationAttributes=false")
public void testValidationAttributesNotExistWithFalse() throws IOException {
Map<String, Object> properties = new HashMap<>();
properties.put(TypeScriptFetchClientCodegen.VALIDATION_ATTRIBUTES, false);
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.assertFileExists(modelsIndex);
TestUtils.assertFileNotContains(modelsIndex, "PetPropertyValidationAttributesMap");
TestUtils.assertFileNotContains(modelsIndex, "satisfies Record<string, PropertyValidationAttributes>");
TestUtils.assertFileNotContains(modelsIndex, "import type { PropertyValidationAttributes } from '../runtime';");

Path runtime = Paths.get(output + "/runtime.ts");
TestUtils.assertFileExists(runtime);
TestUtils.assertFileNotContains(runtime, "export interface PropertyValidationAttributes");
}

@Test(description = "Verify pattern is not HTML-escaped in validationAttributes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

import { mapValues } from '../runtime';
import type { PropertyValidationAttributes } from '../runtime';
/**
* A category for a pet
* @export
Expand All @@ -28,28 +29,12 @@ export interface Category {
*/
name?: string;
}
export const CategoryPropertyValidationAttributesMap: {
[property: string]: {
dataType?: string,
required?: boolean,
maxLength?: number,
minLength?: number,
pattern?: string,
maximum?: number,
exclusiveMaximum?: boolean,
minimum?: number,
exclusiveMinimum?: boolean,
multipleOf?: number,
maxItems?: number,
minItems?: number,
uniqueItems?: boolean
}
} = {
export const CategoryPropertyValidationAttributesMap = {
name: {
dataType: "string",
pattern: '/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/',
},
}
} satisfies Record<string, PropertyValidationAttributes>;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

import { mapValues } from '../runtime';
import type { PropertyValidationAttributes } from '../runtime';
/**
* Describes the result of uploading an image resource
* @export
Expand All @@ -32,24 +33,8 @@ export interface ModelApiResponse {
*/
message?: string;
}
export const ModelApiResponsePropertyValidationAttributesMap: {
[property: string]: {
dataType?: string,
required?: boolean,
maxLength?: number,
minLength?: number,
pattern?: string,
maximum?: number,
exclusiveMaximum?: boolean,
minimum?: number,
exclusiveMinimum?: boolean,
multipleOf?: number,
maxItems?: number,
minItems?: number,
uniqueItems?: boolean
}
} = {
}
export const ModelApiResponsePropertyValidationAttributesMap = {
} satisfies Record<string, PropertyValidationAttributes>;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

import { mapValues } from '../runtime';
import type { PropertyValidationAttributes } from '../runtime';
/**
* An order for a pets from the pet store
* @export
Expand Down Expand Up @@ -57,24 +58,8 @@ export const OrderStatusEnum = {
} as const;
export type OrderStatusEnum = typeof OrderStatusEnum[keyof typeof OrderStatusEnum];

export const OrderPropertyValidationAttributesMap: {
[property: string]: {
dataType?: string,
required?: boolean,
maxLength?: number,
minLength?: number,
pattern?: string,
maximum?: number,
exclusiveMaximum?: boolean,
minimum?: number,
exclusiveMinimum?: boolean,
multipleOf?: number,
maxItems?: number,
minItems?: number,
uniqueItems?: boolean
}
} = {
}
export const OrderPropertyValidationAttributesMap = {
} satisfies Record<string, PropertyValidationAttributes>;

export const OrderAdditionalPropertiesValidationAttributes: { maxProperties?: number, minProperties?: number } = {
maxProperties: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
TagToJSONTyped,
} from './Tag';

import type { PropertyValidationAttributes } from '../runtime';
/**
* A pet for sale in the pet store
* @export
Expand Down Expand Up @@ -72,31 +73,15 @@ export const PetStatusEnum = {
} as const;
export type PetStatusEnum = typeof PetStatusEnum[keyof typeof PetStatusEnum];

export const PetPropertyValidationAttributesMap: {
[property: string]: {
dataType?: string,
required?: boolean,
maxLength?: number,
minLength?: number,
pattern?: string,
maximum?: number,
exclusiveMaximum?: boolean,
minimum?: number,
exclusiveMinimum?: boolean,
multipleOf?: number,
maxItems?: number,
minItems?: number,
uniqueItems?: boolean
}
} = {
export const PetPropertyValidationAttributesMap = {
photoUrls: {
dataType: "Set<string>",
required: true,
maxItems: 8,
minItems: 1,
uniqueItems: true,
},
}
} satisfies Record<string, PropertyValidationAttributes>;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

import { mapValues } from '../runtime';
import type { PropertyValidationAttributes } from '../runtime';
/**
* A tag for a pet
* @export
Expand All @@ -28,24 +29,8 @@ export interface Tag {
*/
name?: string;
}
export const TagPropertyValidationAttributesMap: {
[property: string]: {
dataType?: string,
required?: boolean,
maxLength?: number,
minLength?: number,
pattern?: string,
maximum?: number,
exclusiveMaximum?: boolean,
minimum?: number,
exclusiveMinimum?: boolean,
multipleOf?: number,
maxItems?: number,
minItems?: number,
uniqueItems?: boolean
}
} = {
}
export const TagPropertyValidationAttributesMap = {
} satisfies Record<string, PropertyValidationAttributes>;
Comment thread
devtobi marked this conversation as resolved.


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

import { mapValues } from '../runtime';
import type { PropertyValidationAttributes } from '../runtime';
/**
* A User who is purchasing from the pet store
* @export
Expand Down Expand Up @@ -56,23 +57,7 @@ export interface User {
*/
userStatus?: number;
}
export const UserPropertyValidationAttributesMap: {
[property: string]: {
dataType?: string,
required?: boolean,
maxLength?: number,
minLength?: number,
pattern?: string,
maximum?: number,
exclusiveMaximum?: boolean,
minimum?: number,
exclusiveMinimum?: boolean,
multipleOf?: number,
maxItems?: number,
minItems?: number,
uniqueItems?: boolean
}
} = {
export const UserPropertyValidationAttributesMap = {
password: {
dataType: "string",
maxLength: 256,
Expand All @@ -90,7 +75,7 @@ export const UserPropertyValidationAttributesMap: {
exclusiveMinimum: true,
multipleOf: 10,
},
}
} satisfies Record<string, PropertyValidationAttributes>;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,19 @@ export class TextApiResponse {
return await this.raw.text();
};
}

export interface PropertyValidationAttributes {
dataType?: string,
required?: boolean,
maxLength?: number,
minLength?: number,
pattern?: string,
maximum?: number,
exclusiveMaximum?: boolean,
minimum?: number,
exclusiveMinimum?: boolean,
multipleOf?: number,
maxItems?: number,
minItems?: number,
uniqueItems?: boolean
}
Loading