@tsed/schema 6.97.1 → 6.98.2
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/jest.config.js +14 -0
- 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/SpecTypes.js +3 -0
- package/lib/cjs/domain/SpecTypes.js.map +1 -1
- package/lib/cjs/utils/getOperationsRoutes.js.map +1 -1
- package/lib/cjs/utils/getSpec.js +3 -3
- package/lib/cjs/utils/getSpec.js.map +1 -1
- package/lib/cjs/utils/mapNullableType.js +1 -1
- package/lib/cjs/utils/mapNullableType.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/SpecTypes.js +3 -0
- package/lib/esm/domain/SpecTypes.js.map +1 -1
- package/lib/esm/utils/getOperationsRoutes.js.map +1 -1
- package/lib/esm/utils/getSpec.js +3 -3
- package/lib/esm/utils/getSpec.js.map +1 -1
- package/lib/esm/utils/mapNullableType.js +1 -1
- package/lib/esm/utils/mapNullableType.js.map +1 -1
- 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/SpecTypes.d.ts +3 -0
- package/lib/types/utils/getOperationsRoutes.d.ts +2 -2
- package/lib/types/utils/mapNullableType.d.ts +1 -1
- package/package.json +7 -7
- package/.mocharc.js +0 -5
- package/.nycrc +0 -27
|
@@ -14,6 +14,7 @@ export * from "./generics/genericOf";
|
|
|
14
14
|
// operations
|
|
15
15
|
export * from "./operations/deprecated";
|
|
16
16
|
export * from "./operations/consumes";
|
|
17
|
+
export * from "./operations/view";
|
|
17
18
|
export * from "./operations/contentType";
|
|
18
19
|
export * from "./operations/in";
|
|
19
20
|
export * from "./operations/inFile";
|
|
@@ -31,6 +32,7 @@ export * from "./operations/partial";
|
|
|
31
32
|
export * from "./operations/redirect";
|
|
32
33
|
export * from "./operations/location";
|
|
33
34
|
export * from "./operations/route";
|
|
35
|
+
export * from "./operations/acceptMime";
|
|
34
36
|
// common
|
|
35
37
|
export * from "./common/additionalProperties";
|
|
36
38
|
export * from "./common/allow";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,cAAc;AACd,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAE5C,WAAW;AACX,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AAErC,aAAa;AACb,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,cAAc;AACd,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BA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AkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC","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,24 @@
|
|
|
1
|
+
import { StoreSet, useDecorators } from "@tsed/core";
|
|
2
|
+
import { Produces } from "./produces";
|
|
3
|
+
/**
|
|
4
|
+
* 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.
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @Controller('/mypath')
|
|
8
|
+
* export class MyCtrl {
|
|
9
|
+
*
|
|
10
|
+
* @Get('/')
|
|
11
|
+
* @AcceptMime('application/json')
|
|
12
|
+
* public getResource(){}
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param mimes
|
|
17
|
+
* @decorator
|
|
18
|
+
* @operation
|
|
19
|
+
* @response
|
|
20
|
+
*/
|
|
21
|
+
export function AcceptMime(...mimes) {
|
|
22
|
+
return useDecorators(Produces(...mimes), StoreSet("acceptMimes", mimes));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=acceptMime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acceptMime.js","sourceRoot":"","sources":["../../../../src/decorators/operations/acceptMime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACnD,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,UAAU,CAAC,GAAG,KAAe;IAC3C,OAAO,aAAa,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,EAAE,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC;AAC3E,CAAC","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,27 @@
|
|
|
1
|
+
import { StoreSet } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
* Use a view and sends the rendered HTML string to the client. Optional parameter:
|
|
4
|
+
*
|
|
5
|
+
* * viewOptions, an object whose properties define local variables for the view.
|
|
6
|
+
*
|
|
7
|
+
* The view argument is a string that is the file path of the view file to render.
|
|
8
|
+
* This can be an absolute path, or a path relative to the views setting.
|
|
9
|
+
* If the path does not contain a file extension, then the view engine setting determines the file extension.
|
|
10
|
+
* If the path does contain a file extension, then Express will load the module for the specified template engine (via require())
|
|
11
|
+
* and render it using the loaded module’s __express function.
|
|
12
|
+
*
|
|
13
|
+
* For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).
|
|
14
|
+
*
|
|
15
|
+
* > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,
|
|
16
|
+
* and as so for security reasons should not contain input from the end-user.
|
|
17
|
+
*
|
|
18
|
+
* @param path Relative path to the view file.
|
|
19
|
+
* @param options Additional options
|
|
20
|
+
* @decorator
|
|
21
|
+
* @operation
|
|
22
|
+
* @response
|
|
23
|
+
*/
|
|
24
|
+
export function View(path, options) {
|
|
25
|
+
return StoreSet("view", { path, options });
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../../../src/decorators/operations/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,OAAgB;IACjD,OAAO,QAAQ,CAAC,MAAM,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,CAAQ,CAAC;AAClD,CAAC","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,5 +1,5 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { DecoratorTypes, descriptorOf, isCollection, isFunction, isPromise, Metadata, Store } from "@tsed/core";
|
|
2
|
+
import { DecoratorTypes, deepMerge, descriptorOf, isCollection, isFunction, isPromise, Metadata, prototypeOf, Store } from "@tsed/core";
|
|
3
3
|
import { JsonEntityStore } from "./JsonEntityStore";
|
|
4
4
|
import { JsonOperation } from "./JsonOperation";
|
|
5
5
|
import { JsonSchema } from "./JsonSchema";
|
|
@@ -28,6 +28,21 @@ let JsonMethodStore = class JsonMethodStore extends JsonEntityStore {
|
|
|
28
28
|
this.before(beforeMiddlewares);
|
|
29
29
|
this.use(middlewares);
|
|
30
30
|
}
|
|
31
|
+
get params() {
|
|
32
|
+
return this.parameters;
|
|
33
|
+
}
|
|
34
|
+
get view() {
|
|
35
|
+
return this.store.get("view");
|
|
36
|
+
}
|
|
37
|
+
set view(view) {
|
|
38
|
+
this.store.set("view", view);
|
|
39
|
+
}
|
|
40
|
+
get acceptMimes() {
|
|
41
|
+
return this.store.get("acceptMimes", []);
|
|
42
|
+
}
|
|
43
|
+
set acceptMimes(mimes) {
|
|
44
|
+
this.store.set("acceptMimes", mimes);
|
|
45
|
+
}
|
|
31
46
|
get parameters() {
|
|
32
47
|
return [...this.children.values()];
|
|
33
48
|
}
|
|
@@ -89,10 +104,31 @@ let JsonMethodStore = class JsonMethodStore extends JsonEntityStore {
|
|
|
89
104
|
this.middlewares = this.middlewares.concat(args).filter(isFunction);
|
|
90
105
|
return this;
|
|
91
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Find the value at the controller level. Let this value be extended or overridden by the endpoint itself.
|
|
109
|
+
*
|
|
110
|
+
* @param key
|
|
111
|
+
* @returns {any}
|
|
112
|
+
*/
|
|
113
|
+
get(key) {
|
|
114
|
+
const ctrlValue = Store.from(this.target).get(key);
|
|
115
|
+
return deepMerge(ctrlValue, this.store.get(key));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get an endpoint.
|
|
119
|
+
* @param target
|
|
120
|
+
* @param propertyKey
|
|
121
|
+
* @param descriptor
|
|
122
|
+
*/
|
|
123
|
+
static get(target, propertyKey, descriptor) {
|
|
124
|
+
descriptor = descriptor || descriptorOf(prototypeOf(target), propertyKey);
|
|
125
|
+
return JsonEntityStore.from(prototypeOf(target), propertyKey, descriptor);
|
|
126
|
+
}
|
|
92
127
|
};
|
|
93
128
|
JsonMethodStore = __decorate([
|
|
94
129
|
JsonEntityComponent(DecoratorTypes.METHOD),
|
|
95
130
|
__metadata("design:paramtypes", [Object])
|
|
96
131
|
], JsonMethodStore);
|
|
97
132
|
export { JsonMethodStore };
|
|
133
|
+
export const EndpointMetadata = JsonMethodStore;
|
|
98
134
|
//# sourceMappingURL=JsonMethodStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonMethodStore.js","sourceRoot":"","sources":["../../../src/domain/JsonMethodStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"JsonMethodStore.js","sourceRoot":"","sources":["../../../src/domain/JsonMethodStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAC5I,OAAO,EAAC,eAAe,EAAyB,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAC,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AG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEnD,OAAO,SAAS,CAAI,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,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;QAE1E,OAAO,eAAe,CAAC,IAAI,CAAkB,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IAC7F,CAAC;CACF,CAAA;AAxJY,eAAe;IAD3B,mBAAmB,CAAC,cAAc,CAAC,MAAM,CAAC;;GAC9B,eAAe,CAwJ3B;SAxJY,eAAe;AA6K5B,MAAM,CAAC,MAAM,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"]}
|
|
@@ -2,6 +2,10 @@ import { concatPath } from "../utils/concatPath";
|
|
|
2
2
|
export class JsonOperationRoute {
|
|
3
3
|
constructor(options) {
|
|
4
4
|
Object.assign(this, options);
|
|
5
|
+
this.paramsTypes = [...this.endpoint.children.values()].reduce((obj, item) => ({
|
|
6
|
+
...obj,
|
|
7
|
+
[item.paramType]: true
|
|
8
|
+
}), {});
|
|
5
9
|
}
|
|
6
10
|
get url() {
|
|
7
11
|
return this.fullPath;
|
|
@@ -48,5 +52,8 @@ export class JsonOperationRoute {
|
|
|
48
52
|
get operationId() {
|
|
49
53
|
return this.operation.get("operationId") || this.endpoint.propertyKey;
|
|
50
54
|
}
|
|
55
|
+
has(key) {
|
|
56
|
+
return this.paramsTypes[key];
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
//# sourceMappingURL=JsonOperationRoute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonOperationRoute.js","sourceRoot":"","sources":["../../../src/domain/JsonOperationRoute.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAE/C,MAAM,OAAO,kBAAkB;
|
|
1
|
+
{"version":3,"file":"JsonOperationRoute.js","sourceRoot":"","sources":["../../../src/domain/JsonOperationRoute.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAE/C,MAAM,OAAO,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,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAC5D,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;YACd,GAAG,GAAG;YACN,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI;SACvB,CAAC,EACF,EAAE,CACH,CAAC;IACJ,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,IAAI;;QACN,OAAO,MAAA,IAAI,CAAC,aAAa,0CAAE,IAAI,CAAC;IAClC,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAW,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,MAAM;;QACR,OAAO,CAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,MAAM,KAAI,KAAK,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO;;QACT,OAAO,CAAC,CAAC,CAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,OAAO,CAAA,CAAC;IACvC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,IAAI,CAAC,eAAe,IAAI,CAAC;IACjE,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;IAClC,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;IAClC,CAAC;IAED,IAAI,WAAW;QACb,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IACpC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,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","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"]}
|
|
@@ -4,6 +4,7 @@ import { popGenerics } from "../utils/generics";
|
|
|
4
4
|
import { JsonMap } from "./JsonMap";
|
|
5
5
|
import { formatParameterType, isParameterType, JsonParameterTypes } from "./JsonParameterTypes";
|
|
6
6
|
import { SpecTypes } from "./SpecTypes";
|
|
7
|
+
import { createRefName } from "../utils/ref";
|
|
7
8
|
const IGNORE_OS2_PROPS = ["example", "examples", "title"];
|
|
8
9
|
export class JsonParameter extends JsonMap {
|
|
9
10
|
constructor() {
|
|
@@ -119,8 +120,9 @@ export class JsonParameter extends JsonMap {
|
|
|
119
120
|
return parameter;
|
|
120
121
|
}
|
|
121
122
|
refToParameters(parameter, options, schemasContainer) {
|
|
122
|
-
const
|
|
123
|
-
|
|
123
|
+
const name = createRefName(this.$schema.getName(), options);
|
|
124
|
+
const schema = options.schemas[name];
|
|
125
|
+
if (options.schemas[name] && !schemasContainer.has(name)) {
|
|
124
126
|
delete options.schemas[this.$schema.getName()];
|
|
125
127
|
}
|
|
126
128
|
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,OAAO,EAAC,WAAW,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAGpD,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,CAAC;AACnE,OAAO,EAAiB,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAE1D,MAAM,OAAO,aAAc,SAAQ,OAAiC;IAApE;;QACE,mBAAc,GAAkB,EAAE,CAAC;IA0LrC,CAAC;IArLC,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;QACf,IAAI,CAAC,GAAG,C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CAAC;IACT,CAAC;CACF","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,OAAO,EAAC,WAAW,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAGpD,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,CAAC;AACnE,OAAO,EAAiB,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAE3C,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAE1D,MAAM,OAAO,aAAc,SAAQ,OAAiC;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;QACf,IAAI,CAAC,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E,EAAE,CAAC,CAAC;IACT,CAAC;CACF","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,17 +1,21 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { ancestorsOf, DecoratorTypes, isClass, isCollection, isMethodDescriptor, Metadata, prototypeOf } from "@tsed/core";
|
|
3
3
|
import { JsonEntityStore } from "./JsonEntityStore";
|
|
4
4
|
import { JsonParameter } from "./JsonParameter";
|
|
5
5
|
import { JsonSchema } from "./JsonSchema";
|
|
6
6
|
import { JsonEntityComponent } from "../decorators/config/jsonEntityComponent";
|
|
7
7
|
let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options);
|
|
10
10
|
/**
|
|
11
11
|
* Ref to JsonParameter when the decorated object is a parameter.
|
|
12
12
|
*/
|
|
13
13
|
this.parameter = new JsonParameter();
|
|
14
14
|
this.parent = JsonEntityStore.fromMethod(this.target, this.propertyKey);
|
|
15
|
+
this.pipes = options.pipes || [];
|
|
16
|
+
this.paramType = options.paramType || this.paramType;
|
|
17
|
+
this.expression = options.expression || this.expression;
|
|
18
|
+
this.dataPath = options.dataPath || this.dataPath;
|
|
15
19
|
}
|
|
16
20
|
get nestedGenerics() {
|
|
17
21
|
return this.parameter.nestedGenerics;
|
|
@@ -47,6 +51,9 @@ let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
|
|
|
47
51
|
}
|
|
48
52
|
return [];
|
|
49
53
|
}
|
|
54
|
+
static get(target, propertyKey, index) {
|
|
55
|
+
return JsonEntityStore.from(prototypeOf(target), propertyKey, index);
|
|
56
|
+
}
|
|
50
57
|
/**
|
|
51
58
|
* Check precondition between value, required and allowedRequiredValues to know if the entity is required.
|
|
52
59
|
* @param value
|
|
@@ -81,7 +88,9 @@ let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
|
|
|
81
88
|
}
|
|
82
89
|
};
|
|
83
90
|
JsonParameterStore = __decorate([
|
|
84
|
-
JsonEntityComponent(DecoratorTypes.PARAM)
|
|
91
|
+
JsonEntityComponent(DecoratorTypes.PARAM),
|
|
92
|
+
__metadata("design:paramtypes", [Object])
|
|
85
93
|
], JsonParameterStore);
|
|
86
94
|
export { JsonParameterStore };
|
|
95
|
+
export const ParamMetadata = JsonParameterStore;
|
|
87
96
|
//# sourceMappingURL=JsonParameterStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonParameterStore.js","sourceRoot":"","sources":["../../../src/domain/JsonParameterStore.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"JsonParameterStore.js","sourceRoot":"","sources":["../../../src/domain/JsonParameterStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,WAAW,EAAO,MAAM,YAAY,CAAC;AAC/H,OAAO,EAAC,eAAe,EAAyB,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,mBAAmB,EAAC,MAAM,0CAA0C,CAAC;AAa7E,IAAa,kBAAkB,GAA/B,MAAa,kBAAmB,SAAQ,eAAe;IAcrD,YAAY,OAAkC;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;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AAI,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,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC;;GAC7B,kBAAkB,CAgH9B;SAhHY,kBAAkB;AAsH/B,MAAM,CAAC,MAAM,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"]}
|
|
@@ -57,9 +57,13 @@ let JsonPropertyStore = class JsonPropertyStore extends JsonEntityStore {
|
|
|
57
57
|
this.parent.schema.addProperty(this.propertyName, schema);
|
|
58
58
|
this._schema = schema;
|
|
59
59
|
}
|
|
60
|
+
static get(target, propertyKey) {
|
|
61
|
+
return JsonEntityStore.from(prototypeOf(target), propertyKey);
|
|
62
|
+
}
|
|
60
63
|
};
|
|
61
64
|
JsonPropertyStore = __decorate([
|
|
62
65
|
JsonEntityComponent(DecoratorTypes.PROP)
|
|
63
66
|
], JsonPropertyStore);
|
|
64
67
|
export { JsonPropertyStore };
|
|
68
|
+
export const PropertyMetadata = JsonPropertyStore;
|
|
65
69
|
//# sourceMappingURL=JsonPropertyStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonPropertyStore.js","sourceRoot":"","sources":["../../../src/domain/JsonPropertyStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,cAAc,EAAE,QAAQ,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"JsonPropertyStore.js","sourceRoot":"","sources":["../../../src/domain/JsonPropertyStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,cAAc,EA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AAC,CAAC,CAAC;SAC9E;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC;QAElC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAExD,IAAI,MAAM,GAAe,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAEvD,IAAI,CAAC,MAAM,EAAE;YACX,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YAElD,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC;gBACvB,IAAI,EAAE,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,IAAI;aACvC,CAAC,CAAC;YAEH,IAAI,IAAI,CAAC,cAAc,EAAE;gBACvB,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC9B;SACF;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAE1D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,MAAiB,EAAE,WAA4B;QACxD,OAAO,eAAe,CAAC,IAAI,CAAoB,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;IACnF,CAAC;CACF,CAAA;AAnEY,iBAAiB;IAD7B,mBAAmB,CAAC,cAAc,CAAC,IAAI,CAAC;GAC5B,iBAAiB,CAmE7B;SAnEY,iBAAiB;AAyE9B,MAAM,CAAC,MAAM,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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpecTypes.js","sourceRoot":"","sources":["../../../src/domain/SpecTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"SpecTypes.js","sourceRoot":"","sources":["../../../src/domain/SpecTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,gCAAmB,CAAA;IACnB;;OAEG;IACH,iCAAoB,CAAA;IACpB,iCAAoB,CAAA;AACtB,CAAC,EAPW,SAAS,KAAT,SAAS,QAOpB","sourcesContent":["export enum SpecTypes {\n JSON = \"jsonschema\",\n /**\n * @deprecated\n */\n SWAGGER = \"swagger2\",\n OPENAPI = \"openapi3\"\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOperationsRoutes.js","sourceRoot":"","sources":["../../../src/utils/getOperationsRoutes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getOperationsRoutes.js","sourceRoot":"","sources":["../../../src/utils/getOperationsRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAOxD,MAAM,UAAU,mBAAmB,CACjC,KAAsB,EACtB,UAAsC,EAAE;IAExC,MAAM,KAAK,GAAoB,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACjF,MAAM,QAAQ,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACxF,IAAI,gBAAgB,GAAiC,EAAE,CAAC;IAExD,IAAI,OAAO,CAAC,YAAY,EAAE;QACxB,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAS,qBAAqB,EAAE,EAAE,CAAC,CAAC;QAE9D,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,KAAK,EAAE,EAAE;YAC7D,OAAO,gBAAgB,CAAC,MAAM,CAC5B,mBAAmB,CAAC,KAAK,EAAE;gBACzB,GAAG,OAAO;gBACV,QAAQ;aACT,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,gBAAgB,CAAC,CAAC;KACtB;IAED,OAAO,CAAC,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;QAC1E,MAAM,EAAC,SAAS,EAAC,GAAG,QAAQ,CAAC;QAE7B,IAAI,SAAS,EAAE;YACb,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;gBACjD,MAAM,CAAC,IAAI,CACT,IAAI,kBAAkB,CAAS;oBAC7B,QAAQ;oBACR,KAAK;oBACL,QAAQ;oBACR,aAAa;iBACd,CAAC,CACH,CAAC;YACJ,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,gBAAgB,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JsonMethodStore} from \"../domain/JsonMethodStore\";\nimport {getOperationsStores} from \"./getOperationsStores\";\nimport {JsonOperationRoute} from \"../domain/JsonOperationRoute\";\nimport {JsonEntityStore} from \"../domain/JsonEntityStore\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\n\nexport interface GetOperationsRoutesOptions {\n withChildren?: boolean;\n basePath?: string;\n}\n\nexport function getOperationsRoutes<Entity extends JsonMethodStore = JsonMethodStore>(\n token: Type<any> | any,\n options: GetOperationsRoutesOptions = {}\n): JsonOperationRoute<Entity>[] {\n const store: JsonEntityStore = token.isStore ? token : getJsonEntityStore(token);\n const basePath = ((options.basePath || \"\") + (store.path || \"\")).replace(/\\/\\//gi, \"/\");\n let operationsRoutes: JsonOperationRoute<Entity>[] = [];\n\n if (options.withChildren) {\n const children = store.get<Type[]>(\"childrenControllers\", []);\n\n operationsRoutes = children.reduce((operationsRoutes, token) => {\n return operationsRoutes.concat(\n getOperationsRoutes(token, {\n ...options,\n basePath\n })\n );\n }, operationsRoutes);\n }\n\n return [...getOperationsStores(token).values()].reduce((routes, endpoint) => {\n const {operation} = endpoint;\n\n if (operation) {\n operation.operationPaths.forEach((operationPath) => {\n routes.push(\n new JsonOperationRoute<Entity>({\n basePath,\n token,\n endpoint,\n operationPath\n })\n );\n });\n }\n\n return routes;\n }, operationsRoutes);\n}\n"]}
|
package/lib/esm/utils/getSpec.js
CHANGED
|
@@ -28,9 +28,9 @@ function get(model, options, cb) {
|
|
|
28
28
|
* @param model
|
|
29
29
|
* @param options
|
|
30
30
|
*/
|
|
31
|
-
export function getSpec(model, options = {
|
|
31
|
+
export function getSpec(model, options = {}) {
|
|
32
32
|
if (!options.specType) {
|
|
33
|
-
options.specType = SpecTypes.
|
|
33
|
+
options.specType = SpecTypes.OPENAPI;
|
|
34
34
|
}
|
|
35
35
|
options = {
|
|
36
36
|
...options,
|
|
@@ -40,7 +40,7 @@ export function getSpec(model, options = { specType: SpecTypes.SWAGGER }) {
|
|
|
40
40
|
};
|
|
41
41
|
return get(model, options, () => {
|
|
42
42
|
const store = getJsonEntityStore(model);
|
|
43
|
-
const { specType = SpecTypes.
|
|
43
|
+
const { specType = SpecTypes.OPENAPI, schemas = {}, paths = {}, rootPath = "/", tags = [] } = options;
|
|
44
44
|
const ctrlPath = store.path;
|
|
45
45
|
const defaultTags = cleanObject({
|
|
46
46
|
name: store.schema.getName(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSpec.js","sourceRoot":"","sources":["../../../src/utils/getSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAQ,MAAM,EAAC,MAAM,YAAY,CAAC;AAErD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACt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H,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAErC,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE;YAC/B,IAAI,QAAQ,KAAK,SAAS,CAAC,OAAO,EAAE;gBAClC,QAAQ,CAAC,UAAU,GAAG;oBACpB,OAAO;iBACR,CAAC;aACH;iBAAM;gBACL,QAAQ,CAAC,WAAW,GAAG,OAAO,CAAC;aAChC;SACF;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {cleanObject, Type, uniqBy} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces\";\nimport {buildPath} from \"./buildPath\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\nimport {getOperationsStores} from \"./getOperationsStores\";\nimport {mergeOperation} from \"./mergeOperation\";\nimport {operationIdFormatter} from \"./operationIdFormatter\";\n\nexport interface SpecSerializerOptions extends JsonSchemaOptions {\n specType?: SpecTypes.SWAGGER | SpecTypes.OPENAPI;\n /**\n * Paths\n */\n paths?: any;\n /**\n * Root path. This paths will be added to all generated paths Object.\n */\n rootPath?: string;\n /**\n * A function to generate the operationId.\n */\n operationIdFormatter?: (name: string, propertyKey: string, path: string) => string;\n /**\n * A pattern to generate the operationId.\n */\n operationIdPattern?: string;\n}\n\nexport interface OS3SpecSerializerOptions extends SpecSerializerOptions {\n /**\n * Define Spec types level\n */\n specType: SpecTypes.OPENAPI;\n}\n\nexport interface OS2SpecSerializerOptions extends SpecSerializerOptions {\n /**\n * Define Spec types level\n */\n specType: SpecTypes.SWAGGER;\n}\n\n/**\n * @ignore\n */\nconst caches: Map<Type<any>, Map<string, any>> = new Map();\n\n/**\n * @ignore\n */\nfunction get(model: Type<any>, options: any, cb: any) {\n if (!caches.has(model)) {\n caches.set(model, new Map());\n }\n\n const cache = caches.get(model)!;\n const key = JSON.stringify(options);\n\n if (!cache.has(key)) {\n cache.set(key, cb());\n }\n\n return cache.get(key);\n}\n\n/**\n * Return the swagger or open spec for the given class.\n * @param model\n * @param options\n */\nexport function getSpec(model: Type<any>, options: OS2SpecSerializerOptions): Partial<OpenSpec2>;\nexport function getSpec(model: Type<any>): Partial<OpenSpec2>;\nexport function getSpec(model: Type<any>, options: SpecSerializerOptions): Partial<OpenSpec2>;\n/**\n * Return the swagger or open spec for the given class.\n * @param model\n * @param options\n */\nexport function getSpec(model: Type<any>, options: OS3SpecSerializerOptions): Partial<OpenSpec3>;\n/**\n * Return the swagger or open spec for the given class.\n * @param model\n * @param options\n */\nexport function getSpec(model: Type<any>, options: SpecSerializerOptions = {}): Partial<OpenSpec2 | OpenSpec3> {\n if (!options.specType) {\n options.specType = SpecTypes.OPENAPI;\n }\n\n options = {\n ...options,\n operationIdFormatter: options.operationIdFormatter || operationIdFormatter(options.operationIdPattern),\n root: false,\n specType: options.specType\n };\n\n return get(model, options, () => {\n const store = getJsonEntityStore(model);\n const {specType = SpecTypes.OPENAPI, schemas = {}, paths = {}, rootPath = \"/\", tags = []} = options;\n const ctrlPath = store.path;\n const defaultTags = cleanObject({\n name: store.schema.getName(),\n description: store.schema.get(\"description\")\n });\n\n const specJson: any = {paths};\n\n getOperationsStores(model).forEach((operationStore) => {\n if (operationStore.store.get(\"hidden\")) {\n return;\n }\n\n const operation = operationStore.operation!.toJSON({...options, specType, schemas});\n\n operationStore.operation!.operationPaths.forEach(({path, method}: {path: string; method: string}) => {\n if (method) {\n mergeOperation(specJson, operation, {\n rootPath: buildPath(rootPath + ctrlPath),\n path,\n method,\n defaultTags,\n tags,\n specType,\n operationId: (path: string) =>\n options.operationIdFormatter!(\n operationStore.parent.schema.get(\"name\") || operationStore.parent.targetName,\n operationStore.propertyName,\n path\n )\n });\n }\n });\n });\n\n specJson.tags = uniqBy(tags, \"name\");\n\n if (Object.keys(schemas).length) {\n if (specType === SpecTypes.OPENAPI) {\n specJson.components = {\n schemas\n };\n } else {\n specJson.definitions = schemas;\n }\n }\n\n return specJson;\n });\n}\n"]}
|
|
@@ -4,7 +4,7 @@ function hasNullable(obj) {
|
|
|
4
4
|
return obj.oneOf.find((o) => o.type === "null");
|
|
5
5
|
}
|
|
6
6
|
export function mapNullableType(obj, schema, options) {
|
|
7
|
-
if (!schema.isNullable) {
|
|
7
|
+
if (!(schema === null || schema === void 0 ? void 0 : schema.isNullable)) {
|
|
8
8
|
return obj;
|
|
9
9
|
}
|
|
10
10
|
let types = [].concat(obj.type).filter(Boolean);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapNullableType.js","sourceRoot":"","sources":["../../../src/utils/mapNullableType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAC;AAEhC,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAG9C,SAAS,WAAW,CAAC,GAAQ;IAC3B,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"mapNullableType.js","sourceRoot":"","sources":["../../../src/utils/mapNullableType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAC;AAEhC,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAG9C,SAAS,WAAW,CAAC,GAAQ;IAC3B,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC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C,CAAC,CAAC;iBACrB;aACF;YACD,MAAM;KACT;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import {uniq} from \"@tsed/core\";\nimport type {JsonSchema} from \"../domain/JsonSchema\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport type {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\n\nfunction hasNullable(obj: any) {\n return obj.oneOf.find((o: any) => o.type === \"null\");\n}\n\nexport function mapNullableType(obj: any, schema: JsonSchema | null, options: JsonSchemaOptions) {\n if (!schema?.isNullable) {\n return obj;\n }\n let types: string[] = [].concat(obj.type).filter(Boolean);\n\n switch (options.specType) {\n case SpecTypes.SWAGGER:\n if (!obj.allOf && !obj.$ref) {\n obj.type = uniq([\"null\", ...types]);\n }\n break;\n default:\n case SpecTypes.JSON:\n if (obj.oneOf) {\n if (!hasNullable(obj)) {\n obj.oneOf.unshift({\n type: \"null\"\n });\n }\n } else {\n obj.type = uniq([\"null\", ...types]);\n }\n break;\n\n case SpecTypes.OPENAPI:\n obj.nullable = true;\n\n if (!obj.oneOf) {\n if (types.length > 1) {\n obj.oneOf = types.map((type) => ({type}));\n delete obj.type;\n } else {\n obj.type = types[0];\n }\n }\n break;\n }\n\n return obj;\n}\n"]}
|
|
@@ -10,6 +10,7 @@ export * from "./generics/generics";
|
|
|
10
10
|
export * from "./generics/genericOf";
|
|
11
11
|
export * from "./operations/deprecated";
|
|
12
12
|
export * from "./operations/consumes";
|
|
13
|
+
export * from "./operations/view";
|
|
13
14
|
export * from "./operations/contentType";
|
|
14
15
|
export * from "./operations/in";
|
|
15
16
|
export * from "./operations/inFile";
|
|
@@ -27,6 +28,7 @@ export * from "./operations/partial";
|
|
|
27
28
|
export * from "./operations/redirect";
|
|
28
29
|
export * from "./operations/location";
|
|
29
30
|
export * from "./operations/route";
|
|
31
|
+
export * from "./operations/acceptMime";
|
|
30
32
|
export * from "./common/additionalProperties";
|
|
31
33
|
export * from "./common/allow";
|
|
32
34
|
export * from "./common/any";
|