@tsed/schema 6.97.2 → 6.98.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/decorators/common/enum.js +1 -20
- package/lib/cjs/decorators/common/enum.js.map +1 -1
- package/lib/cjs/decorators/index.js +2 -0
- package/lib/cjs/decorators/index.js.map +1 -1
- package/lib/cjs/decorators/operations/acceptMime.js +28 -0
- package/lib/cjs/decorators/operations/acceptMime.js.map +1 -0
- package/lib/cjs/decorators/operations/view.js +31 -0
- package/lib/cjs/decorators/operations/view.js.map +1 -0
- package/lib/cjs/domain/JsonMethodStore.js +37 -1
- package/lib/cjs/domain/JsonMethodStore.js.map +1 -1
- package/lib/cjs/domain/JsonOperationRoute.js +7 -0
- package/lib/cjs/domain/JsonOperationRoute.js.map +1 -1
- package/lib/cjs/domain/JsonParameter.js +4 -2
- package/lib/cjs/domain/JsonParameter.js.map +1 -1
- package/lib/cjs/domain/JsonParameterStore.js +13 -4
- package/lib/cjs/domain/JsonParameterStore.js.map +1 -1
- package/lib/cjs/domain/JsonPropertyStore.js +5 -1
- package/lib/cjs/domain/JsonPropertyStore.js.map +1 -1
- package/lib/cjs/domain/JsonSchema.js +4 -11
- package/lib/cjs/domain/JsonSchema.js.map +1 -1
- package/lib/cjs/utils/getOperationsRoutes.js.map +1 -1
- package/lib/cjs/utils/mapNullableType.js +1 -1
- package/lib/cjs/utils/mapNullableType.js.map +1 -1
- package/lib/cjs/utils/serializeEnumValues.js +35 -0
- package/lib/cjs/utils/serializeEnumValues.js.map +1 -0
- package/lib/esm/decorators/common/enum.js +1 -20
- package/lib/esm/decorators/common/enum.js.map +1 -1
- package/lib/esm/decorators/index.js +2 -0
- package/lib/esm/decorators/index.js.map +1 -1
- package/lib/esm/decorators/operations/acceptMime.js +24 -0
- package/lib/esm/decorators/operations/acceptMime.js.map +1 -0
- package/lib/esm/decorators/operations/view.js +27 -0
- package/lib/esm/decorators/operations/view.js.map +1 -0
- package/lib/esm/domain/JsonMethodStore.js +37 -1
- package/lib/esm/domain/JsonMethodStore.js.map +1 -1
- package/lib/esm/domain/JsonOperationRoute.js +7 -0
- package/lib/esm/domain/JsonOperationRoute.js.map +1 -1
- package/lib/esm/domain/JsonParameter.js +4 -2
- package/lib/esm/domain/JsonParameter.js.map +1 -1
- package/lib/esm/domain/JsonParameterStore.js +13 -4
- package/lib/esm/domain/JsonParameterStore.js.map +1 -1
- package/lib/esm/domain/JsonPropertyStore.js +4 -0
- package/lib/esm/domain/JsonPropertyStore.js.map +1 -1
- package/lib/esm/domain/JsonSchema.js +4 -11
- package/lib/esm/domain/JsonSchema.js.map +1 -1
- package/lib/esm/utils/getOperationsRoutes.js.map +1 -1
- package/lib/esm/utils/mapNullableType.js +1 -1
- package/lib/esm/utils/mapNullableType.js.map +1 -1
- package/lib/esm/utils/serializeEnumValues.js +30 -0
- package/lib/esm/utils/serializeEnumValues.js.map +1 -0
- package/lib/types/decorators/index.d.ts +2 -0
- package/lib/types/decorators/operations/acceptMime.d.ts +19 -0
- package/lib/types/decorators/operations/view.d.ts +23 -0
- package/lib/types/domain/JsonMethodStore.d.ts +48 -0
- package/lib/types/domain/JsonOperationRoute.d.ts +5 -3
- package/lib/types/domain/JsonParameterStore.d.ts +23 -1
- package/lib/types/domain/JsonPropertyStore.d.ts +7 -0
- package/lib/types/domain/JsonSchema.d.ts +1 -1
- package/lib/types/utils/getOperationsRoutes.d.ts +2 -2
- package/lib/types/utils/mapNullableType.d.ts +1 -1
- package/lib/types/utils/serializeEnumValues.d.ts +5 -0
- package/package.json +7 -7
|
@@ -1,29 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Enum = void 0;
|
|
4
|
-
const core_1 = require("@tsed/core");
|
|
5
4
|
const jsonEntityFn_1 = require("./jsonEntityFn");
|
|
6
|
-
const transformTsEnum = (enumValue) => {
|
|
7
|
-
return Object.keys(enumValue).reduce((acc, key) => {
|
|
8
|
-
if (isNaN(+key)) {
|
|
9
|
-
const value = enumValue[key];
|
|
10
|
-
return acc.concat(value);
|
|
11
|
-
}
|
|
12
|
-
return acc;
|
|
13
|
-
}, []);
|
|
14
|
-
};
|
|
15
5
|
function Enum(enumValue, ...enumValues) {
|
|
16
6
|
return (0, jsonEntityFn_1.JsonEntityFn)((store) => {
|
|
17
|
-
|
|
18
|
-
if ((0, core_1.isObject)(value) && value !== null) {
|
|
19
|
-
value = transformTsEnum(value);
|
|
20
|
-
}
|
|
21
|
-
return acc.concat(value);
|
|
22
|
-
}, []);
|
|
23
|
-
const types = values.reduce((set, value) => {
|
|
24
|
-
return set.add(value === null ? "null" : typeof value);
|
|
25
|
-
}, new Set());
|
|
26
|
-
store.itemSchema.enum(values).any(...types);
|
|
7
|
+
store.itemSchema.enum(enumValue, ...enumValues);
|
|
27
8
|
});
|
|
28
9
|
}
|
|
29
10
|
exports.Enum = Enum;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../../src/decorators/common/enum.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../../src/decorators/common/enum.ts"],"names":[],"mappings":";;;AACA,iDAA4C;AAmG5C,SAAgB,IAAI,CAAC,SAAgC,EAAE,GAAG,UAA6B;IACrF,OAAO,IAAA,2BAAY,EAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,UAAU,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,oBAIC","sourcesContent":["import type {JSONSchema6Type} from \"json-schema\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * The enum keyword is used to restrict a value to a fixed set of values.\n * It must be an array with at least one element, where each element is unique.\n *\n * Elements in the array might be of any value, including null.\n *\n * ::: warning\n * For v6 user, use @@Enum@@ from @tsed/schema instead of @tsed/common.\n * :::\n *\n * ## Example\n * ### With primitive type\n *\n * ```typescript\n * class Model {\n * @Enum(\"value1\", \"value2\")\n * property: \"value1\" | \"value2\";\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"enum\": [\"value1\", \"value2\"]\n * }\n * }\n * }\n * ```\n *\n * ### With array type\n *\n * ```typescript\n * class Model {\n * @Enum(\"value1\", \"value2\")\n * property: (\"value1\" | \"value2\")[];\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"array\",\n * \"items\": {\n * \"type\": \"string\",\n * \"enum\": [\"value1\", \"value2\"]\n * }\n * }\n * }\n * }\n * ```\n *\n * ### With Typescript Enum\n *\n * ```typescript\n * enum SomeEnum {\n * ENUM_1 = \"enum1\",\n * ENUM_2 = \"enum2\"\n * }\n *\n * class Model {\n * @Enum(SomeEnum)\n * property: SomeEnum;\n * }\n * ```\n *\n * Will produce:\n *\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"property\": {\n * \"type\": \"string\",\n * \"enum\": [\"enum1\", \"enum2\"]\n * }\n * }\n * }\n * ```\n *\n * @param {string | number | boolean | {}} enumValue\n * @param enumValues\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n */\nexport function Enum(...enumValues: (JSONSchema6Type | any)[]): Function;\nexport function Enum(enumValue: JSONSchema6Type | any, ...enumValues: JSONSchema6Type[]) {\n return JsonEntityFn((store) => {\n store.itemSchema.enum(enumValue, ...enumValues);\n });\n}\n"]}
|
|
@@ -17,6 +17,7 @@ const tslib_1 = require("tslib");
|
|
|
17
17
|
// operations
|
|
18
18
|
(0, tslib_1.__exportStar)(require("./operations/deprecated"), exports);
|
|
19
19
|
(0, tslib_1.__exportStar)(require("./operations/consumes"), exports);
|
|
20
|
+
(0, tslib_1.__exportStar)(require("./operations/view"), exports);
|
|
20
21
|
(0, tslib_1.__exportStar)(require("./operations/contentType"), exports);
|
|
21
22
|
(0, tslib_1.__exportStar)(require("./operations/in"), exports);
|
|
22
23
|
(0, tslib_1.__exportStar)(require("./operations/inFile"), exports);
|
|
@@ -34,6 +35,7 @@ const tslib_1 = require("tslib");
|
|
|
34
35
|
(0, tslib_1.__exportStar)(require("./operations/redirect"), exports);
|
|
35
36
|
(0, tslib_1.__exportStar)(require("./operations/location"), exports);
|
|
36
37
|
(0, tslib_1.__exportStar)(require("./operations/route"), exports);
|
|
38
|
+
(0, tslib_1.__exportStar)(require("./operations/acceptMime"), exports);
|
|
37
39
|
// common
|
|
38
40
|
(0, tslib_1.__exportStar)(require("./common/additionalProperties"), exports);
|
|
39
41
|
(0, tslib_1.__exportStar)(require("./common/allow"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,QAAQ;AACR,gEAAiC;AAEjC,cAAc;AACd,gFAAiD;AACjD,0EAA2C;AAC3C,sEAAuC;AACvC,sEAAuC;AACvC,yEAA0C;AAC1C,2EAA4C;AAC5C,2EAA4C;AAE5C,WAAW;AACX,mEAAoC;AACpC,oEAAqC;AAErC,aAAa;AACb,uEAAwC;AACxC,qEAAsC;AACtC,wEAAyC;AACzC,+DAAgC;AAChC,mEAAoC;AACpC,wEAAyC;AACzC,0EAA2C;AAC3C,iEAAkC;AAClC,qEAAsC;AACtC,oEAAqC;AACrC,mEAAoC;AACpC,mEAAoC;AACpC,qEAAsC;AACtC,iEAAkC;AAClC,oEAAqC;AACrC,oEAAqC;AACrC,qEAAsC;AACtC,qEAAsC;AACtC,kEAAmC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,QAAQ;AACR,gEAAiC;AAEjC,cAAc;AACd,gFAAiD;AACjD,0EAA2C;AAC3C,sEAAuC;AACvC,sEAAuC;AACvC,yEAA0C;AAC1C,2EAA4C;AAC5C,2EAA4C;AAE5C,WAAW;AACX,mEAAoC;AACpC,oEAAqC;AAErC,aAAa;AACb,uEAAwC;AACxC,qEAAsC;AACtC,iEAAkC;AAClC,wEAAyC;AACzC,+DAAgC;AAChC,mEAAoC;AACpC,wEAAyC;AACzC,0EAA2C;AAC3C,iEAAkC;AAClC,qEAAsC;AACtC,oEAAqC;AACrC,mEAAoC;AACpC,mEAAoC;AACpC,qEAAsC;AACtC,iEAAkC;AAClC,oEAAqC;AACrC,oEAAqC;AACrC,qEAAsC;AACtC,qEAAsC;AACtC,kEAAmC;AACnC,uEAAwC;AAExC,SAAS;AACT,6EAA8C;AAC9C,8DAA+B;AAC/B,4DAA6B;AAC7B,gEAAiC;AACjC,8DAA+B;AAC/B,gEAAiC;AACjC,oEAAqC;AACrC,gEAAiC;AACjC,iEAAkC;AAClC,6DAA8B;AAC9B,yEAA0C;AAC1C,yEAA0C;AAC1C,+DAAgC;AAChC,sEAAuC;AACvC,+DAAgC;AAChC,gEAAiC;AACjC,+DAAgC;AAChC,gEAAiC;AACjC,kEAAmC;AACnC,gEAAiC;AACjC,kEAAmC;AACnC,mEAAoC;AACpC,6DAA8B;AAC9B,iEAAkC;AAClC,uEAAwC;AACxC,iEAAkC;AAClC,+DAAgC;AAChC,8DAA+B;AAC/B,+DAAgC;AAChC,8DAA+B;AAC/B,8DAA+B;AAC/B,8DAA+B;AAC/B,qEAAsC;AACtC,iEAAkC;AAClC,kEAAmC;AACnC,iEAAkC;AAClC,kEAAmC;AACnC,iEAAkC;AAClC,4EAA6C","sourcesContent":["// class\nexport * from \"./class/children\";\n\n// collections\nexport * from \"./collections/collectionContains\";\nexport * from \"./collections/collectionOf\";\nexport * from \"./collections/maxItems\";\nexport * from \"./collections/minItems\";\nexport * from \"./collections/uniqueItems\";\nexport * from \"./collections/maxProperties\";\nexport * from \"./collections/minProperties\";\n\n// generics\nexport * from \"./generics/generics\";\nexport * from \"./generics/genericOf\";\n\n// operations\nexport * from \"./operations/deprecated\";\nexport * from \"./operations/consumes\";\nexport * from \"./operations/view\";\nexport * from \"./operations/contentType\";\nexport * from \"./operations/in\";\nexport * from \"./operations/inFile\";\nexport * from \"./operations/operationId\";\nexport * from \"./operations/operationPath\";\nexport * from \"./operations/path\";\nexport * from \"./operations/produces\";\nexport * from \"./operations/returns\";\nexport * from \"./operations/status\";\nexport * from \"./operations/header\";\nexport * from \"./operations/security\";\nexport * from \"./operations/tags\";\nexport * from \"./operations/summary\";\nexport * from \"./operations/partial\";\nexport * from \"./operations/redirect\";\nexport * from \"./operations/location\";\nexport * from \"./operations/route\";\nexport * from \"./operations/acceptMime\";\n\n// common\nexport * from \"./common/additionalProperties\";\nexport * from \"./common/allow\";\nexport * from \"./common/any\";\nexport * from \"./common/integer\";\nexport * from \"./common/const\";\nexport * from \"./common/default\";\nexport * from \"./common/description\";\nexport * from \"./common/example\";\nexport * from \"./common/examples\";\nexport * from \"./common/enum\";\nexport * from \"./common/exclusiveMaximum\";\nexport * from \"./common/exclusiveMinimum\";\nexport * from \"./common/format\";\nexport * from \"./common/forwardGroups\";\nexport * from \"./common/groups\";\nexport * from \"./common/pattern\";\nexport * from \"./common/ignore\";\nexport * from \"./common/maximum\";\nexport * from \"./common/maxLength\";\nexport * from \"./common/minimum\";\nexport * from \"./common/minLength\";\nexport * from \"./common/multipleOf\";\nexport * from \"./common/name\";\nexport * from \"./common/required\";\nexport * from \"./common/requiredGroups\";\nexport * from \"./common/property\";\nexport * from \"./common/hidden\";\nexport * from \"./common/title\";\nexport * from \"./common/schema\";\nexport * from \"./common/oneOf\";\nexport * from \"./common/allOf\";\nexport * from \"./common/anyOf\";\nexport * from \"./common/jsonEntityFn\";\nexport * from \"./common/optional\";\nexport * from \"./common/writeOnly\";\nexport * from \"./common/readOnly\";\nexport * from \"./common/customKey\";\nexport * from \"./common/nullable\";\nexport * from \"./config/jsonEntityComponent\";\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AcceptMime = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const produces_1 = require("./produces");
|
|
6
|
+
/**
|
|
7
|
+
* Set a mime list which are acceptable and checks if the specified content types are acceptable, based on the request’s Accept HTTP header field.
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Controller('/mypath')
|
|
11
|
+
* export class MyCtrl {
|
|
12
|
+
*
|
|
13
|
+
* @Get('/')
|
|
14
|
+
* @AcceptMime('application/json')
|
|
15
|
+
* public getResource(){}
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param mimes
|
|
20
|
+
* @decorator
|
|
21
|
+
* @operation
|
|
22
|
+
* @response
|
|
23
|
+
*/
|
|
24
|
+
function AcceptMime(...mimes) {
|
|
25
|
+
return (0, core_1.useDecorators)((0, produces_1.Produces)(...mimes), (0, core_1.StoreSet)("acceptMimes", mimes));
|
|
26
|
+
}
|
|
27
|
+
exports.AcceptMime = AcceptMime;
|
|
28
|
+
//# sourceMappingURL=acceptMime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acceptMime.js","sourceRoot":"","sources":["../../../../src/decorators/operations/acceptMime.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,yCAAoC;AAEpC;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,UAAU,CAAC,GAAG,KAAe;IAC3C,OAAO,IAAA,oBAAa,EAAC,IAAA,mBAAQ,EAAC,GAAG,KAAK,CAAC,EAAE,IAAA,eAAQ,EAAC,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC;AAC3E,CAAC;AAFD,gCAEC","sourcesContent":["import {StoreSet, useDecorators} from \"@tsed/core\";\nimport {Produces} from \"./produces\";\n\n/**\n * Set a mime list which are acceptable and checks if the specified content types are acceptable, based on the request’s Accept HTTP header field.\n *\n * ```typescript\n * @Controller('/mypath')\n * export class MyCtrl {\n *\n * @Get('/')\n * @AcceptMime('application/json')\n * public getResource(){}\n * }\n * ```\n *\n * @param mimes\n * @decorator\n * @operation\n * @response\n */\nexport function AcceptMime(...mimes: string[]): Function {\n return useDecorators(Produces(...mimes), StoreSet(\"acceptMimes\", mimes));\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.View = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
/**
|
|
6
|
+
* Use a view and sends the rendered HTML string to the client. Optional parameter:
|
|
7
|
+
*
|
|
8
|
+
* * viewOptions, an object whose properties define local variables for the view.
|
|
9
|
+
*
|
|
10
|
+
* The view argument is a string that is the file path of the view file to render.
|
|
11
|
+
* This can be an absolute path, or a path relative to the views setting.
|
|
12
|
+
* If the path does not contain a file extension, then the view engine setting determines the file extension.
|
|
13
|
+
* If the path does contain a file extension, then Express will load the module for the specified template engine (via require())
|
|
14
|
+
* and render it using the loaded module’s __express function.
|
|
15
|
+
*
|
|
16
|
+
* For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).
|
|
17
|
+
*
|
|
18
|
+
* > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,
|
|
19
|
+
* and as so for security reasons should not contain input from the end-user.
|
|
20
|
+
*
|
|
21
|
+
* @param path Relative path to the view file.
|
|
22
|
+
* @param options Additional options
|
|
23
|
+
* @decorator
|
|
24
|
+
* @operation
|
|
25
|
+
* @response
|
|
26
|
+
*/
|
|
27
|
+
function View(path, options) {
|
|
28
|
+
return (0, core_1.StoreSet)("view", { path, options });
|
|
29
|
+
}
|
|
30
|
+
exports.View = View;
|
|
31
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../../../src/decorators/operations/view.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,IAAI,CAAC,IAAY,EAAE,OAAgB;IACjD,OAAO,IAAA,eAAQ,EAAC,MAAM,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,CAAQ,CAAC;AAClD,CAAC;AAFD,oBAEC","sourcesContent":["import {StoreSet} from \"@tsed/core\";\n\n/**\n * Use a view and sends the rendered HTML string to the client. Optional parameter:\n *\n * * viewOptions, an object whose properties define local variables for the view.\n *\n * The view argument is a string that is the file path of the view file to render.\n * This can be an absolute path, or a path relative to the views setting.\n * If the path does not contain a file extension, then the view engine setting determines the file extension.\n * If the path does contain a file extension, then Express will load the module for the specified template engine (via require())\n * and render it using the loaded module’s __express function.\n *\n * For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).\n *\n * > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,\n * and as so for security reasons should not contain input from the end-user.\n *\n * @param path Relative path to the view file.\n * @param options Additional options\n * @decorator\n * @operation\n * @response\n */\nexport function View(path: string, options?: Object): MethodDecorator {\n return StoreSet(\"view\", {path, options}) as any;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JsonMethodStore = void 0;
|
|
3
|
+
exports.EndpointMetadata = exports.JsonMethodStore = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@tsed/core");
|
|
6
6
|
const JsonEntityStore_1 = require("./JsonEntityStore");
|
|
@@ -31,6 +31,21 @@ let JsonMethodStore = class JsonMethodStore extends JsonEntityStore_1.JsonEntity
|
|
|
31
31
|
this.before(beforeMiddlewares);
|
|
32
32
|
this.use(middlewares);
|
|
33
33
|
}
|
|
34
|
+
get params() {
|
|
35
|
+
return this.parameters;
|
|
36
|
+
}
|
|
37
|
+
get view() {
|
|
38
|
+
return this.store.get("view");
|
|
39
|
+
}
|
|
40
|
+
set view(view) {
|
|
41
|
+
this.store.set("view", view);
|
|
42
|
+
}
|
|
43
|
+
get acceptMimes() {
|
|
44
|
+
return this.store.get("acceptMimes", []);
|
|
45
|
+
}
|
|
46
|
+
set acceptMimes(mimes) {
|
|
47
|
+
this.store.set("acceptMimes", mimes);
|
|
48
|
+
}
|
|
34
49
|
get parameters() {
|
|
35
50
|
return [...this.children.values()];
|
|
36
51
|
}
|
|
@@ -92,10 +107,31 @@ let JsonMethodStore = class JsonMethodStore extends JsonEntityStore_1.JsonEntity
|
|
|
92
107
|
this.middlewares = this.middlewares.concat(args).filter(core_1.isFunction);
|
|
93
108
|
return this;
|
|
94
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Find the value at the controller level. Let this value be extended or overridden by the endpoint itself.
|
|
112
|
+
*
|
|
113
|
+
* @param key
|
|
114
|
+
* @returns {any}
|
|
115
|
+
*/
|
|
116
|
+
get(key) {
|
|
117
|
+
const ctrlValue = core_1.Store.from(this.target).get(key);
|
|
118
|
+
return (0, core_1.deepMerge)(ctrlValue, this.store.get(key));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get an endpoint.
|
|
122
|
+
* @param target
|
|
123
|
+
* @param propertyKey
|
|
124
|
+
* @param descriptor
|
|
125
|
+
*/
|
|
126
|
+
static get(target, propertyKey, descriptor) {
|
|
127
|
+
descriptor = descriptor || (0, core_1.descriptorOf)((0, core_1.prototypeOf)(target), propertyKey);
|
|
128
|
+
return JsonEntityStore_1.JsonEntityStore.from((0, core_1.prototypeOf)(target), propertyKey, descriptor);
|
|
129
|
+
}
|
|
95
130
|
};
|
|
96
131
|
JsonMethodStore = (0, tslib_1.__decorate)([
|
|
97
132
|
(0, jsonEntityComponent_1.JsonEntityComponent)(core_1.DecoratorTypes.METHOD),
|
|
98
133
|
(0, tslib_1.__metadata)("design:paramtypes", [Object])
|
|
99
134
|
], JsonMethodStore);
|
|
100
135
|
exports.JsonMethodStore = JsonMethodStore;
|
|
136
|
+
exports.EndpointMetadata = JsonMethodStore;
|
|
101
137
|
//# sourceMappingURL=JsonMethodStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonMethodStore.js","sourceRoot":"","sources":["../../../src/domain/JsonMethodStore.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"JsonMethodStore.js","sourceRoot":"","sources":["../../../src/domain/JsonMethodStore.ts"],"names":[],"mappings":";;;;AAAA,qCAA4I;AAC5I,uDAA0E;AAC1E,mDAA8C;AAC9C,6CAAwC;AAGxC,kFAA6E;AAa7E,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,iCAAe;IAMlD,YAAY,OAA+B;QACzC,KAAK,CAAC;YACJ,KAAK,EAAE,YAAK,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,WAAY,CAAC;YAC7D,UAAU,EAAE,IAAA,mBAAY,EAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,WAAY,CAAC;YAC9D,GAAG,OAAO;SACX,CAAC,CAAC;QAVI,WAAM,GAAmB,iCAAe,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7D,gBAAW,GAAU,EAAE,CAAC;QACxB,sBAAiB,GAAU,EAAE,CAAC;QAC9B,qBAAgB,GAAU,EAAE,CAAC;QAepC;;WAEG;QACM,cAAS,GAAkB,IAAI,6BAAa,EAAE,CAAC;QACxD;;WAEG;QACM,aAAQ,GAA6C,IAAI,GAAG,EAAE,CAAC;QAbtE,MAAM,EAAC,iBAAiB,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,gBAAgB,GAAG,EAAE,EAAC,GAAG,OAAO,CAAC;QAElF,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,iBAAi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G;IACI,KAAK,CAAC,IAAgB;QAC3B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,iBAAU,CAAC,CAAC;QAE9E,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,GAAG,CAAC,IAAgB;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,iBAAU,CAAC,CAAC;QAEpE,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAU,GAAQ;QACnB,MAAM,SAAS,GAAG,YAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEnD,OAAO,IAAA,gBAAS,EAAI,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,GAAG,CAAC,MAAiB,EAAE,WAA4B,EAAE,UAA+B;QACzF,UAAU,GAAG,UAAU,IAAI,IAAA,mBAAY,EAAC,IAAA,kBAAW,EAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;QAE1E,OAAO,iCAAe,CAAC,IAAI,CAAkB,IAAA,kBAAW,EAAC,MAAM,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IAC7F,CAAC;CACF,CAAA;AAxJY,eAAe;IAD3B,IAAA,yCAAmB,EAAC,qBAAc,CAAC,MAAM,CAAC;;GAC9B,eAAe,CAwJ3B;AAxJY,0CAAe;AA6Kf,QAAA,gBAAgB,GAAG,eAAe,CAAC","sourcesContent":["import {DecoratorTypes, deepMerge, descriptorOf, isCollection, isFunction, isPromise, Metadata, prototypeOf, Store, Type} from \"@tsed/core\";\nimport {JsonEntityStore, JsonEntityStoreOptions} from \"./JsonEntityStore\";\nimport {JsonOperation} from \"./JsonOperation\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport type {JsonParameterStore} from \"./JsonParameterStore\";\nimport type {JsonClassStore} from \"./JsonClassStore\";\nimport {JsonEntityComponent} from \"../decorators/config/jsonEntityComponent\";\n\nexport interface JsonViewOptions {\n path: string;\n options: any;\n}\n\nexport interface JsonRedirectOptions {\n status: number | undefined;\n url: string;\n}\n\n@JsonEntityComponent(DecoratorTypes.METHOD)\nexport class JsonMethodStore extends JsonEntityStore {\n readonly parent: JsonClassStore = JsonEntityStore.from(this.target);\n public middlewares: any[] = [];\n public beforeMiddlewares: any[] = [];\n public afterMiddlewares: any[] = [];\n\n constructor(options: JsonEntityStoreOptions) {\n super({\n store: Store.fromMethod(options.target, options.propertyKey!),\n descriptor: descriptorOf(options.target, options.propertyKey!),\n ...options\n });\n\n const {beforeMiddlewares = [], middlewares = [], afterMiddlewares = []} = options;\n\n this.after(afterMiddlewares);\n this.before(beforeMiddlewares);\n this.use(middlewares);\n }\n /**\n * Ref to JsonOperation when the decorated object is a method.\n */\n readonly operation: JsonOperation = new JsonOperation();\n /**\n * List of children JsonEntityStore (properties or methods or params)\n */\n readonly children: Map<string | number, JsonParameterStore> = new Map();\n\n get params(): JsonParameterStore[] {\n return this.parameters;\n }\n\n get view(): JsonViewOptions {\n return this.store.get(\"view\") as JsonViewOptions;\n }\n\n set view(view: JsonViewOptions) {\n this.store.set(\"view\", view);\n }\n\n get acceptMimes(): string[] {\n return this.store.get<string[]>(\"acceptMimes\", []);\n }\n\n set acceptMimes(mimes: string[]) {\n this.store.set(\"acceptMimes\", mimes);\n }\n\n get parameters(): JsonParameterStore[] {\n return [...this.children.values()] as JsonParameterStore[];\n }\n\n get operationPaths() {\n return this.operation.operationPaths;\n }\n\n getResponseOptions(status: number, contentType: string = \"application/json\"): undefined | any {\n const media = this.operation.getResponseOf(status).getMedia(contentType, false);\n\n if (media && media.has(\"schema\")) {\n const schema = media.get(\"schema\") as JsonSchema;\n\n return {type: schema.getComputedItemType(), groups: media.groups};\n }\n\n return {type: this.type};\n }\n\n protected build() {\n if (!this._type) {\n let type: any = Metadata.getReturnType(this.target, this.propertyKey);\n type = isPromise(type) ? undefined : type;\n\n this.buildType(type);\n }\n\n this._type = this._type || Object;\n\n this.parent.children.set(this.propertyName, this);\n\n if (isCollection(this._type)) {\n this.collectionType = this._type;\n // @ts-ignore\n delete this._type;\n }\n\n this._schema = JsonSchema.from({\n type: this.collectionType || this.type\n });\n\n if (this.collectionType) {\n this._schema.itemSchema(this.type);\n }\n\n this.parent.schema.addProperty(this.propertyName, this.schema);\n }\n\n /**\n * Append middlewares to the beforeMiddlewares list.\n * @param args\n * @returns {EndpointMetadata}\n */\n public before(args: Function[]): this {\n this.beforeMiddlewares = this.beforeMiddlewares.concat(args).filter(isFunction);\n\n return this;\n }\n\n /**\n * Append middlewares to the afterMiddlewares list.\n * @param args\n * @returns {EndpointMetadata}\n */\n public after(args: Function[]): this {\n this.afterMiddlewares = this.afterMiddlewares.concat(args).filter(isFunction);\n\n return this;\n }\n\n /**\n * Store all arguments collected via Annotation.\n * @param args\n */\n public use(args: Function[]) {\n this.middlewares = this.middlewares.concat(args).filter(isFunction);\n\n return this;\n }\n\n /**\n * Find the value at the controller level. Let this value be extended or overridden by the endpoint itself.\n *\n * @param key\n * @returns {any}\n */\n get<T = any>(key: any): T {\n const ctrlValue = Store.from(this.target).get(key);\n\n return deepMerge<T>(ctrlValue, this.store.get(key));\n }\n\n /**\n * Get an endpoint.\n * @param target\n * @param propertyKey\n * @param descriptor\n */\n static get(target: Type<any>, propertyKey: string | symbol, descriptor?: PropertyDescriptor): JsonMethodStore {\n descriptor = descriptor || descriptorOf(prototypeOf(target), propertyKey);\n\n return JsonEntityStore.from<JsonMethodStore>(prototypeOf(target), propertyKey, descriptor);\n }\n}\n\n/**\n * EndpointMetadata contains metadata about a controller and his method.\n * Each annotation (@Get, @Body...) attached to a method are stored into endpoint.\n * EndpointMetadata convert this metadata to an array which contain arguments to call an Express method.\n *\n * Example :\n *```typescript\n * @Controller(\"/my-path\")\n * provide MyClass {\n *\n * @Get(\"/\")\n * @Authenticated()\n * public myMethod(){}\n * }\n *```\n *\n * @alias JsonMethodStore\n */\nexport type EndpointMetadata = JsonMethodStore;\nexport const EndpointMetadata = JsonMethodStore;\n"]}
|
|
@@ -5,6 +5,10 @@ const concatPath_1 = require("../utils/concatPath");
|
|
|
5
5
|
class JsonOperationRoute {
|
|
6
6
|
constructor(options) {
|
|
7
7
|
Object.assign(this, options);
|
|
8
|
+
this.paramsTypes = [...this.endpoint.children.values()].reduce((obj, item) => ({
|
|
9
|
+
...obj,
|
|
10
|
+
[item.paramType]: true
|
|
11
|
+
}), {});
|
|
8
12
|
}
|
|
9
13
|
get url() {
|
|
10
14
|
return this.fullPath;
|
|
@@ -51,6 +55,9 @@ class JsonOperationRoute {
|
|
|
51
55
|
get operationId() {
|
|
52
56
|
return this.operation.get("operationId") || this.endpoint.propertyKey;
|
|
53
57
|
}
|
|
58
|
+
has(key) {
|
|
59
|
+
return this.paramsTypes[key];
|
|
60
|
+
}
|
|
54
61
|
}
|
|
55
62
|
exports.JsonOperationRoute = JsonOperationRoute;
|
|
56
63
|
//# sourceMappingURL=JsonOperationRoute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonOperationRoute.js","sourceRoot":"","sources":["../../../src/domain/JsonOperationRoute.ts"],"names":[],"mappings":";;;AAGA,oDAA+C;AAE/C,MAAa,kBAAkB;
|
|
1
|
+
{"version":3,"file":"JsonOperationRoute.js","sourceRoot":"","sources":["../../../src/domain/JsonOperationRoute.ts"],"names":[],"mappings":";;;AAGA,oDAA+C;AAE/C,MAAa,kBAAkB;IAO7B,YAAY,OAAoC;QAC9C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE7B,IAAI,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAA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C,KAAK,CAAC;IAC7B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,QAAQ,CAAC,SAA0B,CAAC;IAClD,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;IACxE,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACF;AA9ED,gDA8EC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JsonMethodStore} from \"./JsonMethodStore\";\nimport {JsonMethodPath, JsonOperation} from \"./JsonOperation\";\nimport {concatPath} from \"../utils/concatPath\";\n\nexport class JsonOperationRoute<Entity extends JsonMethodStore = JsonMethodStore> {\n readonly token: Type<any>;\n readonly endpoint: Entity;\n readonly operationPath?: JsonMethodPath;\n readonly basePath?: string;\n readonly paramsTypes: Record<string, boolean>;\n\n constructor(options: Partial<JsonOperationRoute>) {\n Object.assign(this, options);\n\n this.paramsTypes = [...this.endpoint.children.values()].reduce(\n (obj, item) => ({\n ...obj,\n [item.paramType]: true\n }),\n {}\n );\n }\n\n get url() {\n return this.fullPath;\n }\n\n get path() {\n return this.operationPath?.path;\n }\n\n get fullPath() {\n return concatPath(this.basePath, this.path as any);\n }\n\n get method() {\n return this.operationPath?.method || \"USE\";\n }\n\n get isFinal() {\n return !!this.operationPath?.isFinal;\n }\n\n get name() {\n return `${this.endpoint.targetName}.${this.methodClassName}()`;\n }\n\n get className() {\n return this.endpoint.targetName;\n }\n\n get methodClassName() {\n return this.propertyKey;\n }\n\n get parameters() {\n return this.endpoint.parameters;\n }\n\n get propertyKey() {\n return String(this.endpoint.propertyKey);\n }\n\n get propertyName() {\n return this.endpoint.propertyName;\n }\n\n get store() {\n return this.endpoint.store;\n }\n\n get operation(): JsonOperation {\n return this.endpoint.operation as JsonOperation;\n }\n\n get operationId() {\n return this.operation.get(\"operationId\") || this.endpoint.propertyKey;\n }\n\n has(key: string) {\n return this.paramsTypes[key];\n }\n}\n"]}
|
|
@@ -7,6 +7,7 @@ const generics_1 = require("../utils/generics");
|
|
|
7
7
|
const JsonMap_1 = require("./JsonMap");
|
|
8
8
|
const JsonParameterTypes_1 = require("./JsonParameterTypes");
|
|
9
9
|
const SpecTypes_1 = require("./SpecTypes");
|
|
10
|
+
const ref_1 = require("../utils/ref");
|
|
10
11
|
const IGNORE_OS2_PROPS = ["example", "examples", "title"];
|
|
11
12
|
class JsonParameter extends JsonMap_1.JsonMap {
|
|
12
13
|
constructor() {
|
|
@@ -122,8 +123,9 @@ class JsonParameter extends JsonMap_1.JsonMap {
|
|
|
122
123
|
return parameter;
|
|
123
124
|
}
|
|
124
125
|
refToParameters(parameter, options, schemasContainer) {
|
|
125
|
-
const
|
|
126
|
-
|
|
126
|
+
const name = (0, ref_1.createRefName)(this.$schema.getName(), options);
|
|
127
|
+
const schema = options.schemas[name];
|
|
128
|
+
if (options.schemas[name] && !schemasContainer.has(name)) {
|
|
127
129
|
delete options.schemas[this.$schema.getName()];
|
|
128
130
|
}
|
|
129
131
|
return Object.entries(schema.properties || {}).reduce((params, [key, { description, ...prop }]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonParameter.js","sourceRoot":"","sources":["../../../src/domain/JsonParameter.ts"],"names":[],"mappings":";;;AAAA,qCAAoD;AAGpD,uFAAmE;AACnE,gDAA8D;AAC9D,uCAAkC;AAClC,6DAA8F;AAE9F,2CAAsC;AAEtC,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAE1D,MAAa,aAAc,SAAQ,iBAAiC;IAApE;;QACE,mBAAc,GAAkB,EAAE,CAAC;IA0LrC,CAAC;IArLC,OAAO;QACL,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAE9B,IAAI,IAAI,C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H,CAAC;aACH;YAED,OAAO;gBACL,GAAG,MAAM;gBACT,IAAA,kBAAW,EAAC;oBACV,GAAG,SAAS;oBACZ,IAAI,EAAE,GAAG;oBACT,QAAQ,EAAE,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;oBAC/C,WAAW;oBACX,GAAG,IAAI;iBACR,CAAC;aACH,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF;AA3LD,sCA2LC","sourcesContent":["import {cleanObject, toMap, Type} from \"@tsed/core\";\nimport {OpenSpecHash, OpenSpecRef, OS2Schema, OS3Example, OS3Parameter, OS3Schema} from \"@tsed/openspec\";\nimport {JsonSchemaOptions} from \"../interfaces\";\nimport {execMapper} from \"../registries/JsonSchemaMapperContainer\";\nimport {NestedGenerics, popGenerics} from \"../utils/generics\";\nimport {JsonMap} from \"./JsonMap\";\nimport {formatParameterType, isParameterType, JsonParameterTypes} from \"./JsonParameterTypes\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport {SpecTypes} from \"./SpecTypes\";\n\nconst IGNORE_OS2_PROPS = [\"example\", \"examples\", \"title\"];\n\nexport class JsonParameter extends JsonMap<OS3Parameter<JsonSchema>> implements NestedGenerics {\n nestedGenerics: Type<any>[][] = [];\n groups: string[];\n $schema: JsonSchema;\n expression: string;\n\n getName() {\n const name = this.get(\"name\");\n\n if (this.get(\"in\") === \"files\") {\n return name.split(\".\")[0];\n }\n\n return name;\n }\n\n name(name: string): this {\n this.set(\"name\", name);\n\n return this;\n }\n\n examples(examples: OpenSpecHash<OS3Example | OpenSpecRef>) {\n super.set(\"examples\", examples);\n\n return this;\n }\n\n description(description: string): this {\n this.set(\"description\", description);\n\n return this;\n }\n\n in(inType: string, expression: string | any = \"\"): this {\n this.set(\"in\", formatParameterType(inType));\n this.expression = expression;\n\n return this;\n }\n\n required(required: boolean): this {\n this.set(\"required\", required);\n\n return this;\n }\n\n schema(schema: JsonSchema): this {\n this.$schema = schema;\n\n return this;\n }\n\n toJSON(options: JsonSchemaOptions = {}) {\n if (!isParameterType(this.get(\"in\"))) {\n return null;\n }\n\n const schemasContainer = toMap<string, OS2Schema | OS3Schema>(options.schemas || {});\n\n return this.build({...options, groups: this.groups}, schemasContainer);\n }\n\n private build(options: JsonSchemaOptions, schemasContainer: Map<string, OS3Schema | OS2Schema>) {\n const {type, schema, ...parameter} = super.toJSON(options);\n\n const jsonSchema = execMapper(\"item\", this.$schema, {\n ...options,\n ...popGenerics(this)\n });\n\n parameter.required = parameter.required || this.get(\"in\") === JsonParameterTypes.PATH;\n\n if (this.get(\"in\") === JsonParameterTypes.FILES) {\n const isOpenApi = options.specType === SpecTypes.OPENAPI;\n\n const schema = {\n type: isOpenApi ? \"string\" : \"file\",\n format: isOpenApi ? \"binary\" : undefined,\n oneOf: undefined\n };\n\n if (jsonSchema.type === \"array\") {\n jsonSchema.items = cleanObject({\n ...jsonSchema.items,\n ...schema\n });\n\n parameter.schema = jsonSchema;\n } else {\n parameter.schema = cleanObject({\n ...jsonSchema,\n ...schema\n });\n }\n\n return parameter;\n }\n\n if (options.specType === SpecTypes.OPENAPI) {\n if ([\"query\"].includes(this.get(\"in\")) && jsonSchema.$ref) {\n if (!parameter.name) {\n return this.refToParameters(parameter, options, schemasContainer);\n }\n\n parameter.style = \"deepObject\";\n }\n }\n\n if (options.specType === SpecTypes.SWAGGER) {\n if (!jsonSchema.$ref && Object.keys(jsonSchema).length === 1) {\n parameter.type = jsonSchema.type;\n return parameter;\n }\n\n if ([\"formData\", \"query\"].includes(this.get(\"in\"))) {\n if (jsonSchema.$ref) {\n return this.refToParameters(parameter, options, schemasContainer);\n }\n\n if (jsonSchema.type === \"array\") {\n const {minLength, ...props} = jsonSchema;\n return cleanObject(\n {\n ...parameter,\n ...props,\n type: \"array\",\n collectionFormat: \"multi\",\n items: {\n type: \"string\"\n }\n },\n IGNORE_OS2_PROPS\n );\n }\n }\n\n if (this.get(\"in\") !== \"body\") {\n return cleanObject(\n {\n ...parameter,\n ...jsonSchema\n },\n IGNORE_OS2_PROPS\n );\n }\n }\n\n parameter.schema = jsonSchema;\n\n return parameter;\n }\n\n private refToParameters(parameter: any, options: JsonSchemaOptions, schemasContainer: Map<string, OS3Schema | OS2Schema>) {\n const schema = options.schemas![this.$schema.getName()];\n\n if (options.schemas![this.$schema.getName()] && !schemasContainer.has(this.$schema.getName())) {\n delete options.schemas![this.$schema.getName()];\n }\n\n return Object.entries(schema.properties || {}).reduce((params, [key, {description, ...prop}]: [string, any]) => {\n if (options.specType === SpecTypes.OPENAPI) {\n return [\n ...params,\n cleanObject({\n ...parameter,\n name: key,\n required: (schema.required || []).includes(key),\n description,\n schema: prop,\n style: prop.$ref ? \"deepObject\" : undefined\n })\n ];\n }\n\n return [\n ...params,\n cleanObject({\n ...parameter,\n name: key,\n required: (schema.required || []).includes(key),\n description,\n ...prop\n })\n ];\n }, []);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"JsonParameter.js","sourceRoot":"","sources":["../../../src/domain/JsonParameter.ts"],"names":[],"mappings":";;;AAAA,qCAAoD;AAGpD,uFAAmE;AACnE,gDAA8D;AAC9D,uCAAkC;AAClC,6DAA8F;AAE9F,2CAAsC;AACtC,sCAA2C;AAE3C,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAE1D,MAAa,aAAc,SAAQ,iBAAiC;IAApE;;QACE,mBAAc,GAAkB,EAAE,CAAC;IA2LrC,CAAC;IAtLC,OAAO;QACL,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAE9B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,OAAO,EAAE;YAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3B;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,IAAY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AAC,CAAC,QAAQ,CAAC,GAAG,CAAC;oBAC/C,WAAW;oBACX,GAAG,IAAI;iBACR,CAAC;aACH,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF;AA5LD,sCA4LC","sourcesContent":["import {cleanObject, toMap, Type} from \"@tsed/core\";\nimport {OpenSpecHash, OpenSpecRef, OS2Schema, OS3Example, OS3Parameter, OS3Schema} from \"@tsed/openspec\";\nimport {JsonSchemaOptions} from \"../interfaces\";\nimport {execMapper} from \"../registries/JsonSchemaMapperContainer\";\nimport {NestedGenerics, popGenerics} from \"../utils/generics\";\nimport {JsonMap} from \"./JsonMap\";\nimport {formatParameterType, isParameterType, JsonParameterTypes} from \"./JsonParameterTypes\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport {SpecTypes} from \"./SpecTypes\";\nimport {createRefName} from \"../utils/ref\";\n\nconst IGNORE_OS2_PROPS = [\"example\", \"examples\", \"title\"];\n\nexport class JsonParameter extends JsonMap<OS3Parameter<JsonSchema>> implements NestedGenerics {\n nestedGenerics: Type<any>[][] = [];\n groups: string[];\n $schema: JsonSchema;\n expression: string;\n\n getName() {\n const name = this.get(\"name\");\n\n if (this.get(\"in\") === \"files\") {\n return name.split(\".\")[0];\n }\n\n return name;\n }\n\n name(name: string): this {\n this.set(\"name\", name);\n\n return this;\n }\n\n examples(examples: OpenSpecHash<OS3Example | OpenSpecRef>) {\n super.set(\"examples\", examples);\n\n return this;\n }\n\n description(description: string): this {\n this.set(\"description\", description);\n\n return this;\n }\n\n in(inType: string, expression: string | any = \"\"): this {\n this.set(\"in\", formatParameterType(inType));\n this.expression = expression;\n\n return this;\n }\n\n required(required: boolean): this {\n this.set(\"required\", required);\n\n return this;\n }\n\n schema(schema: JsonSchema): this {\n this.$schema = schema;\n\n return this;\n }\n\n toJSON(options: JsonSchemaOptions = {}) {\n if (!isParameterType(this.get(\"in\"))) {\n return null;\n }\n\n const schemasContainer = toMap<string, OS2Schema | OS3Schema>(options.schemas || {});\n\n return this.build({...options, groups: this.groups}, schemasContainer);\n }\n\n private build(options: JsonSchemaOptions, schemasContainer: Map<string, OS3Schema | OS2Schema>) {\n const {type, schema, ...parameter} = super.toJSON(options);\n\n const jsonSchema = execMapper(\"item\", this.$schema, {\n ...options,\n ...popGenerics(this)\n });\n\n parameter.required = parameter.required || this.get(\"in\") === JsonParameterTypes.PATH;\n\n if (this.get(\"in\") === JsonParameterTypes.FILES) {\n const isOpenApi = options.specType === SpecTypes.OPENAPI;\n\n const schema = {\n type: isOpenApi ? \"string\" : \"file\",\n format: isOpenApi ? \"binary\" : undefined,\n oneOf: undefined\n };\n\n if (jsonSchema.type === \"array\") {\n jsonSchema.items = cleanObject({\n ...jsonSchema.items,\n ...schema\n });\n\n parameter.schema = jsonSchema;\n } else {\n parameter.schema = cleanObject({\n ...jsonSchema,\n ...schema\n });\n }\n\n return parameter;\n }\n\n if (options.specType === SpecTypes.OPENAPI) {\n if ([\"query\"].includes(this.get(\"in\")) && jsonSchema.$ref) {\n if (!parameter.name) {\n return this.refToParameters(parameter, options, schemasContainer);\n }\n\n parameter.style = \"deepObject\";\n }\n }\n\n if (options.specType === SpecTypes.SWAGGER) {\n if (!jsonSchema.$ref && Object.keys(jsonSchema).length === 1) {\n parameter.type = jsonSchema.type;\n return parameter;\n }\n\n if ([\"formData\", \"query\"].includes(this.get(\"in\"))) {\n if (jsonSchema.$ref) {\n return this.refToParameters(parameter, options, schemasContainer);\n }\n\n if (jsonSchema.type === \"array\") {\n const {minLength, ...props} = jsonSchema;\n return cleanObject(\n {\n ...parameter,\n ...props,\n type: \"array\",\n collectionFormat: \"multi\",\n items: {\n type: \"string\"\n }\n },\n IGNORE_OS2_PROPS\n );\n }\n }\n\n if (this.get(\"in\") !== \"body\") {\n return cleanObject(\n {\n ...parameter,\n ...jsonSchema\n },\n IGNORE_OS2_PROPS\n );\n }\n }\n\n parameter.schema = jsonSchema;\n\n return parameter;\n }\n\n private refToParameters(parameter: any, options: JsonSchemaOptions, schemasContainer: Map<string, OS3Schema | OS2Schema>) {\n const name = createRefName(this.$schema.getName(), options);\n const schema = options.schemas![name];\n\n if (options.schemas![name] && !schemasContainer.has(name)) {\n delete options.schemas![this.$schema.getName()];\n }\n\n return Object.entries(schema.properties || {}).reduce((params, [key, {description, ...prop}]: [string, any]) => {\n if (options.specType === SpecTypes.OPENAPI) {\n return [\n ...params,\n cleanObject({\n ...parameter,\n name: key,\n required: (schema.required || []).includes(key),\n description,\n schema: prop,\n style: prop.$ref ? \"deepObject\" : undefined\n })\n ];\n }\n\n return [\n ...params,\n cleanObject({\n ...parameter,\n name: key,\n required: (schema.required || []).includes(key),\n description,\n ...prop\n })\n ];\n }, []);\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JsonParameterStore = void 0;
|
|
3
|
+
exports.ParamMetadata = exports.JsonParameterStore = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@tsed/core");
|
|
6
6
|
const JsonEntityStore_1 = require("./JsonEntityStore");
|
|
@@ -8,13 +8,17 @@ const JsonParameter_1 = require("./JsonParameter");
|
|
|
8
8
|
const JsonSchema_1 = require("./JsonSchema");
|
|
9
9
|
const jsonEntityComponent_1 = require("../decorators/config/jsonEntityComponent");
|
|
10
10
|
let JsonParameterStore = class JsonParameterStore extends JsonEntityStore_1.JsonEntityStore {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super(options);
|
|
13
13
|
/**
|
|
14
14
|
* Ref to JsonParameter when the decorated object is a parameter.
|
|
15
15
|
*/
|
|
16
16
|
this.parameter = new JsonParameter_1.JsonParameter();
|
|
17
17
|
this.parent = JsonEntityStore_1.JsonEntityStore.fromMethod(this.target, this.propertyKey);
|
|
18
|
+
this.pipes = options.pipes || [];
|
|
19
|
+
this.paramType = options.paramType || this.paramType;
|
|
20
|
+
this.expression = options.expression || this.expression;
|
|
21
|
+
this.dataPath = options.dataPath || this.dataPath;
|
|
18
22
|
}
|
|
19
23
|
get nestedGenerics() {
|
|
20
24
|
return this.parameter.nestedGenerics;
|
|
@@ -50,6 +54,9 @@ let JsonParameterStore = class JsonParameterStore extends JsonEntityStore_1.Json
|
|
|
50
54
|
}
|
|
51
55
|
return [];
|
|
52
56
|
}
|
|
57
|
+
static get(target, propertyKey, index) {
|
|
58
|
+
return JsonEntityStore_1.JsonEntityStore.from((0, core_1.prototypeOf)(target), propertyKey, index);
|
|
59
|
+
}
|
|
53
60
|
/**
|
|
54
61
|
* Check precondition between value, required and allowedRequiredValues to know if the entity is required.
|
|
55
62
|
* @param value
|
|
@@ -84,7 +91,9 @@ let JsonParameterStore = class JsonParameterStore extends JsonEntityStore_1.Json
|
|
|
84
91
|
}
|
|
85
92
|
};
|
|
86
93
|
JsonParameterStore = (0, tslib_1.__decorate)([
|
|
87
|
-
(0, jsonEntityComponent_1.JsonEntityComponent)(core_1.DecoratorTypes.PARAM)
|
|
94
|
+
(0, jsonEntityComponent_1.JsonEntityComponent)(core_1.DecoratorTypes.PARAM),
|
|
95
|
+
(0, tslib_1.__metadata)("design:paramtypes", [Object])
|
|
88
96
|
], JsonParameterStore);
|
|
89
97
|
exports.JsonParameterStore = JsonParameterStore;
|
|
98
|
+
exports.ParamMetadata = JsonParameterStore;
|
|
90
99
|
//# sourceMappingURL=JsonParameterStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonParameterStore.js","sourceRoot":"","sources":["../../../src/domain/JsonParameterStore.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"JsonParameterStore.js","sourceRoot":"","sources":["../../../src/domain/JsonParameterStore.ts"],"names":[],"mappings":";;;;AAAA,qCAA+H;AAC/H,uDAA0E;AAE1E,mDAA8C;AAC9C,6CAAwC;AACxC,kFAA6E;AAa7E,IAAa,kB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GAAQ,eAAQ,CAAC,aAAa,CAAC,IAAA,kBAAW,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAM,CAAC,CAAC;YAElG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SACtB;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC;QAElC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAM,EAAE,IAAI,CAAC,CAAC;YAE5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;YAEhE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEpC,IAAI,IAAI,CAAC,cAAc,EAAE;gBACvB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;aACpD;YAED,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,KAAe,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;SAC1E;IACH,CAAC;CACF,CAAA;AAhHY,kBAAkB;IAD9B,IAAA,yCAAmB,EAAC,qBAAc,CAAC,KAAK,CAAC;;GAC7B,kBAAkB,CAgH9B;AAhHY,gDAAkB;AAsHlB,QAAA,aAAa,GAAG,kBAAkB,CAAC","sourcesContent":["import {ancestorsOf, DecoratorTypes, isClass, isCollection, isMethodDescriptor, Metadata, prototypeOf, Type} from \"@tsed/core\";\nimport {JsonEntityStore, JsonEntityStoreOptions} from \"./JsonEntityStore\";\nimport type {JsonMethodStore} from \"./JsonMethodStore\";\nimport {JsonParameter} from \"./JsonParameter\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport {JsonEntityComponent} from \"../decorators/config/jsonEntityComponent\";\n\nexport interface JsonParameterStoreOptions extends JsonEntityStoreOptions {\n dataPath?: string;\n paramType?: string;\n expression?: string;\n}\n\nexport interface PipeMethods<T = any, R = any> {\n transform(value: T, metadata: JsonParameterStore): R;\n}\n\n@JsonEntityComponent(DecoratorTypes.PARAM)\nexport class JsonParameterStore extends JsonEntityStore {\n public paramType: string;\n public expression: string;\n public dataPath: string;\n /**\n * Define pipes can be called by the framework to transform input parameter\n */\n public pipes: Type<PipeMethods>[];\n /**\n * Ref to JsonParameter when the decorated object is a parameter.\n */\n readonly parameter: JsonParameter = new JsonParameter();\n readonly parent: JsonMethodStore = JsonEntityStore.fromMethod(this.target, this.propertyKey);\n\n constructor(options: JsonParameterStoreOptions) {\n super(options);\n this.pipes = options.pipes || [];\n this.paramType = options.paramType || this.paramType;\n this.expression = options.expression || this.expression;\n this.dataPath = options.dataPath || this.dataPath;\n }\n\n get nestedGenerics(): Type<any>[][] {\n return this.parameter.nestedGenerics;\n }\n\n set nestedGenerics(nestedGenerics: Type<any>[][]) {\n this.parameter.nestedGenerics = nestedGenerics;\n }\n\n /**\n * Return the required state.\n * @returns {boolean}\n */\n get required(): boolean {\n return !!this.parameter.get(\"required\");\n }\n\n set required(value: boolean) {\n this.parameter.required(value);\n }\n\n get allowedRequiredValues() {\n return this.schema.$allow;\n }\n\n static getParams<T extends JsonParameterStore = JsonParameterStore>(target: Type<any>, propertyKey: string | symbol): T[] {\n const params: T[] = [];\n\n const klass = ancestorsOf(target)\n .reverse()\n .find((target) => {\n return isMethodDescriptor(target, propertyKey) && JsonEntityStore.fromMethod(target, propertyKey).children.size;\n });\n\n if (klass) {\n JsonEntityStore.fromMethod(klass, propertyKey).children.forEach((param: T, index) => {\n params[+index] = param;\n });\n\n return params;\n }\n\n return [];\n }\n\n static get(target: Type<any>, propertyKey: string | symbol, index: number) {\n return JsonEntityStore.from<JsonParameterStore>(prototypeOf(target), propertyKey, index);\n }\n\n /**\n * Check precondition between value, required and allowedRequiredValues to know if the entity is required.\n * @param value\n * @returns {boolean}\n */\n isRequired(value: any): boolean {\n return this.required && [undefined, null, \"\"].includes(value) && !this.allowedRequiredValues.includes(value);\n }\n\n protected getSchema(type: any) {\n if (isCollection(type) || !isClass(type)) {\n return JsonSchema.from({\n type\n });\n }\n\n return JsonEntityStore.from(type).schema;\n }\n\n protected build() {\n if (!this._type) {\n const type: any = Metadata.getParamTypes(prototypeOf(this.target), this.propertyKey)[this.index!];\n\n this.buildType(type);\n }\n\n this._type = this._type || Object;\n\n if (!this._schema) {\n this.parent.children.set(this.index!, this);\n\n this._schema = this.getSchema(this.collectionType || this.type);\n\n this.parameter.schema(this._schema);\n\n if (this.collectionType) {\n this._schema.itemSchema(this.getSchema(this.type));\n }\n\n this.parent.operation.addParameter(this.index as number, this.parameter);\n }\n }\n}\n\n/**\n * @alias JsonParameterStore\n */\nexport type ParamMetadata = JsonParameterStore;\nexport const ParamMetadata = JsonParameterStore;\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JsonPropertyStore = void 0;
|
|
3
|
+
exports.PropertyMetadata = exports.JsonPropertyStore = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@tsed/core");
|
|
6
6
|
const JsonEntityStore_1 = require("./JsonEntityStore");
|
|
@@ -60,9 +60,13 @@ let JsonPropertyStore = class JsonPropertyStore extends JsonEntityStore_1.JsonEn
|
|
|
60
60
|
this.parent.schema.addProperty(this.propertyName, schema);
|
|
61
61
|
this._schema = schema;
|
|
62
62
|
}
|
|
63
|
+
static get(target, propertyKey) {
|
|
64
|
+
return JsonEntityStore_1.JsonEntityStore.from((0, core_1.prototypeOf)(target), propertyKey);
|
|
65
|
+
}
|
|
63
66
|
};
|
|
64
67
|
JsonPropertyStore = (0, tslib_1.__decorate)([
|
|
65
68
|
(0, jsonEntityComponent_1.JsonEntityComponent)(core_1.DecoratorTypes.PROP)
|
|
66
69
|
], JsonPropertyStore);
|
|
67
70
|
exports.JsonPropertyStore = JsonPropertyStore;
|
|
71
|
+
exports.PropertyMetadata = JsonPropertyStore;
|
|
68
72
|
//# sourceMappingURL=JsonPropertyStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonPropertyStore.js","sourceRoot":"","sources":["../../../src/domain/JsonPropertyStore.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"JsonPropertyStore.js","sourceRoot":"","sources":["../../../src/domain/JsonPropertyStore.ts"],"names":[],"mappings":";;;;AAAA,qCAAuE;AACvE,uDAAkD;AAClD,6CAAwC;AACxC,kFAA6E;AAI7E,IAAa,iBAAiB,GAA9B,MAAa,iBAAkB,SAAQ,iCAAe;IAAtD;;QACW,WAAM,GAAmB,iCAAe,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAkEtE,CAAC;IAhEC;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,WAAqB,CAAC,CAAC;IACnE,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ,CAAC,KAAc;QACzB,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,WAAqB,CAAC,CAAC;SAC5D;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,WAAqB,CAAC,CAAC;SAC/D;IACH,CAAC;IAED,IAAI,qBAAqB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,KAAU;QACnB,OAAO,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,EAAE,IAAI,EA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,iBAAiB;IAD7B,IAAA,yCAAmB,EAAC,qBAAc,CAAC,IAAI,CAAC;GAC5B,iBAAiB,CAmE7B;AAnEY,8CAAiB;AAyEjB,QAAA,gBAAgB,GAAG,iBAAiB,CAAC","sourcesContent":["import {DecoratorTypes, Metadata, prototypeOf, Type} from \"@tsed/core\";\nimport {JsonEntityStore} from \"./JsonEntityStore\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport {JsonEntityComponent} from \"../decorators/config/jsonEntityComponent\";\nimport type {JsonClassStore} from \"./JsonClassStore\";\n\n@JsonEntityComponent(DecoratorTypes.PROP)\nexport class JsonPropertyStore extends JsonEntityStore {\n readonly parent: JsonClassStore = JsonEntityStore.from(this.target);\n\n /**\n * Return the required state.\n * @returns {boolean}\n */\n get required(): boolean {\n return this.parent.schema.isRequired(this.propertyKey as string);\n }\n\n /**\n * Change the state of the required data.\n * @param value\n */\n set required(value: boolean) {\n if (value) {\n this.parent.schema.addRequired(this.propertyKey as string);\n } else {\n this.parent.schema.removeRequired(this.propertyKey as string);\n }\n }\n\n get allowedRequiredValues() {\n return this.schema.$allow;\n }\n\n /**\n * Check precondition between value, required and allowedRequiredValues to know if the entity is required.\n * @param value\n * @returns {boolean}\n */\n isRequired(value: any): boolean {\n return this.required && [undefined, null, \"\"].includes(value) && !this.allowedRequiredValues.includes(value);\n }\n\n protected build() {\n if (!this._type) {\n this.buildType(Metadata.getType(prototypeOf(this.target), this.propertyKey));\n }\n\n this._type = this._type || Object;\n\n const properties = this.parent.schema.get(\"properties\");\n\n let schema: JsonSchema = properties[this.propertyName];\n\n if (!schema) {\n this.parent.children.set(this.propertyName, this);\n\n schema = JsonSchema.from({\n type: this.collectionType || this.type\n });\n\n if (this.collectionType) {\n schema.itemSchema(this.type);\n }\n }\n\n this.parent.schema.addProperty(this.propertyName, schema);\n\n this._schema = schema;\n }\n\n static get(target: Type<any>, propertyKey: string | symbol) {\n return JsonEntityStore.from<JsonPropertyStore>(prototypeOf(target), propertyKey);\n }\n}\n\n/**\n * @alias JsonPropertyStore\n */\nexport type PropertyMetadata = JsonPropertyStore;\nexport const PropertyMetadata = JsonPropertyStore;\n"]}
|
|
@@ -9,6 +9,7 @@ const getComputedType_1 = require("../utils/getComputedType");
|
|
|
9
9
|
const getJsonType_1 = require("../utils/getJsonType");
|
|
10
10
|
const toJsonRegex_1 = require("../utils/toJsonRegex");
|
|
11
11
|
const JsonEntityStore_1 = require("./JsonEntityStore");
|
|
12
|
+
const serializeEnumValues_1 = require("../utils/serializeEnumValues");
|
|
12
13
|
function mapProperties(properties) {
|
|
13
14
|
// istanbul ignore next
|
|
14
15
|
if (properties instanceof JsonSchema) {
|
|
@@ -394,17 +395,9 @@ class JsonSchema extends Map {
|
|
|
394
395
|
super.set("propertyNames", mapToJsonSchema(propertyNames));
|
|
395
396
|
return this;
|
|
396
397
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
* the array represents a possible value for the instance value. If
|
|
401
|
-
* this attribute is defined, the instance value MUST be one of the
|
|
402
|
-
* values in the array in order for the schema to be valid.
|
|
403
|
-
*
|
|
404
|
-
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.23
|
|
405
|
-
*/
|
|
406
|
-
enum(enumValues) {
|
|
407
|
-
super.set("enum", (0, core_1.uniq)(enumValues));
|
|
398
|
+
enum(enumValue, ...enumValues) {
|
|
399
|
+
const { values, types } = (0, serializeEnumValues_1.serializeEnumValues)([enumValue, enumValues].flat());
|
|
400
|
+
super.set("enum", values).any(...types);
|
|
408
401
|
return this;
|
|
409
402
|
}
|
|
410
403
|
/**
|