@tsed/schema 7.13.7 → 7.14.0

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.
@@ -32,7 +32,13 @@ function Groups(...groups) {
32
32
  });
33
33
  break;
34
34
  case core_1.DecoratorTypes.PARAM:
35
+ let groupsName = "";
36
+ if (groups.length == 2 && (0, core_1.isArray)(groups[1])) {
37
+ groupsName = groups[0];
38
+ groups = groups[1];
39
+ }
35
40
  entity.parameter.groups = groups;
41
+ entity.parameter.groupsName = groupsName;
36
42
  break;
37
43
  }
38
44
  });
@@ -1 +1 @@
1
- {"version":3,"file":"groups.js","sourceRoot":"","sources":["../../../../src/decorators/common/groups.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAG1C,yDAAoD;AACpD,iDAA4C;AAE5C;;GAEG;AACH,SAAS,WAAW,CAAC,MAAW,EAAE,MAAsB;IACtD,MAAM,OAAO,GAAyB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QAC1G,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;QAEpC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC;AAaD,SAAgB,MAAM,CAAC,GAAG,MAAW;IACnC,OAAO,IAAA,2BAAY,EAAC,CAAC,MAAM,EAAE,EAAE;QAC7B,QAAQ,MAAM,CAAC,aAAa,EAAE;YAC5B,KAAK,qBAAc,CAAC,KAAK;gBACvB,WAAW,CAAC,MAAM,EAAE,MAAwB,CAAC,CAAC;gBAC9C,MAAM;YACR,KAAK,qBAAc,CAAC,IAAI;gBACtB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAa,EAAE,WAAqB,EAAE,EAAE;oBACzE,IAAI,CAAC,IAAI,EAAE;wBACT,IAAI,IAAA,yBAAW,EAAC,MAAM,EAAE,WAAW,CAAC,EAAE;4BACpC,OAAO,IAAI,CAAC;yBACb;qBACF;oBAED,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,qBAAc,CAAC,KAAK;gBACtB,MAA6B,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;gBACzD,MAAM;SACT;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAtBD,wBAsBC","sourcesContent":["import {DecoratorTypes} from \"@tsed/core\";\nimport type {JsonClassStore} from \"../../domain/JsonClassStore\";\nimport type {JsonParameterStore} from \"../../domain/JsonParameterStore\";\nimport {matchGroups} from \"../../utils/matchGroups\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * @ignore\n */\nfunction groupsClass(groups: any, entity: JsonClassStore) {\n const entries: [string, string[]][] = Object.entries(groups[0]);\n\n entity.children.forEach((propEntity) => {\n const groups = entries.filter(([, props]) => props.includes(propEntity.propertyName)).map(([key]) => key);\n const decorator = Groups(...groups);\n\n decorator(propEntity.target, propEntity.propertyKey);\n });\n}\n\n/**\n * Apply groups validation strategy\n *\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n */\nexport function Groups<T>(groupsDefinition: Record<string, (keyof T)[]>): ClassDecorator;\nexport function Groups(...groups: string[]): Function;\nexport function Groups(...groups: any): any {\n return JsonEntityFn((entity) => {\n switch (entity.decoratorType) {\n case DecoratorTypes.CLASS:\n groupsClass(groups, entity as JsonClassStore);\n break;\n case DecoratorTypes.PROP:\n entity.schema.$hooks.on(\"groups\", (prev: boolean, givenGroups: string[]) => {\n if (!prev) {\n if (matchGroups(groups, givenGroups)) {\n return true;\n }\n }\n\n return prev;\n });\n break;\n case DecoratorTypes.PARAM:\n (entity as JsonParameterStore).parameter.groups = groups;\n break;\n }\n });\n}\n"]}
1
+ {"version":3,"file":"groups.js","sourceRoot":"","sources":["../../../../src/decorators/common/groups.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AAGnD,yDAAoD;AACpD,iDAA4C;AAE5C;;GAEG;AACH,SAAS,WAAW,CAAC,MAAW,EAAE,MAAsB;IACtD,MAAM,OAAO,GAAyB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QAC1G,MAAM,SAAS,GAAQ,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;QAEzC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC;AAcD,SAAgB,MAAM,CAAC,GAAG,MAAW;IACnC,OAAO,IAAA,2BAAY,EAAC,CAAC,MAAM,EAAE,EAAE;QAC7B,QAAQ,MAAM,CAAC,aAAa,EAAE;YAC5B,KAAK,qBAAc,CAAC,KAAK;gBACvB,WAAW,CAAC,MAAM,EAAE,MAAwB,CAAC,CAAC;gBAC9C,MAAM;YACR,KAAK,qBAAc,CAAC,IAAI;gBACtB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAa,EAAE,WAAqB,EAAE,EAAE;oBACzE,IAAI,CAAC,IAAI,EAAE;wBACT,IAAI,IAAA,yBAAW,EAAC,MAAM,EAAE,WAAW,CAAC,EAAE;4BACpC,OAAO,IAAI,CAAC;yBACb;qBACF;oBAED,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,qBAAc,CAAC,KAAK;gBACvB,IAAI,UAAU,GAAG,EAAE,CAAC;gBAEpB,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,IAAA,cAAO,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;oBAC5C,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;oBACvB,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;iBACpB;gBAEA,MAA6B,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;gBACxD,MAA6B,CAAC,SAAS,CAAC,UAAU,GAAG,UAAU,CAAC;gBACjE,MAAM;SACT;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AA9BD,wBA8BC","sourcesContent":["import {DecoratorTypes, isArray} from \"@tsed/core\";\nimport type {JsonClassStore} from \"../../domain/JsonClassStore\";\nimport type {JsonParameterStore} from \"../../domain/JsonParameterStore\";\nimport {matchGroups} from \"../../utils/matchGroups\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * @ignore\n */\nfunction groupsClass(groups: any, entity: JsonClassStore) {\n const entries: [string, string[]][] = Object.entries(groups[0]);\n\n entity.children.forEach((propEntity) => {\n const groups = entries.filter(([, props]) => props.includes(propEntity.propertyName)).map(([key]) => key);\n const decorator: any = Groups(...groups);\n\n decorator(propEntity.target, propEntity.propertyKey);\n });\n}\n\n/**\n * Apply groups validation strategy\n *\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n */\nexport function Groups<T>(groupsDefinition: Record<string, (keyof T)[]>): ClassDecorator;\nexport function Groups<T>(groupName: string, groups: string[]): ParameterDecorator;\nexport function Groups(...groups: string[]): Function;\nexport function Groups(...groups: any): any {\n return JsonEntityFn((entity) => {\n switch (entity.decoratorType) {\n case DecoratorTypes.CLASS:\n groupsClass(groups, entity as JsonClassStore);\n break;\n case DecoratorTypes.PROP:\n entity.schema.$hooks.on(\"groups\", (prev: boolean, givenGroups: string[]) => {\n if (!prev) {\n if (matchGroups(groups, givenGroups)) {\n return true;\n }\n }\n\n return prev;\n });\n break;\n case DecoratorTypes.PARAM:\n let groupsName = \"\";\n\n if (groups.length == 2 && isArray(groups[1])) {\n groupsName = groups[0];\n groups = groups[1];\n }\n\n (entity as JsonParameterStore).parameter.groups = groups;\n (entity as JsonParameterStore).parameter.groupsName = groupsName;\n break;\n }\n });\n}\n"]}
@@ -91,7 +91,13 @@ class ReturnDecoratorContext extends DecoratorContext_1.DecoratorContext {
91
91
  return this;
92
92
  }
93
93
  groups(...groups) {
94
- this.set("groups", groups);
94
+ if (groups.length === 2 && (0, core_1.isArray)(groups[1])) {
95
+ this.set("groupsName", groups[0]);
96
+ this.set("groups", groups[1]);
97
+ }
98
+ else {
99
+ this.set("groups", groups);
100
+ }
95
101
  return this;
96
102
  }
97
103
  allowedGroups(...allowedGroups) {
@@ -216,6 +222,7 @@ class ReturnDecoratorContext extends DecoratorContext_1.DecoratorContext {
216
222
  const media = response.getMedia(contentType || "*/*");
217
223
  const schema = media.get("schema") || new JsonSchema_1.JsonSchema({ type: model });
218
224
  const groups = this.get("groups");
225
+ const groupsName = this.get("groupsName");
219
226
  const allowedGroups = this.get("allowedGroups");
220
227
  const operation = this.entity.operation;
221
228
  if (model) {
@@ -229,6 +236,7 @@ class ReturnDecoratorContext extends DecoratorContext_1.DecoratorContext {
229
236
  this.set("schema", schema);
230
237
  media.schema(schema);
231
238
  media.groups = groups;
239
+ media.groupsName = groupsName;
232
240
  if (allowedGroups) {
233
241
  media.allowedGroups = allowedGroups;
234
242
  const jsonParameter = new JsonParameter_1.JsonParameter();
@@ -1 +1 @@
1
- {"version":3,"file":"returns.js","sourceRoot":"","sources":["../../../../src/decorators/operations/returns.ts"],"names":[],"mappings":";;;AAAA,qCAWoB;AAEpB,2EAAoE;AACpE,oEAA+D;AAC/D,kEAA6D;AAC7D,8DAAyD;AAEzD,wDAAqE;AAErE,qEAA6D;AAC7D,2CAAwC;AAExC,iEAA4D;AAC5D,uDAAkD;AA2HlD;;GAEG;AACH,SAAS,MAAM,CAAC,IAAS;IACvB,OAAO,IAAA,eAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,WAAW,CAAC,KAAqB;IACxC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACxB,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE;YAChB,OAAO,IAAA,aAAM,GAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;SAC3C;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,sBAAuB,SAAQ,mCAA0C;IACpE,OAAO,GAAa;QAC3B,aAAa;QACb,aAAa;QACb,UAAU;QACV,MAAM;QACN,QAAQ;QACR,IAAI;QACJ,WAAW;QACX,OAAO;QACP,OAAO;QACP,OAAO;QACP,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,QAAQ;QACR,OAAO;QACP,QAAQ;QACR,eAAe;QACf,UAAU;KACX,CAAC;IAEF,YAAY,EAAC,MAAM,EAAE,KAAK,EAAM;QAC9B,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,CAAC,KAAU;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,K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,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAEtC,IAAI,QAAQ,EAAE;YACZ,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SAC1B;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,MAAM,CAAC,IAAY,EAAE,KAAY;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE;YAClB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAe,CAAC;YAEhD,IAAI,IAAA,mBAAY,EAAC,KAAK,CAAC,EAAE;gBACvB,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC;gBAE7B,MAAM,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;aACtC;iBAAM;gBACL,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;aACzB;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA+JD,SAAgB,OAAO,CAAC,MAAwB,EAAE,KAAqC;IACrF,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;QACzC,MAAM;QACN,KAAK;KACN,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC;AAPD,0BAOC","sourcesContent":["import {\n decorateMethodsOf,\n decoratorTypeOf,\n DecoratorTypes,\n isArray,\n isCollection,\n isObject,\n isPlainObject,\n isPrimitiveOrPrimitiveClass,\n isString,\n Type\n} from \"@tsed/core\";\nimport {OS3Example} from \"@tsed/openspec\";\nimport {getStatusMessage} from \"../../constants/httpStatusMessages\";\nimport {DecoratorContext} from \"../../domain/DecoratorContext\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\nimport {JsonParameter} from \"../../domain/JsonParameter\";\nimport {JsonResponse} from \"../../domain/JsonResponse\";\nimport {JsonSchema, JsonSchemaObject} from \"../../domain/JsonSchema\";\nimport {JsonHeader, JsonHeaders} from \"../../interfaces/JsonOpenSpec\";\nimport {getStatusModel} from \"../../utils/defineStatusModel\";\nimport {string} from \"../../utils/from\";\nimport {GenericValue} from \"../../utils/generics\";\nimport {isSuccessStatus} from \"../../utils/isSuccessStatus\";\nimport {mapHeaders} from \"../../utils/mapHeaders\";\n\nexport interface ReturnsChainedDecorators {\n <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;\n\n (target: Function): void;\n\n /**\n * Set a Content-Type for the current response\n * @param value\n * @constructor\n */\n ContentType(value: string): this;\n\n /**\n * Add a description\n * @param description\n */\n Description(description: string): this;\n\n /**\n * Add examples\n * @param examples\n */\n Examples(examples: Record<string, OS3Example>): this;\n\n Examples(examples: Record<string, any>): this;\n\n Examples(examples: any): this;\n\n /**\n * Change the model type\n * @param type\n */\n Type(type: Type<any> | any): this;\n\n /**\n * Change the status\n * @param status\n * @constructor\n */\n Status(status: string | number): this;\n\n /**\n * Add the nested types\n * @param types\n */\n Of(...types: GenericValue[]): this;\n\n /**\n * For the integer type\n */\n OfInteger(): this;\n\n /**\n * Add the nested types\n * @param types\n */\n OneOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AllOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AnyOf(...types: GenericValue[]): this;\n\n /**\n * Declare a nested generic models\n * @param generics\n */\n Nested(...generics: GenericValue[]): this;\n\n /**\n * Add header.\n * @param key\n * @param value\n */\n Header(key: string, value: number | string | (JsonHeader & {value?: string | number | boolean})): this;\n\n /**\n * Add headers\n */\n Headers(headers: JsonHeaders): this;\n\n /**\n * Add location hea\n */\n Location(location: string, meta?: JsonHeader): this;\n\n /**\n * Assign partial schema\n * @param schema\n */\n Schema(schema: Partial<JsonSchemaObject> | JsonSchema): this;\n\n /**\n * Add an inline title for the return model.\n * @param title\n */\n Title(title: string): this;\n\n /**\n * Use group to filter model\n * @param groups\n */\n Groups(...groups: string[]): this;\n\n /**\n * Add a list of allowed groups to filter dynamically fields. Listed groups can be used by the consumer to change\n * the mapped response.\n * @param allowedGroups\n */\n AllowedGroups(...allowedGroups: string[]): this;\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nfunction isEnum(type: any) {\n return isObject(type) && !(\"toJSON\" in type);\n}\n\nfunction mapGenerics(types: GenericValue[]) {\n return types.map((type) => {\n if (isEnum(type)) {\n return string().enum(Object.values(type));\n }\n return type;\n });\n}\n\n/**\n * @ignore\n */\nclass ReturnDecoratorContext extends DecoratorContext<ReturnsChainedDecorators> {\n readonly methods: string[] = [\n \"contentType\",\n \"description\",\n \"examples\",\n \"type\",\n \"status\",\n \"of\",\n \"ofInteger\",\n \"oneOf\",\n \"allOf\",\n \"anyOf\",\n \"nested\",\n \"header\",\n \"headers\",\n \"schema\",\n \"title\",\n \"groups\",\n \"allowedGroups\",\n \"location\"\n ];\n\n constructor({status, model}: any) {\n super();\n\n this.model(model);\n this.status(status);\n }\n\n type(model: any) {\n return this.model(model);\n }\n\n model(model: any) {\n model && this.set(\"model\", model);\n return this;\n }\n\n status(status: number | string) {\n this.set(\"status\", status);\n\n if (status && getStatusMessage(status) && !this.get(\"description\")) {\n this.set(\"description\", getStatusMessage(status));\n\n if (!this.get(\"model\")) {\n this.model(getStatusModel(+status));\n }\n }\n\n return this;\n }\n\n headers(headers: JsonHeaders) {\n this.set(\"headers\", {\n ...(this.get(\"headers\") || {}),\n ...mapHeaders(headers)\n });\n\n return this;\n }\n\n header(key: string, value: string | JsonHeader) {\n return this.headers({[key]: value});\n }\n\n location(path: string, meta: JsonHeaders = {}) {\n this.headers({\n Location: {\n ...meta,\n value: path\n }\n });\n\n return this;\n }\n\n groups(...groups: string[]) {\n this.set(\"groups\", groups);\n return this;\n }\n\n allowedGroups(...allowedGroups: string[]) {\n this.set(\"allowedGroups\", new Set(allowedGroups));\n return this;\n }\n\n nested(...generics: GenericValue[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n this.checkCollection(model);\n\n this.addAction((ctx) => {\n (this.get(\"schema\") as JsonSchema).nestedGenerics.push(mapGenerics(generics));\n });\n\n return this;\n }\n\n of(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema?.itemSchema({type: types[0]});\n } else {\n schema?.nestedGenerics.push(mapGenerics(types));\n }\n });\n\n return this;\n }\n\n ofInteger() {\n return this.of(\"integer\");\n }\n\n oneOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"oneOf\", types);\n }\n\n allOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"allOf\", types);\n }\n\n anyOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"anyOf\", types);\n }\n\n schema(partial: Partial<JsonSchemaObject>) {\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n schema!.assign(partial);\n });\n\n return this;\n }\n\n examples(examples: any) {\n this.set(\"examples\", isString(examples) ? [examples] : examples);\n return this;\n }\n\n title(title: string) {\n return this.schema({title});\n }\n\n protected checkPrimitive(model: any) {\n if (isPrimitiveOrPrimitiveClass(model)) {\n throw new Error(\"Returns.Of cannot be used with the following primitive classes: String, Number, Boolean\");\n }\n }\n\n protected checkCollection(model: any) {\n if (isCollection(model)) {\n throw new Error(\"Returns.Nested cannot be used with the following classes: Map, Set, Array, String, Number, Boolean\");\n }\n }\n\n protected getContentType() {\n const model = this.get(\"model\");\n let contentType = this.get(\"contentType\");\n\n if (model && !isPlainObject(model) && !isPrimitiveOrPrimitiveClass(model)) {\n contentType = contentType || \"application/json\";\n }\n\n return contentType;\n }\n\n protected getStatus() {\n return this.get(\"status\") || \"default\";\n }\n\n protected onInit(args: any[], decorator: any) {\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.METHOD:\n this.entity = JsonEntityStore.from(...args);\n if (this.entity.operation) {\n this.map();\n }\n break;\n case DecoratorTypes.CLASS:\n this.decoratorType = DecoratorTypes.CLASS;\n decorateMethodsOf(args[0], decorator);\n break;\n }\n }\n\n protected map() {\n const model = this.get(\"model\");\n const {entity, decoratorType} = this;\n const operation = this.entity.operation!;\n const currentStatus = this.getStatus();\n const response = operation.ensureResponseOf(currentStatus);\n const contentType = this.getContentType();\n\n let {description = response.get(\"description\")} = this.toObject();\n\n if (description) {\n description = decoratorType === DecoratorTypes.CLASS ? response.get(\"description\") || description : description;\n response.description(description);\n }\n\n const headers = this.getMergedKey(\"headers\", response.get(\"headers\"));\n\n if (headers) {\n response.headers(headers);\n }\n\n this.mapMedia(response);\n\n if (isSuccessStatus(this.get(\"status\")) || currentStatus === \"default\") {\n if (model) {\n entity.type = model;\n }\n }\n\n // additional info for OS2\n contentType && operation.addProduce(contentType);\n\n // run additional actions\n return this.runActions();\n }\n\n protected mapMedia(response: JsonResponse) {\n const contentType = this.getContentType();\n const model = this.get(\"model\");\n const media = response.getMedia(contentType || \"*/*\");\n const schema = media.get(\"schema\") || new JsonSchema({type: model});\n const groups = this.get(\"groups\");\n const allowedGroups = this.get(\"allowedGroups\");\n const operation = this.entity.operation!;\n\n if (model) {\n if (isArray(model)) {\n schema.oneOf(model.map((type) => ({type})));\n } else {\n schema.type(model);\n }\n }\n\n this.set(\"schema\", schema);\n\n media.schema(schema);\n\n media.groups = groups;\n\n if (allowedGroups) {\n media.allowedGroups = allowedGroups;\n\n const jsonParameter = new JsonParameter();\n jsonParameter.in(\"query\").name(\"includes\");\n jsonParameter.schema(\n JsonSchema.from({\n type: \"array\",\n items: {\n type: \"string\",\n enum: [...allowedGroups]\n }\n })\n );\n\n operation.addParameter(-1, jsonParameter);\n }\n\n const examples = this.get(\"examples\");\n\n if (examples) {\n media.examples(examples);\n }\n\n return media;\n }\n\n private manyOf(kind: string, types: any[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema.type(model || Object);\n\n schema.itemSchema().set(kind, types);\n } else {\n schema.set(kind, types);\n }\n });\n\n return this;\n }\n}\n\n/**\n * Add responses documentation for a specific status code.\n *\n * ## Usage\n *\n * Ts.ED v5/v6 API introducing the chaining decorator concept. Now a decorator like Returns can be used with another decorators like Description.\n *\n * ::: warning\n * v5 has a basic support of the chaining decorator to facilitate the migration to v6!\n * :::\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @Returns(404, String).Description(\"Not Found\")\n * @Returns(200, Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ::: tip\n * TypeScript and your IDE will discover automatically the chained decorators. But for more details you can look on @@ReturnsChainedDecorators@@ interface, to know\n * what chained decorators are available under Returns decorator.\n * :::\n *\n * This example will produce this documentation in swagger:\n *\n * ```json\n * {\n * \"responses\": {\n * \"404\": {\n * \"description\": \"Description\",\n * \"schema\": {\"type\": \"string\"}\n * },\n * \"2OO\": {\n * \"description\": \"Description\",\n * \"schema\": {\"$ref\": \"...\"}\n * }\n * }\n * }\n * ```\n *\n * ## Declaring an Array\n *\n * Use chained decorators to declare an array with model as following:\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/models\")\n * class ModelCtrl {\n * @Get(\"/\")\n * @Returns(200, Array).Of(Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {\n * }\n * }\n * ```\n *\n * Deprecated version:\n *\n * ```typescript\n * import {ReturnsArray} from \"@tsed/common\";\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @ReturnsArray(200, Model) // deprecated\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ### Declaring a generic model <Badge text=\"6+\"/>\n *\n * Sometime, it might be useful to use generic models. TypeScript doesn't store the generic type in the metadata. This is why we need to\n * declare explicitly the generic models with the decorators.\n *\n * One of the generic's usage, can be a paginated list. With Returns decorator it's now possible to declare generic type and generate the appropriate OpenSpec documentation.\n *\n * Starting with the pagination model, by using @@Generics@@ and @@CollectionOf@@:\n *\n * ```typescript\n * @Generics(\"T\")\n * class Pagination<T> {\n * @CollectionOf(\"T\")\n * data: T[];\n *\n * @Property()\n * totalCount: number;\n * }\n * ```\n *\n * Now, we need a model to be used with the generic Pagination model:\n *\n * ```typescript\n * class Product {\n * @Property()\n * id: string;\n *\n * @Property()\n * title: string;\n * }\n * ```\n *\n * Finally, we can use our models on a method as following:\n *\n * ```typescript\n * class Controller {\n * @OperationPath(\"POST\", \"/\")\n * @Returns(200, Pagination).Of(Product).Description(\"description\")\n * async method(): Promise<Pagination<Product> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * ### Declaring a nested generics models <Badge text=\"6+\"/>\n *\n * It's also possible to declare a nested generics models in order to have this type `Pagination<Submission<Product>>`:\n *\n * ```typescript\n * import {Generics, Property, Returns} from \"@tsed/schema\";\n * import {Post} from \"@tsed/common\";\n *\n * class Controller {\n * @Post(\"/\")\n * @Returns(200, Pagination).Of(Submission).Nested(Product).Description(\"description\")\n * async method(): Promise<Pagination<Submission<Product>> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * And here is the Submission model:\n *\n * ```typescript\n * import {Generics, Property} from \"@tsed/schema\";\n *\n * @Generics(\"T\")\n * class Submission<T> {\n * @Property()\n * _id: string;\n * @Property(\"T\")\n * data: T;\n * }\n * ```\n *\n * @param status\n * @param model\n * @decorator\n * @swagger\n * @schema\n * @response\n * @operation\n */\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[]): ReturnsChainedDecorators;\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[] | any): ReturnsChainedDecorators {\n const context = new ReturnDecoratorContext({\n status,\n model\n });\n\n return context.build();\n}\n"]}
1
+ {"version":3,"file":"returns.js","sourceRoot":"","sources":["../../../../src/decorators/operations/returns.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TypeOf,\n DecoratorTypes,\n isArray,\n isCollection,\n isObject,\n isPlainObject,\n isPrimitiveOrPrimitiveClass,\n isString,\n Type\n} from \"@tsed/core\";\nimport {OS3Example} from \"@tsed/openspec\";\nimport {getStatusMessage} from \"../../constants/httpStatusMessages\";\nimport {DecoratorContext} from \"../../domain/DecoratorContext\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\nimport {JsonParameter} from \"../../domain/JsonParameter\";\nimport {JsonResponse} from \"../../domain/JsonResponse\";\nimport {JsonSchema, JsonSchemaObject} from \"../../domain/JsonSchema\";\nimport {JsonHeader, JsonHeaders} from \"../../interfaces/JsonOpenSpec\";\nimport {getStatusModel} from \"../../utils/defineStatusModel\";\nimport {string} from \"../../utils/from\";\nimport {GenericValue} from \"../../utils/generics\";\nimport {isSuccessStatus} from \"../../utils/isSuccessStatus\";\nimport {mapHeaders} from \"../../utils/mapHeaders\";\n\nexport interface ReturnsChainedDecorators {\n <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;\n\n (target: Function): void;\n\n /**\n * Set a Content-Type for the current response\n * @param value\n * @constructor\n */\n ContentType(value: string): this;\n\n /**\n * Add a description\n * @param description\n */\n Description(description: string): this;\n\n /**\n * Add examples\n * @param examples\n */\n Examples(examples: Record<string, OS3Example>): this;\n\n Examples(examples: Record<string, any>): this;\n\n Examples(examples: any): this;\n\n /**\n * Change the model type\n * @param type\n */\n Type(type: Type<any> | any): this;\n\n /**\n * Change the status\n * @param status\n * @constructor\n */\n Status(status: string | number): this;\n\n /**\n * Add the nested types\n * @param types\n */\n Of(...types: GenericValue[]): this;\n\n /**\n * For the integer type\n */\n OfInteger(): this;\n\n /**\n * Add the nested types\n * @param types\n */\n OneOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AllOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AnyOf(...types: GenericValue[]): this;\n\n /**\n * Declare a nested generic models\n * @param generics\n */\n Nested(...generics: GenericValue[]): this;\n\n /**\n * Add header.\n * @param key\n * @param value\n */\n Header(key: string, value: number | string | (JsonHeader & {value?: string | number | boolean})): this;\n\n /**\n * Add headers\n */\n Headers(headers: JsonHeaders): this;\n\n /**\n * Add location hea\n */\n Location(location: string, meta?: JsonHeader): this;\n\n /**\n * Assign partial schema\n * @param schema\n */\n Schema(schema: Partial<JsonSchemaObject> | JsonSchema): this;\n\n /**\n * Add an inline title for the return model.\n * @param title\n */\n Title(title: string): this;\n\n /**\n * Use group to filter model\n * @param groups\n */\n Groups(...groups: string[]): this;\n\n Groups(groupName: string, groups: string[]): this;\n\n /**\n * Add a list of allowed groups to filter dynamically fields. Listed groups can be used by the consumer to change\n * the mapped response.\n * @param allowedGroups\n */\n AllowedGroups(...allowedGroups: string[]): this;\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nfunction isEnum(type: any) {\n return isObject(type) && !(\"toJSON\" in type);\n}\n\nfunction mapGenerics(types: GenericValue[]) {\n return types.map((type) => {\n if (isEnum(type)) {\n return string().enum(Object.values(type));\n }\n return type;\n });\n}\n\n/**\n * @ignore\n */\nclass ReturnDecoratorContext extends DecoratorContext<ReturnsChainedDecorators> {\n readonly methods: string[] = [\n \"contentType\",\n \"description\",\n \"examples\",\n \"type\",\n \"status\",\n \"of\",\n \"ofInteger\",\n \"oneOf\",\n \"allOf\",\n \"anyOf\",\n \"nested\",\n \"header\",\n \"headers\",\n \"schema\",\n \"title\",\n \"groups\",\n \"allowedGroups\",\n \"location\"\n ];\n\n constructor({status, model}: any) {\n super();\n\n this.model(model);\n this.status(status);\n }\n\n type(model: any) {\n return this.model(model);\n }\n\n model(model: any) {\n model && this.set(\"model\", model);\n return this;\n }\n\n status(status: number | string) {\n this.set(\"status\", status);\n\n if (status && getStatusMessage(status) && !this.get(\"description\")) {\n this.set(\"description\", getStatusMessage(status));\n\n if (!this.get(\"model\")) {\n this.model(getStatusModel(+status));\n }\n }\n\n return this;\n }\n\n headers(headers: JsonHeaders) {\n this.set(\"headers\", {\n ...(this.get(\"headers\") || {}),\n ...mapHeaders(headers)\n });\n\n return this;\n }\n\n header(key: string, value: string | JsonHeader) {\n return this.headers({[key]: value});\n }\n\n location(path: string, meta: JsonHeaders = {}) {\n this.headers({\n Location: {\n ...meta,\n value: path\n }\n });\n\n return this;\n }\n\n groups(groupName: string, groups: string[]): this;\n groups(...groups: string[]): this;\n groups(...groups: string[] | [string, string[]]) {\n if (groups.length === 2 && isArray(groups[1])) {\n this.set(\"groupsName\", groups[0]);\n this.set(\"groups\", groups[1]);\n } else {\n this.set(\"groups\", groups);\n }\n\n return this;\n }\n\n allowedGroups(...allowedGroups: string[]) {\n this.set(\"allowedGroups\", new Set(allowedGroups));\n return this;\n }\n\n nested(...generics: GenericValue[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n this.checkCollection(model);\n\n this.addAction((ctx) => {\n (this.get(\"schema\") as JsonSchema).nestedGenerics.push(mapGenerics(generics));\n });\n\n return this;\n }\n\n of(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema?.itemSchema({type: types[0]});\n } else {\n schema?.nestedGenerics.push(mapGenerics(types));\n }\n });\n\n return this;\n }\n\n ofInteger() {\n return this.of(\"integer\");\n }\n\n oneOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"oneOf\", types);\n }\n\n allOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"allOf\", types);\n }\n\n anyOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"anyOf\", types);\n }\n\n schema(partial: Partial<JsonSchemaObject>) {\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n schema!.assign(partial);\n });\n\n return this;\n }\n\n examples(examples: any) {\n this.set(\"examples\", isString(examples) ? [examples] : examples);\n return this;\n }\n\n title(title: string) {\n return this.schema({title});\n }\n\n protected checkPrimitive(model: any) {\n if (isPrimitiveOrPrimitiveClass(model)) {\n throw new Error(\"Returns.Of cannot be used with the following primitive classes: String, Number, Boolean\");\n }\n }\n\n protected checkCollection(model: any) {\n if (isCollection(model)) {\n throw new Error(\"Returns.Nested cannot be used with the following classes: Map, Set, Array, String, Number, Boolean\");\n }\n }\n\n protected getContentType() {\n const model = this.get(\"model\");\n let contentType = this.get(\"contentType\");\n\n if (model && !isPlainObject(model) && !isPrimitiveOrPrimitiveClass(model)) {\n contentType = contentType || \"application/json\";\n }\n\n return contentType;\n }\n\n protected getStatus() {\n return this.get(\"status\") || \"default\";\n }\n\n protected onInit(args: any[], decorator: any) {\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.METHOD:\n this.entity = JsonEntityStore.from(...args);\n if (this.entity.operation) {\n this.map();\n }\n break;\n case DecoratorTypes.CLASS:\n this.decoratorType = DecoratorTypes.CLASS;\n decorateMethodsOf(args[0], decorator);\n break;\n }\n }\n\n protected map() {\n const model = this.get(\"model\");\n const {entity, decoratorType} = this;\n const operation = this.entity.operation!;\n const currentStatus = this.getStatus();\n const response = operation.ensureResponseOf(currentStatus);\n const contentType = this.getContentType();\n\n let {description = response.get(\"description\")} = this.toObject();\n\n if (description) {\n description = decoratorType === DecoratorTypes.CLASS ? response.get(\"description\") || description : description;\n response.description(description);\n }\n\n const headers = this.getMergedKey(\"headers\", response.get(\"headers\"));\n\n if (headers) {\n response.headers(headers);\n }\n\n this.mapMedia(response);\n\n if (isSuccessStatus(this.get(\"status\")) || currentStatus === \"default\") {\n if (model) {\n entity.type = model;\n }\n }\n\n // additional info for OS2\n contentType && operation.addProduce(contentType);\n\n // run additional actions\n return this.runActions();\n }\n\n protected mapMedia(response: JsonResponse) {\n const contentType = this.getContentType();\n const model = this.get(\"model\");\n const media = response.getMedia(contentType || \"*/*\");\n const schema = media.get(\"schema\") || new JsonSchema({type: model});\n const groups = this.get(\"groups\");\n const groupsName = this.get(\"groupsName\");\n const allowedGroups = this.get(\"allowedGroups\");\n const operation = this.entity.operation!;\n\n if (model) {\n if (isArray(model)) {\n schema.oneOf(model.map((type) => ({type})));\n } else {\n schema.type(model);\n }\n }\n\n this.set(\"schema\", schema);\n\n media.schema(schema);\n\n media.groups = groups;\n media.groupsName = groupsName;\n\n if (allowedGroups) {\n media.allowedGroups = allowedGroups;\n\n const jsonParameter = new JsonParameter();\n jsonParameter.in(\"query\").name(\"includes\");\n jsonParameter.schema(\n JsonSchema.from({\n type: \"array\",\n items: {\n type: \"string\",\n enum: [...allowedGroups]\n }\n })\n );\n\n operation.addParameter(-1, jsonParameter);\n }\n\n const examples = this.get(\"examples\");\n\n if (examples) {\n media.examples(examples);\n }\n\n return media;\n }\n\n private manyOf(kind: string, types: any[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema.type(model || Object);\n\n schema.itemSchema().set(kind, types);\n } else {\n schema.set(kind, types);\n }\n });\n\n return this;\n }\n}\n\n/**\n * Add responses documentation for a specific status code.\n *\n * ## Usage\n *\n * Ts.ED v5/v6 API introducing the chaining decorator concept. Now a decorator like Returns can be used with another decorators like Description.\n *\n * ::: warning\n * v5 has a basic support of the chaining decorator to facilitate the migration to v6!\n * :::\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @Returns(404, String).Description(\"Not Found\")\n * @Returns(200, Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ::: tip\n * TypeScript and your IDE will discover automatically the chained decorators. But for more details you can look on @@ReturnsChainedDecorators@@ interface, to know\n * what chained decorators are available under Returns decorator.\n * :::\n *\n * This example will produce this documentation in swagger:\n *\n * ```json\n * {\n * \"responses\": {\n * \"404\": {\n * \"description\": \"Description\",\n * \"schema\": {\"type\": \"string\"}\n * },\n * \"2OO\": {\n * \"description\": \"Description\",\n * \"schema\": {\"$ref\": \"...\"}\n * }\n * }\n * }\n * ```\n *\n * ## Declaring an Array\n *\n * Use chained decorators to declare an array with model as following:\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/models\")\n * class ModelCtrl {\n * @Get(\"/\")\n * @Returns(200, Array).Of(Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {\n * }\n * }\n * ```\n *\n * Deprecated version:\n *\n * ```typescript\n * import {ReturnsArray} from \"@tsed/common\";\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @ReturnsArray(200, Model) // deprecated\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ### Declaring a generic model <Badge text=\"6+\"/>\n *\n * Sometime, it might be useful to use generic models. TypeScript doesn't store the generic type in the metadata. This is why we need to\n * declare explicitly the generic models with the decorators.\n *\n * One of the generic's usage, can be a paginated list. With Returns decorator it's now possible to declare generic type and generate the appropriate OpenSpec documentation.\n *\n * Starting with the pagination model, by using @@Generics@@ and @@CollectionOf@@:\n *\n * ```typescript\n * @Generics(\"T\")\n * class Pagination<T> {\n * @CollectionOf(\"T\")\n * data: T[];\n *\n * @Property()\n * totalCount: number;\n * }\n * ```\n *\n * Now, we need a model to be used with the generic Pagination model:\n *\n * ```typescript\n * class Product {\n * @Property()\n * id: string;\n *\n * @Property()\n * title: string;\n * }\n * ```\n *\n * Finally, we can use our models on a method as following:\n *\n * ```typescript\n * class Controller {\n * @OperationPath(\"POST\", \"/\")\n * @Returns(200, Pagination).Of(Product).Description(\"description\")\n * async method(): Promise<Pagination<Product> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * ### Declaring a nested generics models <Badge text=\"6+\"/>\n *\n * It's also possible to declare a nested generics models in order to have this type `Pagination<Submission<Product>>`:\n *\n * ```typescript\n * import {Generics, Property, Returns} from \"@tsed/schema\";\n * import {Post} from \"@tsed/common\";\n *\n * class Controller {\n * @Post(\"/\")\n * @Returns(200, Pagination).Of(Submission).Nested(Product).Description(\"description\")\n * async method(): Promise<Pagination<Submission<Product>> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * And here is the Submission model:\n *\n * ```typescript\n * import {Generics, Property} from \"@tsed/schema\";\n *\n * @Generics(\"T\")\n * class Submission<T> {\n * @Property()\n * _id: string;\n * @Property(\"T\")\n * data: T;\n * }\n * ```\n *\n * @param status\n * @param model\n * @decorator\n * @swagger\n * @schema\n * @response\n * @operation\n */\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[]): ReturnsChainedDecorators;\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[] | any): ReturnsChainedDecorators {\n const context = new ReturnDecoratorContext({\n status,\n model\n });\n\n return context.build();\n}\n"]}
@@ -4,12 +4,13 @@ exports.JsonParameter = void 0;
4
4
  const core_1 = require("@tsed/core");
5
5
  const JsonSchemaMapperContainer_1 = require("../registries/JsonSchemaMapperContainer");
6
6
  const generics_1 = require("../utils/generics");
7
+ const ref_1 = require("../utils/ref");
7
8
  const JsonMap_1 = require("./JsonMap");
8
9
  const JsonParameterTypes_1 = require("./JsonParameterTypes");
9
- const ref_1 = require("../utils/ref");
10
10
  class JsonParameter extends JsonMap_1.JsonMap {
11
11
  nestedGenerics = [];
12
12
  groups;
13
+ groupsName;
13
14
  $schema;
14
15
  expression;
15
16
  getName() {
@@ -49,7 +50,7 @@ class JsonParameter extends JsonMap_1.JsonMap {
49
50
  return null;
50
51
  }
51
52
  const schemasContainer = (0, core_1.toMap)(options.schemas || {});
52
- return this.build({ ...options, groups: this.groups }, schemasContainer);
53
+ return this.build({ ...options, groups: this.groups, groupsName: this.groupsName }, schemasContainer);
53
54
  }
54
55
  build(options, schemasContainer) {
55
56
  const { type, schema, ...parameter } = super.toJSON(options);
@@ -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,6D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Z,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"]}
1
+ {"version":3,"file":"JsonParameter.js","sourceRoot":"","sources":["../../../src/domain/JsonParameter.ts"],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AAE,EAAC,WAAW,EAAE,GAAG,IAAI,EAAC,CAAgB,EAAE,EAAE;YAC7G,OAAO;gBACL,GAAG,MAAM;gBACT,IAAA,kBAAW,EAAC;oBACV,GAAG,SAAS;oBACZ,IAAI,EAAE,GAAG;oBACT,QAAQ,EAAE,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;oBAC/C,WAAW;oBACX,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;AA3ID,sCA2IC","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 {createRefName} from \"../utils/ref\";\nimport {JsonMap} from \"./JsonMap\";\nimport {formatParameterType, isParameterType, JsonParameterTypes} from \"./JsonParameterTypes\";\nimport {JsonSchema} from \"./JsonSchema\";\n\nexport class JsonParameter extends JsonMap<OS3Parameter<JsonSchema>> implements NestedGenerics {\n nestedGenerics: Type<any>[][] = [];\n groups: string[];\n groupsName: 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, groupsName: this.groupsName}, 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"]}
@@ -6,6 +6,7 @@ const toJsonMapCollection_1 = require("../utils/toJsonMapCollection");
6
6
  const JsonMap_1 = require("./JsonMap");
7
7
  class JsonMedia extends JsonMap_1.JsonMap {
8
8
  groups = [];
9
+ groupsName;
9
10
  allowedGroups;
10
11
  schema(schema) {
11
12
  this.set("schema", schema);
@@ -17,7 +18,7 @@ class JsonMedia extends JsonMap_1.JsonMap {
17
18
  }
18
19
  toJSON(options = {}) {
19
20
  let groups = [...(this.groups || [])];
20
- return super.toJSON({ ...options, groups });
21
+ return super.toJSON({ ...options, groups, groupsName: this.groupsName });
21
22
  }
22
23
  }
23
24
  exports.JsonMedia = JsonMedia;
@@ -1 +1 @@
1
- {"version":3,"file":"JsonResponse.js","sourceRoot":"","sources":["../../../src/domain/JsonResponse.ts"],"names":[],"mappings":";;;AAGA,oDAA+C;AAC/C,sEAAiE;AACjE,uCAAkC;AAKlC,MAAa,SAAU,SAAQ,iBAAiC;IAC9D,MAAM,GAAa,EAAE,CAAC;IACtB,aAAa,CAAe;IAE5B,MAAM,CAAC,MAAkB;QACvB,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ,CAAC,QAAa;QACpB,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAE/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,UAA6B,EAAE;QACpC,IAAI,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;QAEtC,OAAO,KAAK,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MAAM,EAAC,CAAC,CAAC;IAC5C,CAAC;CACF;AArBD,8BAqBC;AAED,MAAa,YAAa,SA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AC,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 {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\";\n\nexport type JsonResponseOptions = OS3Response<JsonSchema, string | JsonHeader>;\n\nexport class JsonMedia extends JsonMap<OS3MediaType<JsonSchema>> {\n groups: string[] = [];\n allowedGroups?: Set<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 let groups = [...(this.groups || [])];\n\n return super.toJSON({...options, 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"]}
1
+ {"version":3,"file":"JsonResponse.js","sourceRoot":"","sources":["../../../src/domain/JsonResponse.ts"],"names":[],"mappings":";;;AAGA,oDAA+C;AAC/C,sEAAiE;AACjE,uCAAkC;AAKlC,MAAa,SAAU,SAAQ,iBAAiC;IAC9D,MAAM,GAAa,EAAE,CAAC;IACtB,UAAU,CAAS;IACnB,aAAa,CAAe;IAE5B,MAAM,CAAC,MAAkB;QACvB,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ,CAAC,QAAa;QACpB,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAE/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,UAA6B,EAAE;QACpC,IAAI,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;QAEtC,OAAO,KAAK,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MA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AAI,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 {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\";\n\nexport type JsonResponseOptions = OS3Response<JsonSchema, string | JsonHeader>;\n\nexport class JsonMedia extends JsonMap<OS3MediaType<JsonSchema>> {\n groups: string[] = [];\n groupsName: string;\n allowedGroups?: Set<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 let groups = [...(this.groups || [])];\n\n return super.toJSON({...options, groups, groupsName: this.groupsName});\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"JsonSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/JsonSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {OpenSpecHash, OS2Schema, OS3Schema} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\n\nexport interface JsonSchemaOptions {\n /**\n * Map properties with the alias name. By default: false\n */\n useAlias?: boolean;\n /**\n * Reference to Schema Object.\n */\n schemas?: OpenSpecHash<OS3Schema | OS2Schema>;\n /**\n * Define Spec types level\n */\n specType?: SpecTypes;\n /**\n * Define a groups restriction to generate the JsonSchema.\n * Set false to disable groups.\n */\n groups?: string[] | false;\n /**\n * Generate custom keys when SpecType is JSON.\n */\n customKeys?: boolean;\n\n [key: string]: any;\n}\n"]}
1
+ {"version":3,"file":"JsonSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/JsonSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {OpenSpecHash, OS2Schema, OS3Schema} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\n\nexport interface JsonSchemaOptions {\n /**\n * Map properties with the alias name. By default: false\n */\n useAlias?: boolean;\n /**\n * Reference to Schema Object.\n */\n schemas?: OpenSpecHash<OS3Schema | OS2Schema>;\n /**\n * Define Spec types level\n */\n specType?: SpecTypes;\n /**\n * Define a groups restriction to generate the JsonSchema.\n * Set false to disable groups.\n */\n groups?: string[] | false;\n /**\n * Set the postfix groups name for generated model and ref.\n */\n groupsName?: string;\n /**\n * Generate custom keys when SpecType is JSON.\n */\n customKeys?: boolean;\n\n [key: string]: any;\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toRef = exports.createRef = exports.createRefName = void 0;
4
+ const core_1 = require("@tsed/core");
4
5
  const change_case_1 = require("change-case");
5
6
  const SpecTypes_1 = require("../domain/SpecTypes");
6
- const core_1 = require("@tsed/core");
7
7
  /**
8
8
  * ignore
9
9
  * @param options
@@ -17,7 +17,7 @@ function getHost(options) {
17
17
  */
18
18
  function createRefName(name, options) {
19
19
  if (options.groups && options.groups.length) {
20
- return (0, change_case_1.pascalCase)(`${name} ${options.groups.join(" ")}`);
20
+ return (0, change_case_1.pascalCase)(`${name} ${options.groupsName || options.groups.join(" ")}`);
21
21
  }
22
22
  return name;
23
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/utils/ref.ts"],"names":[],"mappings":";;;AAAA,6CAAuC;AAEvC,mDAA8C;AAE9C,qCAAuC;AAEvC;;;GAGG;AACH,SAAS,OAAO,CAAC,OAA0B;IACzC,MAAM,EAAC,IAAI,GAAG,KAAK,OAAO,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,oBAAoB,CA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C;oBACjB,QAAQ;oBACR,SAAS;oBACT,KAAK,EAAE,CAAC,GAAG,CAAC;iBACb,CAAC,CAAC;SACN;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AA7BD,8BA6BC;AAED;;GAEG;AACH,SAAgB,KAAK,CAAC,KAAiB,EAAE,MAAW,EAAE,OAA0B;IAC9E,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,CAAC,OAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC;IAE3C,OAAO,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAND,sBAMC","sourcesContent":["import {pascalCase} from \"change-case\";\nimport type {JsonSchema} from \"../domain/JsonSchema\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {cleanObject} from \"@tsed/core\";\n\n/**\n * ignore\n * @param options\n */\nfunction getHost(options: JsonSchemaOptions) {\n const {host = `#/${options.specType === \"openapi3\" ? \"components/schemas\" : \"definitions\"}`} = options;\n\n return host;\n}\n\n/**\n * @ignore\n */\nexport function createRefName(name: string, options: JsonSchemaOptions) {\n if (options.groups && options.groups.length) {\n return pascalCase(`${name} ${options.groups.join(\" \")}`);\n }\n\n return name;\n}\n\n/**\n * @ignore\n */\nexport function createRef(name: string, schema: JsonSchema, options: JsonSchemaOptions) {\n const host = getHost(options);\n const ref = {\n $ref: `${host}/${name}`\n };\n\n const nullable = schema.isNullable;\n const readOnly = schema.isReadOnly;\n const writeOnly = schema.isWriteOnly;\n\n if (nullable || readOnly || writeOnly) {\n switch (options.specType) {\n case SpecTypes.OPENAPI:\n return cleanObject({\n nullable: nullable ? true : undefined,\n readOnly: readOnly ? true : undefined,\n writeOnly: writeOnly ? true : undefined,\n oneOf: [ref]\n });\n case SpecTypes.JSON:\n return cleanObject({\n readOnly,\n writeOnly,\n oneOf: [ref]\n });\n }\n }\n\n return ref;\n}\n\n/**\n * @ignore\n */\nexport function toRef(value: JsonSchema, schema: any, options: JsonSchemaOptions) {\n const name = createRefName(value.getName(), options);\n\n options.schemas![value.getName()] = schema;\n\n return createRef(name, value, options);\n}\n"]}
1
+ {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/utils/ref.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AACvC,6CAAuC;AAEvC,mDAA8C;AAG9C;;;GAGG;AACH,SAAS,OAAO,CAAC,OAA0B;IACzC,MAAM,EAAC,IAAI,GAAG,KAAK,OAAO,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,aAAa,EAAE,EAAC,GAAG,OAAO,CAAC;IAEvG,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAY,EAAE,OAA0B;IACpE,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;QAC3C,OAAO,IAAA,wBAAU,EAAC,GAAG,IAAI,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;KAChF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAND,sCAMC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,IAAY,EAAE,MAAkB,EAAE,OAA0B;IACpF,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,MAAM,GAAG,GAAG;QACV,IAAI,EAAE,GAAG,IAAI,IAAI,IAAI,EAAE;KACxB,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC;IACnC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC;IACnC,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC;IAErC,IAAI,QAAQ,IAAI,QAAQ,IAAI,SAAS,EAAE;QACrC,QAAQ,OAAO,CAAC,QAAQ,EAAE;YACxB,KAAK,qBAAS,CAAC,OAAO;gBACpB,OAAO,IAAA,kBAAW,EAAC;oBACjB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;oBACrC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;oBACrC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;oBACvC,KAAK,EAAE,CAAC,GAAG,CAAC;iBACb,CAAC,CAAC;YACL,KAAK,qBAAS,CAAC,IAAI;gBACjB,OAAO,IAAA,kBAAW,EAAC;oBACjB,QAAQ;oBACR,SAAS;oBACT,KAAK,EAAE,CAAC,GAAG,CAAC;iBACb,CAAC,CAAC;SACN;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AA7BD,8BA6BC;AAED;;GAEG;AACH,SAAgB,KAAK,CAAC,KAAiB,EAAE,MAAW,EAAE,OAA0B;IAC9E,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,CAAC,OAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC;IAE3C,OAAO,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAND,sBAMC","sourcesContent":["import {cleanObject} from \"@tsed/core\";\nimport {pascalCase} from \"change-case\";\nimport type {JsonSchema} from \"../domain/JsonSchema\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\n\n/**\n * ignore\n * @param options\n */\nfunction getHost(options: JsonSchemaOptions) {\n const {host = `#/${options.specType === \"openapi3\" ? \"components/schemas\" : \"definitions\"}`} = options;\n\n return host;\n}\n\n/**\n * @ignore\n */\nexport function createRefName(name: string, options: JsonSchemaOptions) {\n if (options.groups && options.groups.length) {\n return pascalCase(`${name} ${options.groupsName || options.groups.join(\" \")}`);\n }\n\n return name;\n}\n\n/**\n * @ignore\n */\nexport function createRef(name: string, schema: JsonSchema, options: JsonSchemaOptions) {\n const host = getHost(options);\n const ref = {\n $ref: `${host}/${name}`\n };\n\n const nullable = schema.isNullable;\n const readOnly = schema.isReadOnly;\n const writeOnly = schema.isWriteOnly;\n\n if (nullable || readOnly || writeOnly) {\n switch (options.specType) {\n case SpecTypes.OPENAPI:\n return cleanObject({\n nullable: nullable ? true : undefined,\n readOnly: readOnly ? true : undefined,\n writeOnly: writeOnly ? true : undefined,\n oneOf: [ref]\n });\n case SpecTypes.JSON:\n return cleanObject({\n readOnly,\n writeOnly,\n oneOf: [ref]\n });\n }\n }\n\n return ref;\n}\n\n/**\n * @ignore\n */\nexport function toRef(value: JsonSchema, schema: any, options: JsonSchemaOptions) {\n const name = createRefName(value.getName(), options);\n\n options.schemas![value.getName()] = schema;\n\n return createRef(name, value, options);\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { DecoratorTypes } from "@tsed/core";
1
+ import { DecoratorTypes, isArray } from "@tsed/core";
2
2
  import { matchGroups } from "../../utils/matchGroups.js";
3
3
  import { JsonEntityFn } from "./jsonEntityFn.js";
4
4
  /**
@@ -29,7 +29,13 @@ export function Groups(...groups) {
29
29
  });
30
30
  break;
31
31
  case DecoratorTypes.PARAM:
32
+ let groupsName = "";
33
+ if (groups.length == 2 && isArray(groups[1])) {
34
+ groupsName = groups[0];
35
+ groups = groups[1];
36
+ }
32
37
  entity.parameter.groups = groups;
38
+ entity.parameter.groupsName = groupsName;
33
39
  break;
34
40
  }
35
41
  });
@@ -1 +1 @@
1
- {"version":3,"file":"groups.js","sourceRoot":"","sources":["../../../../src/decorators/common/groups.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AA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C,CAAC;gBACH,MAAM;YACR,KAAK,cAAc,CAAC,KAAK;gBACtB,MAA6B,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;gBACzD,MAAM;SACT;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {DecoratorTypes} from \"@tsed/core\";\nimport type {JsonClassStore} from \"../../domain/JsonClassStore\";\nimport type {JsonParameterStore} from \"../../domain/JsonParameterStore\";\nimport {matchGroups} from \"../../utils/matchGroups\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * @ignore\n */\nfunction groupsClass(groups: any, entity: JsonClassStore) {\n const entries: [string, string[]][] = Object.entries(groups[0]);\n\n entity.children.forEach((propEntity) => {\n const groups = entries.filter(([, props]) => props.includes(propEntity.propertyName)).map(([key]) => key);\n const decorator = Groups(...groups);\n\n decorator(propEntity.target, propEntity.propertyKey);\n });\n}\n\n/**\n * Apply groups validation strategy\n *\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n */\nexport function Groups<T>(groupsDefinition: Record<string, (keyof T)[]>): ClassDecorator;\nexport function Groups(...groups: string[]): Function;\nexport function Groups(...groups: any): any {\n return JsonEntityFn((entity) => {\n switch (entity.decoratorType) {\n case DecoratorTypes.CLASS:\n groupsClass(groups, entity as JsonClassStore);\n break;\n case DecoratorTypes.PROP:\n entity.schema.$hooks.on(\"groups\", (prev: boolean, givenGroups: string[]) => {\n if (!prev) {\n if (matchGroups(groups, givenGroups)) {\n return true;\n }\n }\n\n return prev;\n });\n break;\n case DecoratorTypes.PARAM:\n (entity as JsonParameterStore).parameter.groups = groups;\n break;\n }\n });\n}\n"]}
1
+ {"version":3,"file":"groups.js","sourceRoot":"","sources":["../../../../src/decorators/common/groups.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC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AE,CAAC;gBAEpB,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;oBAC5C,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;oBACvB,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;iBACpB;gBAEA,MAA6B,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;gBACxD,MAA6B,CAAC,SAAS,CAAC,UAAU,GAAG,UAAU,CAAC;gBACjE,MAAM;SACT;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {DecoratorTypes, isArray} from \"@tsed/core\";\nimport type {JsonClassStore} from \"../../domain/JsonClassStore\";\nimport type {JsonParameterStore} from \"../../domain/JsonParameterStore\";\nimport {matchGroups} from \"../../utils/matchGroups\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\n\n/**\n * @ignore\n */\nfunction groupsClass(groups: any, entity: JsonClassStore) {\n const entries: [string, string[]][] = Object.entries(groups[0]);\n\n entity.children.forEach((propEntity) => {\n const groups = entries.filter(([, props]) => props.includes(propEntity.propertyName)).map(([key]) => key);\n const decorator: any = Groups(...groups);\n\n decorator(propEntity.target, propEntity.propertyKey);\n });\n}\n\n/**\n * Apply groups validation strategy\n *\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n */\nexport function Groups<T>(groupsDefinition: Record<string, (keyof T)[]>): ClassDecorator;\nexport function Groups<T>(groupName: string, groups: string[]): ParameterDecorator;\nexport function Groups(...groups: string[]): Function;\nexport function Groups(...groups: any): any {\n return JsonEntityFn((entity) => {\n switch (entity.decoratorType) {\n case DecoratorTypes.CLASS:\n groupsClass(groups, entity as JsonClassStore);\n break;\n case DecoratorTypes.PROP:\n entity.schema.$hooks.on(\"groups\", (prev: boolean, givenGroups: string[]) => {\n if (!prev) {\n if (matchGroups(groups, givenGroups)) {\n return true;\n }\n }\n\n return prev;\n });\n break;\n case DecoratorTypes.PARAM:\n let groupsName = \"\";\n\n if (groups.length == 2 && isArray(groups[1])) {\n groupsName = groups[0];\n groups = groups[1];\n }\n\n (entity as JsonParameterStore).parameter.groups = groups;\n (entity as JsonParameterStore).parameter.groupsName = groupsName;\n break;\n }\n });\n}\n"]}
@@ -88,7 +88,13 @@ class ReturnDecoratorContext extends DecoratorContext {
88
88
  return this;
89
89
  }
90
90
  groups(...groups) {
91
- this.set("groups", groups);
91
+ if (groups.length === 2 && isArray(groups[1])) {
92
+ this.set("groupsName", groups[0]);
93
+ this.set("groups", groups[1]);
94
+ }
95
+ else {
96
+ this.set("groups", groups);
97
+ }
92
98
  return this;
93
99
  }
94
100
  allowedGroups(...allowedGroups) {
@@ -213,6 +219,7 @@ class ReturnDecoratorContext extends DecoratorContext {
213
219
  const media = response.getMedia(contentType || "*/*");
214
220
  const schema = media.get("schema") || new JsonSchema({ type: model });
215
221
  const groups = this.get("groups");
222
+ const groupsName = this.get("groupsName");
216
223
  const allowedGroups = this.get("allowedGroups");
217
224
  const operation = this.entity.operation;
218
225
  if (model) {
@@ -226,6 +233,7 @@ class ReturnDecoratorContext extends DecoratorContext {
226
233
  this.set("schema", schema);
227
234
  media.schema(schema);
228
235
  media.groups = groups;
236
+ media.groupsName = groupsName;
229
237
  if (allowedGroups) {
230
238
  media.allowedGroups = allowedGroups;
231
239
  const jsonParameter = new JsonParameter();
@@ -1 +1 @@
1
- {"version":3,"file":"returns.js","sourceRoot":"","sources":["../../../../src/decorators/operations/returns.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,2BAA2B,EAC3B,QAAQ,EAET,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAC,gBAAgB,EAAC,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA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AAE;YACZ,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SAC1B;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,MAAM,CAAC,IAAY,EAAE,KAAY;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE;YAClB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAe,CAAC;YAEhD,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;gBACvB,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC;gBAE7B,MAAM,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;aACtC;iBAAM;gBACL,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;aACzB;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA+JD,MAAM,UAAU,OAAO,CAAC,MAAwB,EAAE,KAAqC;IACrF,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;QACzC,MAAM;QACN,KAAK;KACN,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import {\n decorateMethodsOf,\n decoratorTypeOf,\n DecoratorTypes,\n isArray,\n isCollection,\n isObject,\n isPlainObject,\n isPrimitiveOrPrimitiveClass,\n isString,\n Type\n} from \"@tsed/core\";\nimport {OS3Example} from \"@tsed/openspec\";\nimport {getStatusMessage} from \"../../constants/httpStatusMessages\";\nimport {DecoratorContext} from \"../../domain/DecoratorContext\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\nimport {JsonParameter} from \"../../domain/JsonParameter\";\nimport {JsonResponse} from \"../../domain/JsonResponse\";\nimport {JsonSchema, JsonSchemaObject} from \"../../domain/JsonSchema\";\nimport {JsonHeader, JsonHeaders} from \"../../interfaces/JsonOpenSpec\";\nimport {getStatusModel} from \"../../utils/defineStatusModel\";\nimport {string} from \"../../utils/from\";\nimport {GenericValue} from \"../../utils/generics\";\nimport {isSuccessStatus} from \"../../utils/isSuccessStatus\";\nimport {mapHeaders} from \"../../utils/mapHeaders\";\n\nexport interface ReturnsChainedDecorators {\n <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;\n\n (target: Function): void;\n\n /**\n * Set a Content-Type for the current response\n * @param value\n * @constructor\n */\n ContentType(value: string): this;\n\n /**\n * Add a description\n * @param description\n */\n Description(description: string): this;\n\n /**\n * Add examples\n * @param examples\n */\n Examples(examples: Record<string, OS3Example>): this;\n\n Examples(examples: Record<string, any>): this;\n\n Examples(examples: any): this;\n\n /**\n * Change the model type\n * @param type\n */\n Type(type: Type<any> | any): this;\n\n /**\n * Change the status\n * @param status\n * @constructor\n */\n Status(status: string | number): this;\n\n /**\n * Add the nested types\n * @param types\n */\n Of(...types: GenericValue[]): this;\n\n /**\n * For the integer type\n */\n OfInteger(): this;\n\n /**\n * Add the nested types\n * @param types\n */\n OneOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AllOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AnyOf(...types: GenericValue[]): this;\n\n /**\n * Declare a nested generic models\n * @param generics\n */\n Nested(...generics: GenericValue[]): this;\n\n /**\n * Add header.\n * @param key\n * @param value\n */\n Header(key: string, value: number | string | (JsonHeader & {value?: string | number | boolean})): this;\n\n /**\n * Add headers\n */\n Headers(headers: JsonHeaders): this;\n\n /**\n * Add location hea\n */\n Location(location: string, meta?: JsonHeader): this;\n\n /**\n * Assign partial schema\n * @param schema\n */\n Schema(schema: Partial<JsonSchemaObject> | JsonSchema): this;\n\n /**\n * Add an inline title for the return model.\n * @param title\n */\n Title(title: string): this;\n\n /**\n * Use group to filter model\n * @param groups\n */\n Groups(...groups: string[]): this;\n\n /**\n * Add a list of allowed groups to filter dynamically fields. Listed groups can be used by the consumer to change\n * the mapped response.\n * @param allowedGroups\n */\n AllowedGroups(...allowedGroups: string[]): this;\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nfunction isEnum(type: any) {\n return isObject(type) && !(\"toJSON\" in type);\n}\n\nfunction mapGenerics(types: GenericValue[]) {\n return types.map((type) => {\n if (isEnum(type)) {\n return string().enum(Object.values(type));\n }\n return type;\n });\n}\n\n/**\n * @ignore\n */\nclass ReturnDecoratorContext extends DecoratorContext<ReturnsChainedDecorators> {\n readonly methods: string[] = [\n \"contentType\",\n \"description\",\n \"examples\",\n \"type\",\n \"status\",\n \"of\",\n \"ofInteger\",\n \"oneOf\",\n \"allOf\",\n \"anyOf\",\n \"nested\",\n \"header\",\n \"headers\",\n \"schema\",\n \"title\",\n \"groups\",\n \"allowedGroups\",\n \"location\"\n ];\n\n constructor({status, model}: any) {\n super();\n\n this.model(model);\n this.status(status);\n }\n\n type(model: any) {\n return this.model(model);\n }\n\n model(model: any) {\n model && this.set(\"model\", model);\n return this;\n }\n\n status(status: number | string) {\n this.set(\"status\", status);\n\n if (status && getStatusMessage(status) && !this.get(\"description\")) {\n this.set(\"description\", getStatusMessage(status));\n\n if (!this.get(\"model\")) {\n this.model(getStatusModel(+status));\n }\n }\n\n return this;\n }\n\n headers(headers: JsonHeaders) {\n this.set(\"headers\", {\n ...(this.get(\"headers\") || {}),\n ...mapHeaders(headers)\n });\n\n return this;\n }\n\n header(key: string, value: string | JsonHeader) {\n return this.headers({[key]: value});\n }\n\n location(path: string, meta: JsonHeaders = {}) {\n this.headers({\n Location: {\n ...meta,\n value: path\n }\n });\n\n return this;\n }\n\n groups(...groups: string[]) {\n this.set(\"groups\", groups);\n return this;\n }\n\n allowedGroups(...allowedGroups: string[]) {\n this.set(\"allowedGroups\", new Set(allowedGroups));\n return this;\n }\n\n nested(...generics: GenericValue[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n this.checkCollection(model);\n\n this.addAction((ctx) => {\n (this.get(\"schema\") as JsonSchema).nestedGenerics.push(mapGenerics(generics));\n });\n\n return this;\n }\n\n of(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema?.itemSchema({type: types[0]});\n } else {\n schema?.nestedGenerics.push(mapGenerics(types));\n }\n });\n\n return this;\n }\n\n ofInteger() {\n return this.of(\"integer\");\n }\n\n oneOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"oneOf\", types);\n }\n\n allOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"allOf\", types);\n }\n\n anyOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"anyOf\", types);\n }\n\n schema(partial: Partial<JsonSchemaObject>) {\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n schema!.assign(partial);\n });\n\n return this;\n }\n\n examples(examples: any) {\n this.set(\"examples\", isString(examples) ? [examples] : examples);\n return this;\n }\n\n title(title: string) {\n return this.schema({title});\n }\n\n protected checkPrimitive(model: any) {\n if (isPrimitiveOrPrimitiveClass(model)) {\n throw new Error(\"Returns.Of cannot be used with the following primitive classes: String, Number, Boolean\");\n }\n }\n\n protected checkCollection(model: any) {\n if (isCollection(model)) {\n throw new Error(\"Returns.Nested cannot be used with the following classes: Map, Set, Array, String, Number, Boolean\");\n }\n }\n\n protected getContentType() {\n const model = this.get(\"model\");\n let contentType = this.get(\"contentType\");\n\n if (model && !isPlainObject(model) && !isPrimitiveOrPrimitiveClass(model)) {\n contentType = contentType || \"application/json\";\n }\n\n return contentType;\n }\n\n protected getStatus() {\n return this.get(\"status\") || \"default\";\n }\n\n protected onInit(args: any[], decorator: any) {\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.METHOD:\n this.entity = JsonEntityStore.from(...args);\n if (this.entity.operation) {\n this.map();\n }\n break;\n case DecoratorTypes.CLASS:\n this.decoratorType = DecoratorTypes.CLASS;\n decorateMethodsOf(args[0], decorator);\n break;\n }\n }\n\n protected map() {\n const model = this.get(\"model\");\n const {entity, decoratorType} = this;\n const operation = this.entity.operation!;\n const currentStatus = this.getStatus();\n const response = operation.ensureResponseOf(currentStatus);\n const contentType = this.getContentType();\n\n let {description = response.get(\"description\")} = this.toObject();\n\n if (description) {\n description = decoratorType === DecoratorTypes.CLASS ? response.get(\"description\") || description : description;\n response.description(description);\n }\n\n const headers = this.getMergedKey(\"headers\", response.get(\"headers\"));\n\n if (headers) {\n response.headers(headers);\n }\n\n this.mapMedia(response);\n\n if (isSuccessStatus(this.get(\"status\")) || currentStatus === \"default\") {\n if (model) {\n entity.type = model;\n }\n }\n\n // additional info for OS2\n contentType && operation.addProduce(contentType);\n\n // run additional actions\n return this.runActions();\n }\n\n protected mapMedia(response: JsonResponse) {\n const contentType = this.getContentType();\n const model = this.get(\"model\");\n const media = response.getMedia(contentType || \"*/*\");\n const schema = media.get(\"schema\") || new JsonSchema({type: model});\n const groups = this.get(\"groups\");\n const allowedGroups = this.get(\"allowedGroups\");\n const operation = this.entity.operation!;\n\n if (model) {\n if (isArray(model)) {\n schema.oneOf(model.map((type) => ({type})));\n } else {\n schema.type(model);\n }\n }\n\n this.set(\"schema\", schema);\n\n media.schema(schema);\n\n media.groups = groups;\n\n if (allowedGroups) {\n media.allowedGroups = allowedGroups;\n\n const jsonParameter = new JsonParameter();\n jsonParameter.in(\"query\").name(\"includes\");\n jsonParameter.schema(\n JsonSchema.from({\n type: \"array\",\n items: {\n type: \"string\",\n enum: [...allowedGroups]\n }\n })\n );\n\n operation.addParameter(-1, jsonParameter);\n }\n\n const examples = this.get(\"examples\");\n\n if (examples) {\n media.examples(examples);\n }\n\n return media;\n }\n\n private manyOf(kind: string, types: any[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema.type(model || Object);\n\n schema.itemSchema().set(kind, types);\n } else {\n schema.set(kind, types);\n }\n });\n\n return this;\n }\n}\n\n/**\n * Add responses documentation for a specific status code.\n *\n * ## Usage\n *\n * Ts.ED v5/v6 API introducing the chaining decorator concept. Now a decorator like Returns can be used with another decorators like Description.\n *\n * ::: warning\n * v5 has a basic support of the chaining decorator to facilitate the migration to v6!\n * :::\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @Returns(404, String).Description(\"Not Found\")\n * @Returns(200, Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ::: tip\n * TypeScript and your IDE will discover automatically the chained decorators. But for more details you can look on @@ReturnsChainedDecorators@@ interface, to know\n * what chained decorators are available under Returns decorator.\n * :::\n *\n * This example will produce this documentation in swagger:\n *\n * ```json\n * {\n * \"responses\": {\n * \"404\": {\n * \"description\": \"Description\",\n * \"schema\": {\"type\": \"string\"}\n * },\n * \"2OO\": {\n * \"description\": \"Description\",\n * \"schema\": {\"$ref\": \"...\"}\n * }\n * }\n * }\n * ```\n *\n * ## Declaring an Array\n *\n * Use chained decorators to declare an array with model as following:\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/models\")\n * class ModelCtrl {\n * @Get(\"/\")\n * @Returns(200, Array).Of(Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {\n * }\n * }\n * ```\n *\n * Deprecated version:\n *\n * ```typescript\n * import {ReturnsArray} from \"@tsed/common\";\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @ReturnsArray(200, Model) // deprecated\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ### Declaring a generic model <Badge text=\"6+\"/>\n *\n * Sometime, it might be useful to use generic models. TypeScript doesn't store the generic type in the metadata. This is why we need to\n * declare explicitly the generic models with the decorators.\n *\n * One of the generic's usage, can be a paginated list. With Returns decorator it's now possible to declare generic type and generate the appropriate OpenSpec documentation.\n *\n * Starting with the pagination model, by using @@Generics@@ and @@CollectionOf@@:\n *\n * ```typescript\n * @Generics(\"T\")\n * class Pagination<T> {\n * @CollectionOf(\"T\")\n * data: T[];\n *\n * @Property()\n * totalCount: number;\n * }\n * ```\n *\n * Now, we need a model to be used with the generic Pagination model:\n *\n * ```typescript\n * class Product {\n * @Property()\n * id: string;\n *\n * @Property()\n * title: string;\n * }\n * ```\n *\n * Finally, we can use our models on a method as following:\n *\n * ```typescript\n * class Controller {\n * @OperationPath(\"POST\", \"/\")\n * @Returns(200, Pagination).Of(Product).Description(\"description\")\n * async method(): Promise<Pagination<Product> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * ### Declaring a nested generics models <Badge text=\"6+\"/>\n *\n * It's also possible to declare a nested generics models in order to have this type `Pagination<Submission<Product>>`:\n *\n * ```typescript\n * import {Generics, Property, Returns} from \"@tsed/schema\";\n * import {Post} from \"@tsed/common\";\n *\n * class Controller {\n * @Post(\"/\")\n * @Returns(200, Pagination).Of(Submission).Nested(Product).Description(\"description\")\n * async method(): Promise<Pagination<Submission<Product>> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * And here is the Submission model:\n *\n * ```typescript\n * import {Generics, Property} from \"@tsed/schema\";\n *\n * @Generics(\"T\")\n * class Submission<T> {\n * @Property()\n * _id: string;\n * @Property(\"T\")\n * data: T;\n * }\n * ```\n *\n * @param status\n * @param model\n * @decorator\n * @swagger\n * @schema\n * @response\n * @operation\n */\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[]): ReturnsChainedDecorators;\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[] | any): ReturnsChainedDecorators {\n const context = new ReturnDecoratorContext({\n status,\n model\n });\n\n return context.build();\n}\n"]}
1
+ {"version":3,"file":"returns.js","sourceRoot":"","sources":["../../../../src/decorators/operations/returns.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,OAAO,EACP,YAAY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,CAAC;CACF;AA+JD,MAAM,UAAU,OAAO,CAAC,MAAwB,EAAE,KAAqC;IACrF,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;QACzC,MAAM;QACN,KAAK;KACN,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import {\n decorateMethodsOf,\n decoratorTypeOf,\n DecoratorTypes,\n isArray,\n isCollection,\n isObject,\n isPlainObject,\n isPrimitiveOrPrimitiveClass,\n isString,\n Type\n} from \"@tsed/core\";\nimport {OS3Example} from \"@tsed/openspec\";\nimport {getStatusMessage} from \"../../constants/httpStatusMessages\";\nimport {DecoratorContext} from \"../../domain/DecoratorContext\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\nimport {JsonParameter} from \"../../domain/JsonParameter\";\nimport {JsonResponse} from \"../../domain/JsonResponse\";\nimport {JsonSchema, JsonSchemaObject} from \"../../domain/JsonSchema\";\nimport {JsonHeader, JsonHeaders} from \"../../interfaces/JsonOpenSpec\";\nimport {getStatusModel} from \"../../utils/defineStatusModel\";\nimport {string} from \"../../utils/from\";\nimport {GenericValue} from \"../../utils/generics\";\nimport {isSuccessStatus} from \"../../utils/isSuccessStatus\";\nimport {mapHeaders} from \"../../utils/mapHeaders\";\n\nexport interface ReturnsChainedDecorators {\n <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;\n\n (target: Function): void;\n\n /**\n * Set a Content-Type for the current response\n * @param value\n * @constructor\n */\n ContentType(value: string): this;\n\n /**\n * Add a description\n * @param description\n */\n Description(description: string): this;\n\n /**\n * Add examples\n * @param examples\n */\n Examples(examples: Record<string, OS3Example>): this;\n\n Examples(examples: Record<string, any>): this;\n\n Examples(examples: any): this;\n\n /**\n * Change the model type\n * @param type\n */\n Type(type: Type<any> | any): this;\n\n /**\n * Change the status\n * @param status\n * @constructor\n */\n Status(status: string | number): this;\n\n /**\n * Add the nested types\n * @param types\n */\n Of(...types: GenericValue[]): this;\n\n /**\n * For the integer type\n */\n OfInteger(): this;\n\n /**\n * Add the nested types\n * @param types\n */\n OneOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AllOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AnyOf(...types: GenericValue[]): this;\n\n /**\n * Declare a nested generic models\n * @param generics\n */\n Nested(...generics: GenericValue[]): this;\n\n /**\n * Add header.\n * @param key\n * @param value\n */\n Header(key: string, value: number | string | (JsonHeader & {value?: string | number | boolean})): this;\n\n /**\n * Add headers\n */\n Headers(headers: JsonHeaders): this;\n\n /**\n * Add location hea\n */\n Location(location: string, meta?: JsonHeader): this;\n\n /**\n * Assign partial schema\n * @param schema\n */\n Schema(schema: Partial<JsonSchemaObject> | JsonSchema): this;\n\n /**\n * Add an inline title for the return model.\n * @param title\n */\n Title(title: string): this;\n\n /**\n * Use group to filter model\n * @param groups\n */\n Groups(...groups: string[]): this;\n\n Groups(groupName: string, groups: string[]): this;\n\n /**\n * Add a list of allowed groups to filter dynamically fields. Listed groups can be used by the consumer to change\n * the mapped response.\n * @param allowedGroups\n */\n AllowedGroups(...allowedGroups: string[]): this;\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nfunction isEnum(type: any) {\n return isObject(type) && !(\"toJSON\" in type);\n}\n\nfunction mapGenerics(types: GenericValue[]) {\n return types.map((type) => {\n if (isEnum(type)) {\n return string().enum(Object.values(type));\n }\n return type;\n });\n}\n\n/**\n * @ignore\n */\nclass ReturnDecoratorContext extends DecoratorContext<ReturnsChainedDecorators> {\n readonly methods: string[] = [\n \"contentType\",\n \"description\",\n \"examples\",\n \"type\",\n \"status\",\n \"of\",\n \"ofInteger\",\n \"oneOf\",\n \"allOf\",\n \"anyOf\",\n \"nested\",\n \"header\",\n \"headers\",\n \"schema\",\n \"title\",\n \"groups\",\n \"allowedGroups\",\n \"location\"\n ];\n\n constructor({status, model}: any) {\n super();\n\n this.model(model);\n this.status(status);\n }\n\n type(model: any) {\n return this.model(model);\n }\n\n model(model: any) {\n model && this.set(\"model\", model);\n return this;\n }\n\n status(status: number | string) {\n this.set(\"status\", status);\n\n if (status && getStatusMessage(status) && !this.get(\"description\")) {\n this.set(\"description\", getStatusMessage(status));\n\n if (!this.get(\"model\")) {\n this.model(getStatusModel(+status));\n }\n }\n\n return this;\n }\n\n headers(headers: JsonHeaders) {\n this.set(\"headers\", {\n ...(this.get(\"headers\") || {}),\n ...mapHeaders(headers)\n });\n\n return this;\n }\n\n header(key: string, value: string | JsonHeader) {\n return this.headers({[key]: value});\n }\n\n location(path: string, meta: JsonHeaders = {}) {\n this.headers({\n Location: {\n ...meta,\n value: path\n }\n });\n\n return this;\n }\n\n groups(groupName: string, groups: string[]): this;\n groups(...groups: string[]): this;\n groups(...groups: string[] | [string, string[]]) {\n if (groups.length === 2 && isArray(groups[1])) {\n this.set(\"groupsName\", groups[0]);\n this.set(\"groups\", groups[1]);\n } else {\n this.set(\"groups\", groups);\n }\n\n return this;\n }\n\n allowedGroups(...allowedGroups: string[]) {\n this.set(\"allowedGroups\", new Set(allowedGroups));\n return this;\n }\n\n nested(...generics: GenericValue[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n this.checkCollection(model);\n\n this.addAction((ctx) => {\n (this.get(\"schema\") as JsonSchema).nestedGenerics.push(mapGenerics(generics));\n });\n\n return this;\n }\n\n of(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema?.itemSchema({type: types[0]});\n } else {\n schema?.nestedGenerics.push(mapGenerics(types));\n }\n });\n\n return this;\n }\n\n ofInteger() {\n return this.of(\"integer\");\n }\n\n oneOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"oneOf\", types);\n }\n\n allOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"allOf\", types);\n }\n\n anyOf(...types: (Type<any> | any)[]) {\n return this.manyOf(\"anyOf\", types);\n }\n\n schema(partial: Partial<JsonSchemaObject>) {\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n schema!.assign(partial);\n });\n\n return this;\n }\n\n examples(examples: any) {\n this.set(\"examples\", isString(examples) ? [examples] : examples);\n return this;\n }\n\n title(title: string) {\n return this.schema({title});\n }\n\n protected checkPrimitive(model: any) {\n if (isPrimitiveOrPrimitiveClass(model)) {\n throw new Error(\"Returns.Of cannot be used with the following primitive classes: String, Number, Boolean\");\n }\n }\n\n protected checkCollection(model: any) {\n if (isCollection(model)) {\n throw new Error(\"Returns.Nested cannot be used with the following classes: Map, Set, Array, String, Number, Boolean\");\n }\n }\n\n protected getContentType() {\n const model = this.get(\"model\");\n let contentType = this.get(\"contentType\");\n\n if (model && !isPlainObject(model) && !isPrimitiveOrPrimitiveClass(model)) {\n contentType = contentType || \"application/json\";\n }\n\n return contentType;\n }\n\n protected getStatus() {\n return this.get(\"status\") || \"default\";\n }\n\n protected onInit(args: any[], decorator: any) {\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.METHOD:\n this.entity = JsonEntityStore.from(...args);\n if (this.entity.operation) {\n this.map();\n }\n break;\n case DecoratorTypes.CLASS:\n this.decoratorType = DecoratorTypes.CLASS;\n decorateMethodsOf(args[0], decorator);\n break;\n }\n }\n\n protected map() {\n const model = this.get(\"model\");\n const {entity, decoratorType} = this;\n const operation = this.entity.operation!;\n const currentStatus = this.getStatus();\n const response = operation.ensureResponseOf(currentStatus);\n const contentType = this.getContentType();\n\n let {description = response.get(\"description\")} = this.toObject();\n\n if (description) {\n description = decoratorType === DecoratorTypes.CLASS ? response.get(\"description\") || description : description;\n response.description(description);\n }\n\n const headers = this.getMergedKey(\"headers\", response.get(\"headers\"));\n\n if (headers) {\n response.headers(headers);\n }\n\n this.mapMedia(response);\n\n if (isSuccessStatus(this.get(\"status\")) || currentStatus === \"default\") {\n if (model) {\n entity.type = model;\n }\n }\n\n // additional info for OS2\n contentType && operation.addProduce(contentType);\n\n // run additional actions\n return this.runActions();\n }\n\n protected mapMedia(response: JsonResponse) {\n const contentType = this.getContentType();\n const model = this.get(\"model\");\n const media = response.getMedia(contentType || \"*/*\");\n const schema = media.get(\"schema\") || new JsonSchema({type: model});\n const groups = this.get(\"groups\");\n const groupsName = this.get(\"groupsName\");\n const allowedGroups = this.get(\"allowedGroups\");\n const operation = this.entity.operation!;\n\n if (model) {\n if (isArray(model)) {\n schema.oneOf(model.map((type) => ({type})));\n } else {\n schema.type(model);\n }\n }\n\n this.set(\"schema\", schema);\n\n media.schema(schema);\n\n media.groups = groups;\n media.groupsName = groupsName;\n\n if (allowedGroups) {\n media.allowedGroups = allowedGroups;\n\n const jsonParameter = new JsonParameter();\n jsonParameter.in(\"query\").name(\"includes\");\n jsonParameter.schema(\n JsonSchema.from({\n type: \"array\",\n items: {\n type: \"string\",\n enum: [...allowedGroups]\n }\n })\n );\n\n operation.addParameter(-1, jsonParameter);\n }\n\n const examples = this.get(\"examples\");\n\n if (examples) {\n media.examples(examples);\n }\n\n return media;\n }\n\n private manyOf(kind: string, types: any[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema.type(model || Object);\n\n schema.itemSchema().set(kind, types);\n } else {\n schema.set(kind, types);\n }\n });\n\n return this;\n }\n}\n\n/**\n * Add responses documentation for a specific status code.\n *\n * ## Usage\n *\n * Ts.ED v5/v6 API introducing the chaining decorator concept. Now a decorator like Returns can be used with another decorators like Description.\n *\n * ::: warning\n * v5 has a basic support of the chaining decorator to facilitate the migration to v6!\n * :::\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @Returns(404, String).Description(\"Not Found\")\n * @Returns(200, Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ::: tip\n * TypeScript and your IDE will discover automatically the chained decorators. But for more details you can look on @@ReturnsChainedDecorators@@ interface, to know\n * what chained decorators are available under Returns decorator.\n * :::\n *\n * This example will produce this documentation in swagger:\n *\n * ```json\n * {\n * \"responses\": {\n * \"404\": {\n * \"description\": \"Description\",\n * \"schema\": {\"type\": \"string\"}\n * },\n * \"2OO\": {\n * \"description\": \"Description\",\n * \"schema\": {\"$ref\": \"...\"}\n * }\n * }\n * }\n * ```\n *\n * ## Declaring an Array\n *\n * Use chained decorators to declare an array with model as following:\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/models\")\n * class ModelCtrl {\n * @Get(\"/\")\n * @Returns(200, Array).Of(Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {\n * }\n * }\n * ```\n *\n * Deprecated version:\n *\n * ```typescript\n * import {ReturnsArray} from \"@tsed/common\";\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @ReturnsArray(200, Model) // deprecated\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ### Declaring a generic model <Badge text=\"6+\"/>\n *\n * Sometime, it might be useful to use generic models. TypeScript doesn't store the generic type in the metadata. This is why we need to\n * declare explicitly the generic models with the decorators.\n *\n * One of the generic's usage, can be a paginated list. With Returns decorator it's now possible to declare generic type and generate the appropriate OpenSpec documentation.\n *\n * Starting with the pagination model, by using @@Generics@@ and @@CollectionOf@@:\n *\n * ```typescript\n * @Generics(\"T\")\n * class Pagination<T> {\n * @CollectionOf(\"T\")\n * data: T[];\n *\n * @Property()\n * totalCount: number;\n * }\n * ```\n *\n * Now, we need a model to be used with the generic Pagination model:\n *\n * ```typescript\n * class Product {\n * @Property()\n * id: string;\n *\n * @Property()\n * title: string;\n * }\n * ```\n *\n * Finally, we can use our models on a method as following:\n *\n * ```typescript\n * class Controller {\n * @OperationPath(\"POST\", \"/\")\n * @Returns(200, Pagination).Of(Product).Description(\"description\")\n * async method(): Promise<Pagination<Product> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * ### Declaring a nested generics models <Badge text=\"6+\"/>\n *\n * It's also possible to declare a nested generics models in order to have this type `Pagination<Submission<Product>>`:\n *\n * ```typescript\n * import {Generics, Property, Returns} from \"@tsed/schema\";\n * import {Post} from \"@tsed/common\";\n *\n * class Controller {\n * @Post(\"/\")\n * @Returns(200, Pagination).Of(Submission).Nested(Product).Description(\"description\")\n * async method(): Promise<Pagination<Submission<Product>> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * And here is the Submission model:\n *\n * ```typescript\n * import {Generics, Property} from \"@tsed/schema\";\n *\n * @Generics(\"T\")\n * class Submission<T> {\n * @Property()\n * _id: string;\n * @Property(\"T\")\n * data: T;\n * }\n * ```\n *\n * @param status\n * @param model\n * @decorator\n * @swagger\n * @schema\n * @response\n * @operation\n */\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[]): ReturnsChainedDecorators;\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[] | any): ReturnsChainedDecorators {\n const context = new ReturnDecoratorContext({\n status,\n model\n });\n\n return context.build();\n}\n"]}
@@ -1,12 +1,13 @@
1
1
  import { cleanObject, toMap } from "@tsed/core";
2
2
  import { execMapper } from "../registries/JsonSchemaMapperContainer.js";
3
3
  import { popGenerics } from "../utils/generics.js";
4
+ import { createRefName } from "../utils/ref.js";
4
5
  import { JsonMap } from "./JsonMap.js";
5
6
  import { formatParameterType, isParameterType, JsonParameterTypes } from "./JsonParameterTypes.js";
6
- import { createRefName } from "../utils/ref.js";
7
7
  export class JsonParameter extends JsonMap {
8
8
  nestedGenerics = [];
9
9
  groups;
10
+ groupsName;
10
11
  $schema;
11
12
  expression;
12
13
  getName() {
@@ -46,7 +47,7 @@ export class JsonParameter extends JsonMap {
46
47
  return null;
47
48
  }
48
49
  const schemasContainer = toMap(options.schemas || {});
49
- return this.build({ ...options, groups: this.groups }, schemasContainer);
50
+ return this.build({ ...options, groups: this.groups, groupsName: this.groupsName }, schemasContainer);
50
51
  }
51
52
  build(options, schemasContainer) {
52
53
  const { type, schema, ...parameter } = super.toJSON(options);