@tsed/schema 6.114.17 → 6.114.18
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/components/lazyRefMapper.js +1 -2
- package/lib/cjs/components/lazyRefMapper.js.map +1 -1
- package/lib/cjs/components/objectMapper.js +1 -1
- package/lib/cjs/components/objectMapper.js.map +1 -1
- package/lib/cjs/constants/httpStatusMessages.js +2 -4
- package/lib/cjs/constants/httpStatusMessages.js.map +1 -1
- package/lib/cjs/decorators/common/description.js +1 -2
- package/lib/cjs/decorators/common/description.js.map +1 -1
- package/lib/cjs/decorators/operations/redirect.js +1 -2
- package/lib/cjs/decorators/operations/redirect.js.map +1 -1
- package/lib/cjs/decorators/operations/returns.js +20 -20
- package/lib/cjs/decorators/operations/returns.js.map +1 -1
- package/lib/cjs/decorators/operations/route.js +1 -4
- package/lib/cjs/decorators/operations/route.js.map +1 -1
- package/lib/cjs/domain/DecoratorContext.js +4 -1
- package/lib/cjs/domain/DecoratorContext.js.map +1 -1
- package/lib/cjs/domain/JsonClassStore.js +4 -7
- package/lib/cjs/domain/JsonClassStore.js.map +1 -1
- package/lib/cjs/domain/JsonEntityStore.js +37 -1
- package/lib/cjs/domain/JsonEntityStore.js.map +1 -1
- package/lib/cjs/domain/JsonLazyRef.js +2 -1
- package/lib/cjs/domain/JsonLazyRef.js.map +1 -1
- package/lib/cjs/domain/JsonMethodStore.js +12 -12
- package/lib/cjs/domain/JsonMethodStore.js.map +1 -1
- package/lib/cjs/domain/JsonOperation.js +12 -16
- package/lib/cjs/domain/JsonOperation.js.map +1 -1
- package/lib/cjs/domain/JsonOperationPathsMap.js +1 -4
- package/lib/cjs/domain/JsonOperationPathsMap.js.map +1 -1
- package/lib/cjs/domain/JsonOperationRoute.js +8 -6
- package/lib/cjs/domain/JsonOperationRoute.js.map +1 -1
- package/lib/cjs/domain/JsonParameter.js +4 -4
- package/lib/cjs/domain/JsonParameter.js.map +1 -1
- package/lib/cjs/domain/JsonParameterStore.js +12 -5
- package/lib/cjs/domain/JsonParameterStore.js.map +1 -1
- package/lib/cjs/domain/JsonPropertyStore.js +1 -4
- package/lib/cjs/domain/JsonPropertyStore.js.map +1 -1
- package/lib/cjs/domain/JsonResponse.js +3 -6
- package/lib/cjs/domain/JsonResponse.js.map +1 -1
- package/lib/cjs/domain/JsonSchema.js +58 -60
- package/lib/cjs/domain/JsonSchema.js.map +1 -1
- package/lib/cjs/hooks/alterIgnore.js +2 -3
- package/lib/cjs/hooks/alterIgnore.js.map +1 -1
- package/lib/cjs/hooks/alterRequiredGroups.js +1 -2
- package/lib/cjs/hooks/alterRequiredGroups.js.map +1 -1
- package/lib/cjs/utils/getJsonSchema.js +1 -2
- package/lib/cjs/utils/getJsonSchema.js.map +1 -1
- package/lib/cjs/utils/getRequiredProperties.js +3 -3
- package/lib/cjs/utils/getRequiredProperties.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/mergeOperation.js +1 -2
- package/lib/cjs/utils/mergeOperation.js.map +1 -1
- package/lib/cjs/utils/transformToOS2.js +2 -2
- package/lib/cjs/utils/transformToOS2.js.map +1 -1
- package/lib/esm/components/lazyRefMapper.js +1 -2
- package/lib/esm/components/lazyRefMapper.js.map +1 -1
- package/lib/esm/components/objectMapper.js +1 -1
- package/lib/esm/components/objectMapper.js.map +1 -1
- package/lib/esm/constants/httpStatusMessages.js +2 -4
- package/lib/esm/constants/httpStatusMessages.js.map +1 -1
- package/lib/esm/decorators/common/description.js +1 -2
- package/lib/esm/decorators/common/description.js.map +1 -1
- package/lib/esm/decorators/operations/redirect.js +1 -2
- package/lib/esm/decorators/operations/redirect.js.map +1 -1
- package/lib/esm/decorators/operations/returns.js +20 -20
- package/lib/esm/decorators/operations/returns.js.map +1 -1
- package/lib/esm/decorators/operations/route.js +1 -4
- package/lib/esm/decorators/operations/route.js.map +1 -1
- package/lib/esm/domain/DecoratorContext.js +4 -1
- package/lib/esm/domain/DecoratorContext.js.map +1 -1
- package/lib/esm/domain/JsonClassStore.js +4 -7
- package/lib/esm/domain/JsonClassStore.js.map +1 -1
- package/lib/esm/domain/JsonEntityStore.js +37 -1
- package/lib/esm/domain/JsonEntityStore.js.map +1 -1
- package/lib/esm/domain/JsonLazyRef.js +2 -1
- package/lib/esm/domain/JsonLazyRef.js.map +1 -1
- package/lib/esm/domain/JsonMethodStore.js +12 -12
- package/lib/esm/domain/JsonMethodStore.js.map +1 -1
- package/lib/esm/domain/JsonOperation.js +12 -16
- package/lib/esm/domain/JsonOperation.js.map +1 -1
- package/lib/esm/domain/JsonOperationPathsMap.js +1 -4
- package/lib/esm/domain/JsonOperationPathsMap.js.map +1 -1
- package/lib/esm/domain/JsonOperationRoute.js +8 -6
- package/lib/esm/domain/JsonOperationRoute.js.map +1 -1
- package/lib/esm/domain/JsonParameter.js +4 -4
- package/lib/esm/domain/JsonParameter.js.map +1 -1
- package/lib/esm/domain/JsonParameterStore.js +12 -5
- package/lib/esm/domain/JsonParameterStore.js.map +1 -1
- package/lib/esm/domain/JsonPropertyStore.js +1 -4
- package/lib/esm/domain/JsonPropertyStore.js.map +1 -1
- package/lib/esm/domain/JsonResponse.js +3 -6
- package/lib/esm/domain/JsonResponse.js.map +1 -1
- package/lib/esm/domain/JsonSchema.js +58 -60
- package/lib/esm/domain/JsonSchema.js.map +1 -1
- package/lib/esm/hooks/alterIgnore.js +2 -3
- package/lib/esm/hooks/alterIgnore.js.map +1 -1
- package/lib/esm/hooks/alterRequiredGroups.js +1 -2
- package/lib/esm/hooks/alterRequiredGroups.js.map +1 -1
- package/lib/esm/utils/getJsonSchema.js +1 -2
- package/lib/esm/utils/getJsonSchema.js.map +1 -1
- package/lib/esm/utils/getRequiredProperties.js +3 -3
- package/lib/esm/utils/getRequiredProperties.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/mergeOperation.js +1 -2
- package/lib/esm/utils/mergeOperation.js.map +1 -1
- package/lib/esm/utils/transformToOS2.js +2 -2
- package/lib/esm/utils/transformToOS2.js.map +1 -1
- package/package.json +6 -6
- package/tsconfig.compile.esm.json +2 -1
|
@@ -8,24 +8,24 @@ const JsonOperation_1 = require("./JsonOperation");
|
|
|
8
8
|
const JsonSchema_1 = require("./JsonSchema");
|
|
9
9
|
const jsonEntityComponent_1 = require("../decorators/config/jsonEntityComponent");
|
|
10
10
|
let JsonMethodStore = class JsonMethodStore extends JsonEntityStore_1.JsonEntityStore {
|
|
11
|
+
parent = JsonEntityStore_1.JsonEntityStore.from(this.target);
|
|
12
|
+
middlewares = [];
|
|
13
|
+
beforeMiddlewares = [];
|
|
14
|
+
afterMiddlewares = [];
|
|
15
|
+
/**
|
|
16
|
+
* Ref to JsonOperation when the decorated object is a method.
|
|
17
|
+
*/
|
|
18
|
+
operation = new JsonOperation_1.JsonOperation();
|
|
19
|
+
/**
|
|
20
|
+
* List of children JsonEntityStore (properties or methods or params)
|
|
21
|
+
*/
|
|
22
|
+
children = new Map();
|
|
11
23
|
constructor(options) {
|
|
12
24
|
super({
|
|
13
25
|
store: core_1.Store.fromMethod(options.target, options.propertyKey),
|
|
14
26
|
descriptor: (0, core_1.descriptorOf)(options.target, options.propertyKey),
|
|
15
27
|
...options
|
|
16
28
|
});
|
|
17
|
-
this.parent = JsonEntityStore_1.JsonEntityStore.from(this.target);
|
|
18
|
-
this.middlewares = [];
|
|
19
|
-
this.beforeMiddlewares = [];
|
|
20
|
-
this.afterMiddlewares = [];
|
|
21
|
-
/**
|
|
22
|
-
* Ref to JsonOperation when the decorated object is a method.
|
|
23
|
-
*/
|
|
24
|
-
this.operation = new JsonOperation_1.JsonOperation();
|
|
25
|
-
/**
|
|
26
|
-
* List of children JsonEntityStore (properties or methods or params)
|
|
27
|
-
*/
|
|
28
|
-
this.children = new Map();
|
|
29
29
|
const { beforeMiddlewares = [], middlewares = [], afterMiddlewares = [] } = options;
|
|
30
30
|
this.after(afterMiddlewares);
|
|
31
31
|
this.before(beforeMiddlewares);
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;IACzC,MAAM,GAAmB,iCAAe,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7D,WAAW,GAAU,EAAE,CAAC;IACxB,iBAAiB,GAAU,EAAE,CAAC;IAC9B,gBAAgB,GAAU,EAAE,CAAC;IACpC;;OAEG;IACM,SAAS,GAAkB,IAAI,6BAAa,EAAE,CAAC;IACxD;;OAEG;IACM,QAAQ,GAA6C,IAAI,GAAG,EAAE,CAAC;IAExE,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;QAEH,MAAM,EAAC,iBAAiB,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,gBAAgB,GAAG,EAAE,EAAC,GAAG,OAAO,CAAC;QAElF,IAAI,CAAC,KAAK,CAAC,gBAAg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AC;IACjE,CAAC;CACF,CAAA;AAlKY,eAAe;IAD3B,IAAA,yCAAmB,EAAC,qBAAc,CAAC,MAAM,CAAC;;GAC9B,eAAe,CAkK3B;AAlKY,0CAAe;AAuLf,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 * 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 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 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 /**\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 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 /**\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 public 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 public getParamTypes(): Record<string, boolean> {\n return [...this.children.values()].reduce(\n (obj, item) => ({\n ...obj,\n [item.paramType]: true\n }),\n {}\n );\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/**\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"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _JsonOperation_status, _JsonOperation_redirection;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.JsonOperation = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
4
|
const core_1 = require("@tsed/core");
|
|
7
5
|
const httpStatusMessages_1 = require("../constants/httpStatusMessages");
|
|
8
6
|
const isSuccessStatus_1 = require("../utils/isSuccessStatus");
|
|
@@ -12,17 +10,17 @@ const JsonRequestBody_1 = require("./JsonRequestBody");
|
|
|
12
10
|
const JsonResponse_1 = require("./JsonResponse");
|
|
13
11
|
const JsonSchema_1 = require("./JsonSchema");
|
|
14
12
|
class JsonOperation extends JsonMap_1.JsonMap {
|
|
13
|
+
operationPaths = new Map();
|
|
14
|
+
#status;
|
|
15
|
+
#redirection = false;
|
|
15
16
|
constructor(obj = {}) {
|
|
16
17
|
super({ parameters: [], responses: new JsonMap_1.JsonMap(), ...obj });
|
|
17
|
-
this.operationPaths = new Map();
|
|
18
|
-
_JsonOperation_status.set(this, void 0);
|
|
19
|
-
_JsonOperation_redirection.set(this, false);
|
|
20
18
|
}
|
|
21
19
|
get response() {
|
|
22
20
|
return this.getResponses().get(this.getStatus().toString());
|
|
23
21
|
}
|
|
24
22
|
get status() {
|
|
25
|
-
return
|
|
23
|
+
return this.#status;
|
|
26
24
|
}
|
|
27
25
|
tags(tags) {
|
|
28
26
|
super.set("tags", tags);
|
|
@@ -45,27 +43,27 @@ class JsonOperation extends JsonMap_1.JsonMap {
|
|
|
45
43
|
return this;
|
|
46
44
|
}
|
|
47
45
|
defaultStatus(status) {
|
|
48
|
-
|
|
46
|
+
this.#status = status;
|
|
49
47
|
return this;
|
|
50
48
|
}
|
|
51
49
|
getStatus() {
|
|
52
|
-
return
|
|
50
|
+
return this.#status || 200;
|
|
53
51
|
}
|
|
54
52
|
setRedirection(status = 302) {
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
this.#redirection = true;
|
|
54
|
+
this.#status = status;
|
|
57
55
|
return this;
|
|
58
56
|
}
|
|
59
57
|
isRedirection(status) {
|
|
60
|
-
if (
|
|
58
|
+
if (this.#redirection) {
|
|
61
59
|
if (status) {
|
|
62
60
|
return (0, isSuccessStatus_1.isRedirectionStatus)(status);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
|
-
return
|
|
63
|
+
return this.#redirection;
|
|
66
64
|
}
|
|
67
65
|
addResponse(statusCode, response) {
|
|
68
|
-
if (((0, isSuccessStatus_1.isSuccessStatus)(statusCode) || (0, isSuccessStatus_1.isRedirectionStatus)(statusCode)) && !
|
|
66
|
+
if (((0, isSuccessStatus_1.isSuccessStatus)(statusCode) || (0, isSuccessStatus_1.isRedirectionStatus)(statusCode)) && !this.#status) {
|
|
69
67
|
const res = this.getResponseOf(200);
|
|
70
68
|
this.getResponses().set(statusCode.toString(), res).delete("200");
|
|
71
69
|
this.defaultStatus(Number(statusCode));
|
|
@@ -186,11 +184,9 @@ class JsonOperation extends JsonMap_1.JsonMap {
|
|
|
186
184
|
}
|
|
187
185
|
}
|
|
188
186
|
exports.JsonOperation = JsonOperation;
|
|
189
|
-
_JsonOperation_status = new WeakMap(), _JsonOperation_redirection = new WeakMap();
|
|
190
187
|
function toRequestBody(operation, { schema, in: _, ...props }) {
|
|
191
|
-
var _a;
|
|
192
188
|
const requestBody = new JsonRequestBody_1.JsonRequestBody(props);
|
|
193
|
-
const consumes =
|
|
189
|
+
const consumes = operation.get("consumes")?.length ? operation.get("consumes") : ["application/json"];
|
|
194
190
|
consumes.forEach((consume) => {
|
|
195
191
|
requestBody.addContent(consume, schema);
|
|
196
192
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonOperation.js","sourceRoot":"","sources":["../../../src/domain/JsonOperation.ts"],"names":[],"mappings":";;;;;AAAA,qCAAmD;AAEnD,wEAAiE;AAGjE,8DAA8E;AAC9E,uCAAkC;AAElC,6DAAyE;AACzE,uDAAkD;AAClD,iDAA4C;AAC5C,6CAAwC;AAexC,MAAa,aAAc,SAAQ,iBAA6B;IAK9D,YAAY,MAAqC,EAAE;QACjD,KAAK,CAAC,EAAC,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,iBAAO,EAAE,EAAE,GAAG,GAAG,EAAC,CAAC,CAAC;QALnD,mBAAc,GAAgC,IAAI,GAAG,EAAE,CAAC;QACjE,wCAAgB;QAChB,qCAAwB,KAAK,EAAC;IAI9B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,MAAM;QACR,OAAO,+BAAA,IAAI,6BAAQ,CAAC;IACtB,CAAC;IAED,IAAI,CAAC,IAAmB;QACtB,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAExB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GAAG,KAAK,EAAC,CAAC;AACrE,CAAC","sourcesContent":["import {deepMerge, uniq, uniqBy} from \"@tsed/core\";\nimport {OpenSpecSecurity, OpenSpecTag, OS3Operation} from \"@tsed/openspec\";\nimport {getStatusMessage} from \"../constants/httpStatusMessages\";\nimport {JsonHeader} from \"../interfaces/JsonOpenSpec\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {isRedirectionStatus, isSuccessStatus} from \"../utils/isSuccessStatus\";\nimport {JsonMap} from \"./JsonMap\";\nimport {JsonParameter} from \"./JsonParameter\";\nimport {isParameterType, JsonParameterTypes} from \"./JsonParameterTypes\";\nimport {JsonRequestBody} from \"./JsonRequestBody\";\nimport {JsonResponse} from \"./JsonResponse\";\nimport {JsonSchema} from \"./JsonSchema\";\n\nexport interface JsonMethodPath {\n path: string | RegExp;\n method: string;\n isFinal?: boolean;\n\n [key: string]: any;\n}\n\nexport interface JsonOperationOptions extends OS3Operation<JsonSchema, JsonParameter, JsonMap<JsonResponse>> {\n consumes: string[];\n produces: string[];\n}\n\nexport class JsonOperation extends JsonMap<JsonOperationOptions> {\n readonly operationPaths: Map<string, JsonMethodPath> = new Map();\n #status: number;\n #redirection: boolean = false;\n\n constructor(obj: Partial<JsonOperationOptions> = {}) {\n super({parameters: [], responses: new JsonMap(), ...obj});\n }\n\n get response(): JsonResponse | undefined {\n return this.getResponses().get(this.getStatus().toString());\n }\n\n get status() {\n return this.#status;\n }\n\n tags(tags: OpenSpecTag[]): this {\n super.set(\"tags\", tags);\n\n return this;\n }\n\n addTags(tags: OpenSpecTag[]) {\n tags = uniqBy([...(this.get(\"tags\") || []), ...tags], \"name\");\n\n return this.tags(tags);\n }\n\n summary(summary: string): this {\n super.set(\"summary\", summary);\n\n return this;\n }\n\n operationId(operationId: string): this {\n this.set(\"operationId\", operationId);\n\n return this;\n }\n\n responses(responses: JsonMap<any>): this {\n this.set(\"responses\", responses);\n\n return this;\n }\n\n defaultStatus(status: number) {\n this.#status = status;\n\n return this;\n }\n\n getStatus() {\n return this.#status || 200;\n }\n\n setRedirection(status = 302) {\n this.#redirection = true;\n this.#status = status;\n return this;\n }\n\n isRedirection(status?: number) {\n if (this.#redirection) {\n if (status) {\n return isRedirectionStatus(status);\n }\n }\n\n return this.#redirection;\n }\n\n addResponse(statusCode: string | number, response: JsonResponse) {\n if ((isSuccessStatus(statusCode) || isRedirectionStatus(statusCode)) && !this.#status) {\n const res = this.getResponseOf(200);\n\n this.getResponses().set(statusCode.toString(), res).delete(\"200\");\n\n this.defaultStatus(Number(statusCode));\n }\n\n const currentCode = statusCode === \"default\" ? this.getStatus().toString() : statusCode.toString();\n const currentResponse = this.getResponses().get(currentCode);\n\n if (!currentResponse) {\n response.status = Number(currentCode);\n this.getResponses().set(currentCode, response);\n } else {\n response.forEach((value, key) => {\n if (![\"content\"].includes(key)) {\n currentResponse.set(key, deepMerge(currentResponse.get(key), value));\n }\n });\n currentResponse.status = Number(currentCode);\n }\n\n return this;\n }\n\n getResponses() {\n return this.get(\"responses\") as JsonMap<JsonResponse>;\n }\n\n getResponseOf(status: number | string): JsonResponse {\n return (status === \"default\" ? this.response : this.getResponses().get(String(status))) || new JsonResponse();\n }\n\n ensureResponseOf(status: number | string): JsonResponse {\n this.addResponse(status, this.getResponseOf(status));\n return this.getResponseOf(status);\n }\n\n getHeadersOf(status: number): Record<string, JsonHeader & {example: string}> {\n return this.getResponseOf(status).get(\"headers\") || {};\n }\n\n getContentTypeOf(status: number): any {\n return [...this.getResponseOf(status).get(\"content\").keys()].slice(-1)[0];\n }\n\n security(security: OpenSpecSecurity): this {\n this.set(\"security\", security);\n\n return this;\n }\n\n addSecurityScopes(name: string, scopes: string[]) {\n const security = this.get(\"security\") || {};\n security[name] = uniq([...(security[name] || []), ...scopes]);\n\n return this.security(security);\n }\n\n description(description: string): this {\n super.set(\"description\", description);\n\n return this;\n }\n\n deprecated(deprecated: boolean): this {\n super.set(\"deprecated\", deprecated);\n\n return this;\n }\n\n parameters(parameters: JsonParameter[]): this {\n super.set(\"parameters\", parameters);\n\n return this;\n }\n\n addParameter(index: number, parameter: JsonParameter) {\n if (index === -1) {\n index = this.get(\"parameters\").length;\n }\n this.get(\"parameters\")[index] = parameter;\n }\n\n consumes(consumes: string[]): this {\n super.set(\"consumes\", consumes);\n\n return this;\n }\n\n produces(produces: string[]): this {\n super.set(\"produces\", produces);\n\n return this;\n }\n\n addProduce(produce: string) {\n const produces = uniq([].concat(this.get(\"produces\"), produce as never)).filter(Boolean);\n\n this.set(\"produces\", produces);\n }\n\n addOperationPath(method: string, path: string | RegExp, options: any = {}) {\n this.operationPaths.set(String(method) + String(path), {\n ...options,\n method,\n path\n });\n\n return this;\n }\n\n toJSON(options: JsonSchemaOptions = {}): any {\n const operation = super.toJSON({...options, ignore: [\"parameters\"]});\n const bodyParameters: JsonParameter[] = [];\n const parameters: any[] = [];\n\n if (operation.security) {\n operation.security = [].concat(operation.security);\n }\n\n this.get(\"parameters\").forEach((parameter: JsonParameter) => {\n if (!isParameterType(this.get(\"in\"))) {\n if (parameter.get(\"in\")) {\n if ([JsonParameterTypes.BODY, JsonParameterTypes.FILES].includes(parameter.get(\"in\"))) {\n bodyParameters.push(parameter);\n } else {\n parameters.push(...[].concat(parameter.toJSON(options)));\n }\n }\n }\n });\n\n operation.parameters = parameters.filter(Boolean);\n\n if (this.get(\"responses\").size === 0) {\n operation.responses = {\n \"200\": {\n description: getStatusMessage(200)\n }\n };\n }\n\n if (bodyParameters.length) {\n const parameter = buildSchemaFromBodyParameters(bodyParameters, options);\n operation.requestBody = toRequestBody(this, parameter).toJSON(options);\n }\n\n delete operation.consumes;\n delete operation.produces;\n\n return operation;\n }\n}\n\nfunction toRequestBody(operation: JsonOperation, {schema, in: _, ...props}: any) {\n const requestBody = new JsonRequestBody(props);\n\n const consumes = operation.get(\"consumes\")?.length ? operation.get(\"consumes\") : [\"application/json\"];\n\n consumes.forEach((consume: string) => {\n requestBody.addContent(consume, schema);\n });\n\n return requestBody;\n}\n\nfunction buildSchemaFromBodyParameters(parameters: JsonParameter[], options: JsonSchemaOptions) {\n let schema = new JsonSchema();\n const props: any = {};\n const refs: JsonSchema[] = [];\n let propsLength = 0;\n\n parameters.forEach((parameter) => {\n const name = parameter.getName();\n\n Array.from(parameter.entries())\n .filter(([key]) => ![\"in\", \"name\"].includes(key))\n .forEach(([key, value]) => {\n if (props[key] === undefined) {\n props[key] = value;\n }\n });\n\n const jsonParameter = parameter.toJSON(options);\n\n if (name) {\n schema.addProperty(\n name,\n jsonParameter.schema || {\n type: jsonParameter.type\n }\n );\n\n if (parameter.get(\"required\")) {\n schema.addRequired(name);\n }\n\n propsLength++;\n } else {\n refs.push(jsonParameter);\n }\n });\n\n if (!propsLength) {\n if (refs.length === 1) {\n return refs[0];\n }\n }\n\n schema.type(\"object\");\n\n return {schema: schema.toJSON(options), required: false, ...props};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"JsonOperation.js","sourceRoot":"","sources":["../../../src/domain/JsonOperation.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AAEnD,wEAAiE;AAGjE,8DAA8E;AAC9E,uCAAkC;AAElC,6DAAyE;AACzE,uDAAkD;AAClD,iDAA4C;AAC5C,6CAAwC;AAexC,MAAa,aAAc,SAAQ,iBAA6B;IACrD,cAAc,GAAgC,IAAI,GAAG,EAAE,CAAC;IACjE,OAAO,CAAS;IAChB,YAAY,GAAY,KAAK,CAAC;IAE9B,YAAY,MAAqC,EAAE;QACjD,KAAK,CAAC,EAAC,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,iBAAO,EAAE,EAAE,GAAG,GAAG,EAAC,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACt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CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK,EAAC,CAAC;AACrE,CAAC","sourcesContent":["import {deepMerge, uniq, uniqBy} from \"@tsed/core\";\nimport {OpenSpecSecurity, OpenSpecTag, OS3Operation} from \"@tsed/openspec\";\nimport {getStatusMessage} from \"../constants/httpStatusMessages\";\nimport {JsonHeader} from \"../interfaces/JsonOpenSpec\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {isRedirectionStatus, isSuccessStatus} from \"../utils/isSuccessStatus\";\nimport {JsonMap} from \"./JsonMap\";\nimport {JsonParameter} from \"./JsonParameter\";\nimport {isParameterType, JsonParameterTypes} from \"./JsonParameterTypes\";\nimport {JsonRequestBody} from \"./JsonRequestBody\";\nimport {JsonResponse} from \"./JsonResponse\";\nimport {JsonSchema} from \"./JsonSchema\";\n\nexport interface JsonMethodPath {\n path: string | RegExp;\n method: string;\n isFinal?: boolean;\n\n [key: string]: any;\n}\n\nexport interface JsonOperationOptions extends OS3Operation<JsonSchema, JsonParameter, JsonMap<JsonResponse>> {\n consumes: string[];\n produces: string[];\n}\n\nexport class JsonOperation extends JsonMap<JsonOperationOptions> {\n readonly operationPaths: Map<string, JsonMethodPath> = new Map();\n #status: number;\n #redirection: boolean = false;\n\n constructor(obj: Partial<JsonOperationOptions> = {}) {\n super({parameters: [], responses: new JsonMap(), ...obj});\n }\n\n get response(): JsonResponse | undefined {\n return this.getResponses().get(this.getStatus().toString());\n }\n\n get status() {\n return this.#status;\n }\n\n tags(tags: OpenSpecTag[]): this {\n super.set(\"tags\", tags);\n\n return this;\n }\n\n addTags(tags: OpenSpecTag[]) {\n tags = uniqBy([...(this.get(\"tags\") || []), ...tags], \"name\");\n\n return this.tags(tags);\n }\n\n summary(summary: string): this {\n super.set(\"summary\", summary);\n\n return this;\n }\n\n operationId(operationId: string): this {\n this.set(\"operationId\", operationId);\n\n return this;\n }\n\n responses(responses: JsonMap<any>): this {\n this.set(\"responses\", responses);\n\n return this;\n }\n\n defaultStatus(status: number) {\n this.#status = status;\n\n return this;\n }\n\n getStatus() {\n return this.#status || 200;\n }\n\n setRedirection(status = 302) {\n this.#redirection = true;\n this.#status = status;\n return this;\n }\n\n isRedirection(status?: number) {\n if (this.#redirection) {\n if (status) {\n return isRedirectionStatus(status);\n }\n }\n\n return this.#redirection;\n }\n\n addResponse(statusCode: string | number, response: JsonResponse) {\n if ((isSuccessStatus(statusCode) || isRedirectionStatus(statusCode)) && !this.#status) {\n const res = this.getResponseOf(200);\n\n this.getResponses().set(statusCode.toString(), res).delete(\"200\");\n\n this.defaultStatus(Number(statusCode));\n }\n\n const currentCode = statusCode === \"default\" ? this.getStatus().toString() : statusCode.toString();\n const currentResponse = this.getResponses().get(currentCode);\n\n if (!currentResponse) {\n response.status = Number(currentCode);\n this.getResponses().set(currentCode, response);\n } else {\n response.forEach((value, key) => {\n if (![\"content\"].includes(key)) {\n currentResponse.set(key, deepMerge(currentResponse.get(key), value));\n }\n });\n currentResponse.status = Number(currentCode);\n }\n\n return this;\n }\n\n getResponses() {\n return this.get(\"responses\") as JsonMap<JsonResponse>;\n }\n\n getResponseOf(status: number | string): JsonResponse {\n return (status === \"default\" ? this.response : this.getResponses().get(String(status))) || new JsonResponse();\n }\n\n ensureResponseOf(status: number | string): JsonResponse {\n this.addResponse(status, this.getResponseOf(status));\n return this.getResponseOf(status);\n }\n\n getHeadersOf(status: number): Record<string, JsonHeader & {example: string}> {\n return this.getResponseOf(status).get(\"headers\") || {};\n }\n\n getContentTypeOf(status: number): any {\n return [...this.getResponseOf(status).get(\"content\").keys()].slice(-1)[0];\n }\n\n security(security: OpenSpecSecurity): this {\n this.set(\"security\", security);\n\n return this;\n }\n\n addSecurityScopes(name: string, scopes: string[]) {\n const security = this.get(\"security\") || {};\n security[name] = uniq([...(security[name] || []), ...scopes]);\n\n return this.security(security);\n }\n\n description(description: string): this {\n super.set(\"description\", description);\n\n return this;\n }\n\n deprecated(deprecated: boolean): this {\n super.set(\"deprecated\", deprecated);\n\n return this;\n }\n\n parameters(parameters: JsonParameter[]): this {\n super.set(\"parameters\", parameters);\n\n return this;\n }\n\n addParameter(index: number, parameter: JsonParameter) {\n if (index === -1) {\n index = this.get(\"parameters\").length;\n }\n this.get(\"parameters\")[index] = parameter;\n }\n\n consumes(consumes: string[]): this {\n super.set(\"consumes\", consumes);\n\n return this;\n }\n\n produces(produces: string[]): this {\n super.set(\"produces\", produces);\n\n return this;\n }\n\n addProduce(produce: string) {\n const produces = uniq([].concat(this.get(\"produces\"), produce as never)).filter(Boolean);\n\n this.set(\"produces\", produces);\n }\n\n addOperationPath(method: string, path: string | RegExp, options: any = {}) {\n this.operationPaths.set(String(method) + String(path), {\n ...options,\n method,\n path\n });\n\n return this;\n }\n\n toJSON(options: JsonSchemaOptions = {}): any {\n const operation = super.toJSON({...options, ignore: [\"parameters\"]});\n const bodyParameters: JsonParameter[] = [];\n const parameters: any[] = [];\n\n if (operation.security) {\n operation.security = [].concat(operation.security);\n }\n\n this.get(\"parameters\").forEach((parameter: JsonParameter) => {\n if (!isParameterType(this.get(\"in\"))) {\n if (parameter.get(\"in\")) {\n if ([JsonParameterTypes.BODY, JsonParameterTypes.FILES].includes(parameter.get(\"in\"))) {\n bodyParameters.push(parameter);\n } else {\n parameters.push(...[].concat(parameter.toJSON(options)));\n }\n }\n }\n });\n\n operation.parameters = parameters.filter(Boolean);\n\n if (this.get(\"responses\").size === 0) {\n operation.responses = {\n \"200\": {\n description: getStatusMessage(200)\n }\n };\n }\n\n if (bodyParameters.length) {\n const parameter = buildSchemaFromBodyParameters(bodyParameters, options);\n operation.requestBody = toRequestBody(this, parameter).toJSON(options);\n }\n\n delete operation.consumes;\n delete operation.produces;\n\n return operation;\n }\n}\n\nfunction toRequestBody(operation: JsonOperation, {schema, in: _, ...props}: any) {\n const requestBody = new JsonRequestBody(props);\n\n const consumes = operation.get(\"consumes\")?.length ? operation.get(\"consumes\") : [\"application/json\"];\n\n consumes.forEach((consume: string) => {\n requestBody.addContent(consume, schema);\n });\n\n return requestBody;\n}\n\nfunction buildSchemaFromBodyParameters(parameters: JsonParameter[], options: JsonSchemaOptions) {\n let schema = new JsonSchema();\n const props: any = {};\n const refs: JsonSchema[] = [];\n let propsLength = 0;\n\n parameters.forEach((parameter) => {\n const name = parameter.getName();\n\n Array.from(parameter.entries())\n .filter(([key]) => ![\"in\", \"name\"].includes(key))\n .forEach(([key, value]) => {\n if (props[key] === undefined) {\n props[key] = value;\n }\n });\n\n const jsonParameter = parameter.toJSON(options);\n\n if (name) {\n schema.addProperty(\n name,\n jsonParameter.schema || {\n type: jsonParameter.type\n }\n );\n\n if (parameter.get(\"required\")) {\n schema.addRequired(name);\n }\n\n propsLength++;\n } else {\n refs.push(jsonParameter);\n }\n });\n\n if (!propsLength) {\n if (refs.length === 1) {\n return refs[0];\n }\n }\n\n schema.type(\"object\");\n\n return {schema: schema.toJSON(options), required: false, ...props};\n}\n"]}
|
|
@@ -3,10 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.JsonOperationPathsMap = void 0;
|
|
4
4
|
const httpMethods_1 = require("../constants/httpMethods");
|
|
5
5
|
class JsonOperationPathsMap extends Map {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.getKey = (method, path) => `${method}-${path}`;
|
|
9
|
-
}
|
|
10
6
|
setOperationPath(operationPath) {
|
|
11
7
|
if (operationPath.method !== httpMethods_1.OperationMethods.CUSTOM) {
|
|
12
8
|
const key = this.getKey(operationPath.method, operationPath.path);
|
|
@@ -15,6 +11,7 @@ class JsonOperationPathsMap extends Map {
|
|
|
15
11
|
this.setFinalRoute(key, operationPath);
|
|
16
12
|
}
|
|
17
13
|
}
|
|
14
|
+
getKey = (method, path) => `${method}-${path}`;
|
|
18
15
|
updateFinalRouteState(key) {
|
|
19
16
|
if (this.has(key)) {
|
|
20
17
|
this.get(key).isFinal = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonOperationPathsMap.js","sourceRoot":"","sources":["../../../src/domain/JsonOperationPathsMap.ts"],"names":[],"mappings":";;;AAAA,0DAA0D;AAG1D,MAAa,qBAAsB,SAAQ,GAA2B;
|
|
1
|
+
{"version":3,"file":"JsonOperationPathsMap.js","sourceRoot":"","sources":["../../../src/domain/JsonOperationPathsMap.ts"],"names":[],"mappings":";;;AAAA,0DAA0D;AAG1D,MAAa,qBAAsB,SAAQ,GAA2B;IACpE,gBAAgB,CAAC,aAA6B;QAC5C,IAAI,aAAa,CAAC,MAAM,KAAK,8BAAgB,CAAC,MAAM,EAAE;YACpD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;YAClE,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,8BAAgB,CAAC,GAAG,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;YAClF,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;SACxC;IACH,CAAC;IAES,MAAM,GAAG,CAAC,MAAc,EAAE,IAAS,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC;IAE5D,qBAAqB,CAAC,GAAW;QACzC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACjB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,OAAO,GAAG,KAAK,CAAC;SAChC;IACH,CAAC;IAES,aAAa,CAAC,GAAW,EAAE,aAA6B;QAChE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QAC7B,aAAa,CAAC,OAAO,GAAG,IAAI,CAAC;IAC/B,CAAC;CACF;AAtBD,sDAsBC","sourcesContent":["import {OperationMethods} from \"../constants/httpMethods\";\nimport {JsonMethodPath} from \"./JsonOperation\";\n\nexport class JsonOperationPathsMap extends Map<string, JsonMethodPath> {\n setOperationPath(operationPath: JsonMethodPath) {\n if (operationPath.method !== OperationMethods.CUSTOM) {\n const key = this.getKey(operationPath.method, operationPath.path);\n this.updateFinalRouteState(key);\n this.updateFinalRouteState(this.getKey(OperationMethods.ALL, operationPath.path));\n this.setFinalRoute(key, operationPath);\n }\n }\n\n protected getKey = (method: string, path: any) => `${method}-${path}`;\n\n protected updateFinalRouteState(key: string) {\n if (this.has(key)) {\n this.get(key)!.isFinal = false;\n }\n }\n\n protected setFinalRoute(key: string, operationPath: JsonMethodPath) {\n this.set(key, operationPath);\n operationPath.isFinal = true;\n }\n}\n"]}
|
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.JsonOperationRoute = void 0;
|
|
4
4
|
const concatPath_1 = require("../utils/concatPath");
|
|
5
5
|
class JsonOperationRoute {
|
|
6
|
+
token;
|
|
7
|
+
endpoint;
|
|
8
|
+
operationPath;
|
|
9
|
+
basePath;
|
|
10
|
+
paramsTypes;
|
|
6
11
|
constructor(options) {
|
|
7
12
|
Object.assign(this, options);
|
|
8
13
|
this.paramsTypes = this.endpoint.getParamTypes();
|
|
@@ -11,19 +16,16 @@ class JsonOperationRoute {
|
|
|
11
16
|
return this.fullPath;
|
|
12
17
|
}
|
|
13
18
|
get path() {
|
|
14
|
-
|
|
15
|
-
return (_a = this.operationPath) === null || _a === void 0 ? void 0 : _a.path;
|
|
19
|
+
return this.operationPath?.path;
|
|
16
20
|
}
|
|
17
21
|
get fullPath() {
|
|
18
22
|
return (0, concatPath_1.concatPath)(this.basePath, this.path);
|
|
19
23
|
}
|
|
20
24
|
get method() {
|
|
21
|
-
|
|
22
|
-
return ((_a = this.operationPath) === null || _a === void 0 ? void 0 : _a.method) || "USE";
|
|
25
|
+
return this.operationPath?.method || "USE";
|
|
23
26
|
}
|
|
24
27
|
get isFinal() {
|
|
25
|
-
|
|
26
|
-
return !!((_a = this.operationPath) === null || _a === void 0 ? void 0 : _a.isFinal);
|
|
28
|
+
return !!this.operationPath?.isFinal;
|
|
27
29
|
}
|
|
28
30
|
get name() {
|
|
29
31
|
return `${this.endpoint.targetName}.${this.methodClassName}()`;
|
|
@@ -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;IACpB,KAAK,CAAY;IACjB,QAAQ,CAAS;IACjB,aAAa,CAAkB;IAC/B,QAAQ,CAAU;IAClB,WAAW,CAA0B;IAE9C,YAAY,OAAoC;QAC9C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE7B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;IACnD,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC;IAClC,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAA,uBAAU,EAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAW,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,aAAa,EAAE,MAAM,IAAI,KAAK,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,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;AAxED,gDAwEC","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.getParamTypes();\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"]}
|
|
@@ -8,10 +8,10 @@ const JsonMap_1 = require("./JsonMap");
|
|
|
8
8
|
const JsonParameterTypes_1 = require("./JsonParameterTypes");
|
|
9
9
|
const ref_1 = require("../utils/ref");
|
|
10
10
|
class JsonParameter extends JsonMap_1.JsonMap {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
nestedGenerics = [];
|
|
12
|
+
groups;
|
|
13
|
+
$schema;
|
|
14
|
+
expression;
|
|
15
15
|
getName() {
|
|
16
16
|
const name = this.get("name");
|
|
17
17
|
if (this.get("in") === "files") {
|
|
@@ -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,sCAA2C;AAE3C,MAAa,aAAc,SAAQ,iBAAiC;
|
|
1
|
+
{"version":3,"file":"JsonParameter.js","sourceRoot":"","sources":["../../../src/domain/JsonParameter.ts"],"names":[],"mappings":";;;AAAA,qCAAoD;AAG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AM;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,MAAM,EAAE,IAAI;oBACZ,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;iBAC5C,CAAC;aACH,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF;AA1ID,sCA0IC","sourcesContent":["import {cleanObject, toMap, Type} from \"@tsed/core\";\nimport {OpenSpecHash, OpenSpecRef, OS3Example, OS3Parameter, OS3Schema} from \"@tsed/openspec\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\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 {createRefName} from \"../utils/ref\";\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, OS3Schema>(options.schemas || {});\n\n return this.build({...options, groups: this.groups}, schemasContainer);\n }\n\n private build(options: JsonSchemaOptions, schemasContainer: Map<string, OS3Schema>) {\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 switch (this.get(\"in\")) {\n case JsonParameterTypes.FILES:\n return this.getFileSchema(jsonSchema, parameter);\n case JsonParameterTypes.QUERY:\n if (jsonSchema.$ref) {\n if (!parameter.name) {\n return this.refToParameters(parameter, options, schemasContainer);\n }\n\n parameter.style = \"deepObject\";\n }\n break;\n }\n\n parameter.schema = jsonSchema;\n\n return parameter;\n }\n\n private getFileSchema(jsonSchema: any, parameter: Pick<any, string | number | symbol>) {\n const schema = {\n type: \"string\",\n format: \"binary\",\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 private refToParameters(parameter: any, options: JsonSchemaOptions, schemasContainer: Map<string, OS3Schema>) {\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 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}\n"]}
|
|
@@ -8,13 +8,20 @@ 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
|
+
paramType;
|
|
12
|
+
expression;
|
|
13
|
+
dataPath;
|
|
14
|
+
/**
|
|
15
|
+
* Define pipes can be called by the framework to transform input parameter
|
|
16
|
+
*/
|
|
17
|
+
pipes;
|
|
18
|
+
/**
|
|
19
|
+
* Ref to JsonParameter when the decorated object is a parameter.
|
|
20
|
+
*/
|
|
21
|
+
parameter = new JsonParameter_1.JsonParameter();
|
|
22
|
+
parent = JsonEntityStore_1.JsonEntityStore.fromMethod(this.target, this.propertyKey);
|
|
11
23
|
constructor(options) {
|
|
12
24
|
super(options);
|
|
13
|
-
/**
|
|
14
|
-
* Ref to JsonParameter when the decorated object is a parameter.
|
|
15
|
-
*/
|
|
16
|
-
this.parameter = new JsonParameter_1.JsonParameter();
|
|
17
|
-
this.parent = JsonEntityStore_1.JsonEntityStore.fromMethod(this.target, this.propertyKey);
|
|
18
25
|
this.pipes = options.pipes || [];
|
|
19
26
|
this.paramType = options.paramType || this.paramType;
|
|
20
27
|
this.expression = options.expression || this.expression;
|
|
@@ -1 +1 @@
|
|
|
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,kBAAkB,GAA/B,MAAa,kBAAmB,SAAQ,iCAAe;
|
|
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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onEntityStoreOptions} 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"]}
|
|
@@ -7,10 +7,7 @@ const JsonEntityStore_1 = require("./JsonEntityStore");
|
|
|
7
7
|
const JsonSchema_1 = require("./JsonSchema");
|
|
8
8
|
const jsonEntityComponent_1 = require("../decorators/config/jsonEntityComponent");
|
|
9
9
|
let JsonPropertyStore = class JsonPropertyStore extends JsonEntityStore_1.JsonEntityStore {
|
|
10
|
-
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.parent = JsonEntityStore_1.JsonEntityStore.from(this.target);
|
|
13
|
-
}
|
|
10
|
+
parent = JsonEntityStore_1.JsonEntityStore.from(this.target);
|
|
14
11
|
/**
|
|
15
12
|
* Return the required state.
|
|
16
13
|
* @returns {boolean}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;IAC3C,MAAM,GAAmB,iCAAe,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEpE;;;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,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/G,CAAC;IAES,KAAK;QACb,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,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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"]}
|
|
@@ -5,10 +5,7 @@ const mapHeaders_1 = require("../utils/mapHeaders");
|
|
|
5
5
|
const toJsonMapCollection_1 = require("../utils/toJsonMapCollection");
|
|
6
6
|
const JsonMap_1 = require("./JsonMap");
|
|
7
7
|
class JsonMedia extends JsonMap_1.JsonMap {
|
|
8
|
-
|
|
9
|
-
super(...arguments);
|
|
10
|
-
this.groups = [];
|
|
11
|
-
}
|
|
8
|
+
groups = [];
|
|
12
9
|
schema(schema) {
|
|
13
10
|
this.set("schema", schema);
|
|
14
11
|
return this;
|
|
@@ -23,6 +20,7 @@ class JsonMedia extends JsonMap_1.JsonMap {
|
|
|
23
20
|
}
|
|
24
21
|
exports.JsonMedia = JsonMedia;
|
|
25
22
|
class JsonResponse extends JsonMap_1.JsonMap {
|
|
23
|
+
status;
|
|
26
24
|
constructor(obj = {}) {
|
|
27
25
|
super(obj);
|
|
28
26
|
this.content(obj.content || {});
|
|
@@ -43,9 +41,8 @@ class JsonResponse extends JsonMap_1.JsonMap {
|
|
|
43
41
|
return this.get("content");
|
|
44
42
|
}
|
|
45
43
|
getMedia(mediaType, create = true) {
|
|
46
|
-
var _a;
|
|
47
44
|
create && this.addMedia(mediaType);
|
|
48
|
-
return
|
|
45
|
+
return this.getContent()?.get(mediaType);
|
|
49
46
|
}
|
|
50
47
|
addMedia(mediaType) {
|
|
51
48
|
const content = this.get("content");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonResponse.js","sourceRoot":"","sources":["../../../src/domain/JsonResponse.ts"],"names":[],"mappings":";;;AAIA,oDAA+C;AAC/C,sEAAiE;AACjE,uCAAkC;AAMlC,MAAa,SAAU,SAAQ,iBAAiC;
|
|
1
|
+
{"version":3,"file":"JsonResponse.js","sourceRoot":"","sources":["../../../src/domain/JsonResponse.ts"],"names":[],"mappings":";;;AAIA,oDAA+C;AAC/C,sEAAiE;AACjE,uCAAkC;AAMlC,MAAa,SAAU,SAAQ,iBAAiC;IAC9D,MAAM,GAAa,EAAE,CAAC;IAEtB,MAAM,CAAC,MAAkB;QACvB,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC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;IAED,QAAQ,CAAC,SAAiB;QACxB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEpC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;YAC3B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,SAAS,EAAE,CAAC,CAAC;SACzC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,UAA6B,EAAE;QACpC,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEvC,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,EAAE;YACvB,OAAO,QAAQ,CAAC,OAAO,CAAC;SACzB;QAED,IAAI,QAAQ,CAAC,OAAO,EAAE;YACpB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,EAAC,IAAI,EAAE,GAAG,KAAK,EAAC,CAAgB,EAAE,EAAE;gBAClF,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;oBACtB,GAAG,KAAK;oBACR,MAAM,EAAE;wBACN,IAAI;qBACL;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAnED,oCAmEC","sourcesContent":["import {cleanObject} from \"@tsed/core\";\nimport {OS3MediaType, OS3Response} from \"@tsed/openspec\";\nimport {JsonHeader} from \"../interfaces/JsonOpenSpec\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {mapHeaders} from \"../utils/mapHeaders\";\nimport {toJsonMapCollection} from \"../utils/toJsonMapCollection\";\nimport {JsonMap} from \"./JsonMap\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport {SpecTypes} from \"./SpecTypes\";\n\nexport type JsonResponseOptions = OS3Response<JsonSchema, string | JsonHeader>;\n\nexport class JsonMedia extends JsonMap<OS3MediaType<JsonSchema>> {\n groups: string[] = [];\n\n schema(schema: JsonSchema) {\n this.set(\"schema\", schema);\n\n return this;\n }\n\n examples(examples: any) {\n this.set(\"examples\", examples);\n\n return this;\n }\n\n toJSON(options: JsonSchemaOptions = {}): any {\n return super.toJSON({...options, groups: this.groups});\n }\n}\n\nexport class JsonResponse extends JsonMap<JsonResponseOptions> {\n status: number;\n\n constructor(obj: Partial<JsonResponseOptions> = {}) {\n super(obj);\n\n this.content(obj.content || ({} as any));\n }\n\n description(description: string): this {\n this.set(\"description\", description);\n\n return this;\n }\n\n headers(headers: Record<string, string | JsonHeader>): this {\n this.set(\"headers\", mapHeaders(headers));\n\n return this;\n }\n\n content(content: Record<string, OS3MediaType<JsonSchema>>) {\n this.set(\"content\", toJsonMapCollection(content, JsonMedia));\n\n return this;\n }\n\n getContent(): JsonMap<JsonMedia> {\n return this.get(\"content\")!;\n }\n\n getMedia(mediaType: string, create = true): JsonMedia {\n create && this.addMedia(mediaType);\n\n return this.getContent()?.get(mediaType) as any;\n }\n\n addMedia(mediaType: string) {\n const content = this.get(\"content\");\n\n if (!content.has(mediaType)) {\n content.set(mediaType, new JsonMedia());\n }\n\n return this;\n }\n\n toJSON(options: JsonSchemaOptions = {}): any {\n const response = super.toJSON(options);\n\n if (this.status === 204) {\n delete response.content;\n }\n\n if (response.headers) {\n Object.entries(response.headers).forEach(([key, {type, ...props}]: [string, any]) => {\n response.headers[key] = {\n ...props,\n schema: {\n type\n }\n };\n });\n }\n\n return response;\n }\n}\n"]}
|