@tsed/schema 8.13.5 → 8.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.
Files changed (87) hide show
  1. package/lib/esm/components/default/anyMapper.js +1 -2
  2. package/lib/esm/components/default/classMapper.js +2 -22
  3. package/lib/esm/components/default/genericsMapper.js +62 -48
  4. package/lib/esm/components/default/lazyRefMapper.js +1 -2
  5. package/lib/esm/components/default/mapMapper.js +0 -2
  6. package/lib/esm/components/default/nextMapper.js +74 -0
  7. package/lib/esm/components/default/objectMapper.js +8 -3
  8. package/lib/esm/components/default/ofMapper.js +2 -5
  9. package/lib/esm/components/default/requiredMapper.js +2 -2
  10. package/lib/esm/components/default/schemaMapper.js +6 -7
  11. package/lib/esm/components/index.js +1 -7
  12. package/lib/esm/components/open-spec/nullableMapper.js +5 -1
  13. package/lib/esm/components/open-spec/operationInParameterMapper.js +3 -7
  14. package/lib/esm/components/open-spec/operationInQueryMapper.js +22 -17
  15. package/lib/esm/components/open-spec/operationMediaMapper.js +5 -2
  16. package/lib/esm/components/open-spec/operationRequestBodyMapper.js +2 -2
  17. package/lib/esm/constants/VendorKeys.js +11 -0
  18. package/lib/esm/decorators/collections/collectionOf.js +14 -3
  19. package/lib/esm/decorators/common/description.js +9 -12
  20. package/lib/esm/decorators/common/discriminatorKey.js +1 -1
  21. package/lib/esm/decorators/common/forwardGroups.js +1 -1
  22. package/lib/esm/decorators/common/groups.js +15 -26
  23. package/lib/esm/decorators/common/oneOf.js +1 -1
  24. package/lib/esm/decorators/generics/genericOf.js +8 -17
  25. package/lib/esm/decorators/generics/generics.js +3 -3
  26. package/lib/esm/decorators/operations/redirect.js +1 -1
  27. package/lib/esm/decorators/operations/returns.js +40 -63
  28. package/lib/esm/domain/JsonEntityStore.js +40 -41
  29. package/lib/esm/domain/JsonMedia.js +27 -6
  30. package/lib/esm/domain/JsonMethodStore.js +28 -9
  31. package/lib/esm/domain/JsonOperation.js +15 -0
  32. package/lib/esm/domain/JsonParameter.js +11 -10
  33. package/lib/esm/domain/JsonParameterStore.js +3 -9
  34. package/lib/esm/domain/JsonPropertyStore.js +14 -45
  35. package/lib/esm/domain/JsonSchema.js +287 -80
  36. package/lib/esm/fn/email.js +2 -2
  37. package/lib/esm/fn/uri.js +2 -2
  38. package/lib/esm/fn/url.js +2 -2
  39. package/lib/esm/index.js +3 -8
  40. package/lib/esm/utils/generics.js +3 -32
  41. package/lib/esm/utils/getJsonSchema.js +24 -17
  42. package/lib/esm/utils/mergeSchema.js +98 -0
  43. package/lib/esm/utils/ref.js +14 -13
  44. package/lib/types/components/default/classMapper.d.ts +1 -1
  45. package/lib/types/components/default/genericsMapper.d.ts +9 -2
  46. package/lib/types/components/default/lazyRefMapper.d.ts +1 -1
  47. package/lib/types/components/default/nextMapper.d.ts +5 -0
  48. package/lib/types/components/default/ofMapper.d.ts +1 -1
  49. package/lib/types/components/index.d.ts +1 -7
  50. package/lib/types/components/open-spec/nullableMapper.d.ts +2 -1
  51. package/lib/types/components/open-spec/operationInQueryMapper.d.ts +1 -1
  52. package/lib/types/constants/VendorKeys.d.ts +10 -0
  53. package/lib/types/decorators/collections/collectionOf.d.ts +1 -1
  54. package/lib/types/decorators/generics/genericOf.d.ts +3 -0
  55. package/lib/types/decorators/generics/generics.d.ts +2 -2
  56. package/lib/types/decorators/operations/returns.d.ts +11 -9
  57. package/lib/types/domain/JsonEntityStore.d.ts +20 -18
  58. package/lib/types/domain/JsonMedia.d.ts +4 -5
  59. package/lib/types/domain/JsonMethodStore.d.ts +9 -2
  60. package/lib/types/domain/JsonOperation.d.ts +1 -0
  61. package/lib/types/domain/JsonParameter.d.ts +2 -7
  62. package/lib/types/domain/JsonParameterStore.d.ts +0 -2
  63. package/lib/types/domain/JsonPropertyStore.d.ts +1 -20
  64. package/lib/types/domain/JsonSchema.d.ts +82 -39
  65. package/lib/types/index.d.ts +3 -8
  66. package/lib/types/interfaces/JsonSchemaOptions.d.ts +16 -2
  67. package/lib/types/utils/generics.d.ts +7 -48
  68. package/lib/types/utils/getJsonSchema.d.ts +2 -1
  69. package/lib/types/utils/mergeSchema.d.ts +2 -0
  70. package/lib/types/utils/ref.d.ts +4 -2
  71. package/package.json +7 -7
  72. package/lib/esm/components/async-api/channelsMapper.js +0 -57
  73. package/lib/esm/components/async-api/generate.js +0 -17
  74. package/lib/esm/components/async-api/messageMapper.js +0 -39
  75. package/lib/esm/components/async-api/payloadMapper.js +0 -47
  76. package/lib/esm/components/async-api/responseMapper.js +0 -53
  77. package/lib/esm/components/default/itemMapper.js +0 -5
  78. package/lib/esm/components/default/propertiesMapper.js +0 -20
  79. package/lib/esm/utils/somethingOf.js +0 -11
  80. package/lib/types/components/async-api/channelsMapper.d.ts +0 -2
  81. package/lib/types/components/async-api/generate.d.ts +0 -1
  82. package/lib/types/components/async-api/messageMapper.d.ts +0 -6
  83. package/lib/types/components/async-api/payloadMapper.d.ts +0 -4
  84. package/lib/types/components/async-api/responseMapper.d.ts +0 -6
  85. package/lib/types/components/default/itemMapper.d.ts +0 -2
  86. package/lib/types/components/default/propertiesMapper.d.ts +0 -3
  87. package/lib/types/utils/somethingOf.d.ts +0 -1
@@ -10,6 +10,6 @@ import { JsonEntityFn } from "./jsonEntityFn.js";
10
10
  */
11
11
  export function ForwardGroups(bool = true) {
12
12
  return JsonEntityFn((entity) => {
13
- entity.schema.$forwardGroups = bool;
13
+ entity.schema.forwardGroups(bool);
14
14
  });
15
15
  }
@@ -1,6 +1,4 @@
1
1
  import { DecoratorTypes, isArray } from "@tsed/core";
2
- import { matchGroups } from "../../utils/matchGroups.js";
3
- import { CustomKey } from "./customKey.js";
4
2
  import { JsonEntityFn } from "./jsonEntityFn.js";
5
3
  /**
6
4
  * @ignore
@@ -15,30 +13,21 @@ function groupsClass(groups, entity) {
15
13
  }
16
14
  export function Groups(...groups) {
17
15
  return JsonEntityFn((entity) => {
18
- switch (entity.decoratorType) {
19
- case DecoratorTypes.CLASS:
20
- groupsClass(groups, entity);
21
- break;
22
- case DecoratorTypes.PROP:
23
- CustomKey("x-groups", groups)(entity.target, entity.propertyKey);
24
- entity.schema.$hooks.on("groups", (prev, givenGroups) => {
25
- if (!prev) {
26
- if (matchGroups(groups, givenGroups)) {
27
- return true;
28
- }
29
- }
30
- return prev;
31
- });
32
- break;
33
- case DecoratorTypes.PARAM:
34
- let groupsName = "";
35
- if (groups.length == 2 && isArray(groups[1])) {
36
- groupsName = groups[0];
37
- groups = groups[1];
38
- }
39
- entity.parameter.groups = groups;
40
- entity.parameter.groupsName = groupsName;
41
- break;
16
+ if (entity.is(DecoratorTypes.CLASS)) {
17
+ groupsClass(groups, entity);
18
+ return;
19
+ }
20
+ if (entity.is(DecoratorTypes.PROP)) {
21
+ entity.schema.groups(groups, true);
22
+ return;
23
+ }
24
+ if (entity.is(DecoratorTypes.PARAM)) {
25
+ let groupsName = "";
26
+ if (groups.length == 2 && isArray(groups[1])) {
27
+ groupsName = groups[0];
28
+ groups = groups[1];
29
+ }
30
+ entity.parameter.schema().groups(groups).groupsName(groupsName);
42
31
  }
43
32
  });
44
33
  }
@@ -16,6 +16,6 @@ import { JsonEntityFn } from "./jsonEntityFn.js";
16
16
  */
17
17
  export function OneOf(...oneOf) {
18
18
  return JsonEntityFn((entity) => {
19
- entity.itemSchema.oneOf(oneOf);
19
+ entity.schema.oneOf(oneOf);
20
20
  });
21
21
  }
@@ -1,12 +1,5 @@
1
- import { isObject } from "@tsed/core";
1
+ import { DecoratorTypes } from "@tsed/core";
2
2
  import { JsonEntityStore } from "../../domain/JsonEntityStore.js";
3
- import { string } from "../../fn/string.js";
4
- /**
5
- * @ignore
6
- */
7
- function isEnum(type) {
8
- return isObject(type) && !("toJSON" in type);
9
- }
10
3
  /**
11
4
  * Set the types of a Generic class.
12
5
  *
@@ -74,17 +67,15 @@ function isEnum(type) {
74
67
  * @generics
75
68
  */
76
69
  export function GenericOf(...generics) {
77
- const nestedGenerics = [
78
- generics.map((type) => {
79
- if (isEnum(type)) {
80
- return string().enum(Object.values(type));
81
- }
82
- return type;
83
- })
84
- ];
70
+ const nestedGenerics = [generics];
85
71
  const decorator = (...args) => {
86
72
  const store = JsonEntityStore.from(...args);
87
- store.nestedGenerics = nestedGenerics;
73
+ if (store.is(DecoratorTypes.PARAM)) {
74
+ store.parameter.schema().genericOf(...nestedGenerics);
75
+ }
76
+ else {
77
+ store.schema.genericOf(...nestedGenerics);
78
+ }
88
79
  };
89
80
  decorator.Nested = (...generics) => {
90
81
  nestedGenerics.push(generics);
@@ -4,17 +4,17 @@ import { JsonEntityStore } from "../../domain/JsonEntityStore.js";
4
4
  *
5
5
  * See @@GenericOf@@ decorator for more details.
6
6
  *
7
- * @param generics
8
7
  * @decorator
9
8
  * @validation
10
9
  * @swagger
11
10
  * @schema
12
11
  * @input
13
12
  * @generics
13
+ * @param genericLabels
14
14
  */
15
- export function Generics(...generics) {
15
+ export function Generics(...genericLabels) {
16
16
  return (target) => {
17
17
  const storedSchema = JsonEntityStore.from(target);
18
- storedSchema.schema.genericLabels = generics;
18
+ storedSchema.schema.genericLabels(genericLabels);
19
19
  };
20
20
  }
@@ -14,7 +14,7 @@ export function Redirect(...args) {
14
14
  options.meta = value;
15
15
  return options;
16
16
  }, { status: 302, url: "", meta: {} });
17
- return useDecorators(Returns(status).Location(url, meta), JsonEntityFn((entity) => {
17
+ return useDecorators(Returns(status, String).Location(url, meta), JsonEntityFn((entity) => {
18
18
  entity.operation?.setRedirection(status);
19
19
  }));
20
20
  }
@@ -1,27 +1,9 @@
1
- import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes, isArray, isCollection, isObject, isPlainObject, isPrimitiveOrPrimitiveClass, isString } from "@tsed/core";
1
+ import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes, isArray, isCollection, isPlainObject, isPrimitiveOrPrimitiveClass, isString } from "@tsed/core";
2
2
  import { getStatusMessage } from "../../constants/httpStatusMessages.js";
3
3
  import { DecoratorContext } from "../../domain/DecoratorContext.js";
4
4
  import { JsonEntityStore } from "../../domain/JsonEntityStore.js";
5
- import { JsonParameter } from "../../domain/JsonParameter.js";
6
- import { JsonSchema } from "../../domain/JsonSchema.js";
7
- import { string } from "../../fn/string.js";
8
5
  import { getStatusModel } from "../../utils/defineStatusModel.js";
9
- import { isSuccessStatus } from "../../utils/isSuccessStatus.js";
10
6
  import { mapHeaders } from "../../utils/mapHeaders.js";
11
- /**
12
- * @ignore
13
- */
14
- function isEnum(type) {
15
- return isObject(type) && !("toJSON" in type);
16
- }
17
- function mapGenerics(types) {
18
- return types.map((type) => {
19
- if (isEnum(type)) {
20
- return string().enum(Object.values(type));
21
- }
22
- return type;
23
- });
24
- }
25
7
  /**
26
8
  * @ignore
27
9
  */
@@ -44,6 +26,7 @@ class ReturnDecoratorContext extends DecoratorContext {
44
26
  "headers",
45
27
  "schema",
46
28
  "title",
29
+ "label",
47
30
  "groups",
48
31
  "allowedGroups",
49
32
  "location",
@@ -83,6 +66,9 @@ class ReturnDecoratorContext extends DecoratorContext {
83
66
  return this.headers({ [key]: value });
84
67
  }
85
68
  location(path, meta = {}) {
69
+ if (!this.get("model")) {
70
+ this.model(String);
71
+ }
86
72
  this.headers({
87
73
  Location: {
88
74
  ...meta,
@@ -110,7 +96,9 @@ class ReturnDecoratorContext extends DecoratorContext {
110
96
  this.checkPrimitive(model);
111
97
  this.checkCollection(model);
112
98
  this.addAction((ctx) => {
113
- this.get("schema").nestedGenerics.push(mapGenerics(generics));
99
+ const currentGenerics = ctx.get("generics") || [];
100
+ currentGenerics.push(generics);
101
+ ctx.get("schema").genericOf(...currentGenerics);
114
102
  });
115
103
  return this;
116
104
  }
@@ -119,11 +107,14 @@ class ReturnDecoratorContext extends DecoratorContext {
119
107
  this.checkPrimitive(model);
120
108
  this.addAction(() => {
121
109
  const schema = this.get("schema");
122
- if (isCollection(model)) {
123
- schema?.itemSchema({ type: types[0] });
124
- }
125
- else {
126
- schema?.nestedGenerics.push(mapGenerics(types));
110
+ if (schema) {
111
+ if (isCollection(model)) {
112
+ schema.itemSchema({ type: types[0] });
113
+ }
114
+ else {
115
+ this.set("generics", [types]);
116
+ schema.genericOf(types);
117
+ }
127
118
  }
128
119
  });
129
120
  return this;
@@ -151,8 +142,15 @@ class ReturnDecoratorContext extends DecoratorContext {
151
142
  this.set("examples", isString(examples) ? [examples] : examples);
152
143
  return this;
153
144
  }
145
+ /**
146
+ * @deprecated
147
+ * @param title
148
+ */
154
149
  title(title) {
155
- return this.schema({ title });
150
+ return this.schema({ label: title });
151
+ }
152
+ label(label) {
153
+ return this.schema({ label });
156
154
  }
157
155
  binary() {
158
156
  this.type(String);
@@ -213,11 +211,12 @@ class ReturnDecoratorContext extends DecoratorContext {
213
211
  response.headers(headers);
214
212
  }
215
213
  this.mapMedia(response);
216
- if (isSuccessStatus(this.get("status")) || currentStatus === "default") {
217
- if (model) {
218
- entity.type = model;
219
- }
220
- }
214
+ // if (isSuccessStatus(this.get("status")) || currentStatus === "default") {
215
+ // if (model) {
216
+ // // TODO Check why we need that ?
217
+ // // entity.type = model;
218
+ // }
219
+ // }
221
220
  // additional info for OS2
222
221
  contentType && operation.addProduce(contentType);
223
222
  // run additional actions
@@ -225,41 +224,19 @@ class ReturnDecoratorContext extends DecoratorContext {
225
224
  }
226
225
  mapMedia(response) {
227
226
  const contentType = this.getContentType();
228
- const model = this.get("model");
229
- const media = response.getMedia(contentType || "*/*");
230
- const schema = media.get("schema") || new JsonSchema({ type: model });
231
- const groups = this.get("groups");
232
- const groupsName = this.get("groupsName");
233
227
  const allowedGroups = this.get("allowedGroups");
234
- const operation = this.entity.operation;
235
- if (model) {
236
- if (isArray(model)) {
237
- schema.oneOf(model.map((type) => ({ type })));
238
- }
239
- else {
240
- schema.type(model);
241
- }
242
- }
228
+ const { operation } = this.entity;
229
+ const media = response.getMedia(contentType || "*/*");
230
+ const schema = media
231
+ .type(this.get("model"))
232
+ .examples(this.get("examples"))
233
+ .schema()
234
+ .groups(this.get("groups"))
235
+ .groupsName(this.get("groupsName"))
236
+ .allowedGroups(allowedGroups);
243
237
  this.set("schema", schema);
244
- media.schema(schema);
245
- media.groups = groups;
246
- media.groupsName = groupsName;
247
238
  if (allowedGroups) {
248
- media.allowedGroups = allowedGroups;
249
- const jsonParameter = new JsonParameter();
250
- jsonParameter.in("query").name("includes");
251
- jsonParameter.schema(JsonSchema.from({
252
- type: "array",
253
- items: {
254
- type: "string",
255
- enum: [...allowedGroups]
256
- }
257
- }));
258
- operation.addParameter(-1, jsonParameter);
259
- }
260
- const examples = this.get("examples");
261
- if (examples) {
262
- media.examples(examples);
239
+ operation.addAllowedGroupsParameter(allowedGroups);
263
240
  }
264
241
  return media;
265
242
  }
@@ -9,7 +9,7 @@ export class JsonEntityStore {
9
9
  const { target, propertyKey, descriptor, index, decoratorType } = options;
10
10
  this.target = target;
11
11
  this.propertyKey = propertyKey;
12
- this.propertyName = String(propertyKey);
12
+ this.propertyName = propertyKey ? String(propertyKey) : propertyKey || "";
13
13
  this.descriptor = descriptor;
14
14
  this.index = index;
15
15
  this.decoratorType = decoratorType;
@@ -17,6 +17,25 @@ export class JsonEntityStore {
17
17
  this.store = options.store;
18
18
  this.parent = this;
19
19
  }
20
+ get type() {
21
+ return this._type;
22
+ }
23
+ /**
24
+ * Get original type without transformation
25
+ * @param value
26
+ */
27
+ set type(value) {
28
+ if (!value?.$schema?.skip) {
29
+ this._type = value;
30
+ }
31
+ this.build();
32
+ }
33
+ /**
34
+ * Return the JsonSchema
35
+ */
36
+ get schema() {
37
+ return this._schema;
38
+ }
20
39
  /**
21
40
  * Return the class name of the entity.
22
41
  * @returns {string}
@@ -47,35 +66,12 @@ export class JsonEntityStore {
47
66
  get isClass() {
48
67
  return isClass(this.computedType);
49
68
  }
50
- /**
51
- * Return the JsonSchema
52
- */
53
- get schema() {
54
- return this._schema;
55
- }
56
- get nestedGenerics() {
57
- return this.schema.nestedGenerics;
58
- }
59
- set nestedGenerics(nestedGenerics) {
60
- this.schema.nestedGenerics = nestedGenerics;
61
- }
62
- get type() {
63
- return this._type;
64
- }
65
- /**
66
- * Get original type without transformation
67
- * @param value
68
- */
69
- set type(value) {
70
- this._type = value;
71
- this.build();
72
- }
73
69
  /**
74
70
  * Return the itemSchema computed type. if the type is a function used for recursive model, the function will be called to
75
71
  * get the right type.
76
72
  */
77
73
  get computedType() {
78
- return this.itemSchema.getComputedType();
74
+ return this.itemSchema.class;
79
75
  }
80
76
  get itemSchema() {
81
77
  return this.isCollection ? this.schema.itemSchema() : this.schema;
@@ -86,6 +82,12 @@ export class JsonEntityStore {
86
82
  get isDiscriminatorChild() {
87
83
  return this.schema.isDiscriminator && this.discriminatorAncestor?.schema.discriminator().base !== this.target;
88
84
  }
85
+ get path() {
86
+ return this.store.get("path");
87
+ }
88
+ set path(path) {
89
+ this.store.set("path", path);
90
+ }
89
91
  static from(...args) {
90
92
  if (args[0].isStore) {
91
93
  return args[0];
@@ -129,11 +131,23 @@ export class JsonEntityStore {
129
131
  toString() {
130
132
  return [this.targetName, this.propertyName, this.index].filter((o) => o !== undefined).join(":");
131
133
  }
134
+ getBestType() {
135
+ return this.itemSchema.hasDiscriminator
136
+ ? this.itemSchema.discriminator().base
137
+ : isClassObject(this.type)
138
+ ? this.itemSchema.getTarget()
139
+ : isArrowFn(this.type)
140
+ ? this.type()
141
+ : this.type;
142
+ }
143
+ is(input) {
144
+ return this.decoratorType === input;
145
+ }
132
146
  buildType(type) {
133
147
  if (isCollection(type)) {
134
148
  this.collectionType = type;
135
149
  }
136
- else {
150
+ else if (!(type && "$schema" in type && type.$schema.skip)) {
137
151
  this._type = type;
138
152
  // issue #1534: Enum metadata stored as plain object instead of String (see: https://github.com/tsedio/tsed/issues/1534)
139
153
  if (this._type && isPlainObject(this._type)) {
@@ -141,19 +155,4 @@ export class JsonEntityStore {
141
155
  }
142
156
  }
143
157
  }
144
- set path(path) {
145
- this.store.set("path", path);
146
- }
147
- get path() {
148
- return this.store.get("path");
149
- }
150
- getBestType() {
151
- return this.itemSchema.hasDiscriminator
152
- ? this.itemSchema.discriminator().base
153
- : isClassObject(this.type)
154
- ? this.itemSchema.getTarget()
155
- : isArrowFn(this.type)
156
- ? this.type()
157
- : this.type;
158
- }
159
158
  }
@@ -1,16 +1,37 @@
1
+ import { isArray, isClass } from "@tsed/core";
1
2
  import { JsonMap } from "./JsonMap.js";
3
+ import { JsonSchema } from "./JsonSchema.js";
2
4
  export class JsonMedia extends JsonMap {
3
- constructor() {
4
- super(...arguments);
5
+ constructor(obj = {}) {
6
+ super(obj);
5
7
  this.$kind = "operationMedia";
6
- this.groups = [];
8
+ if (!this.has("schema")) {
9
+ this.set("schema", new JsonSchema());
10
+ }
7
11
  }
8
12
  schema(schema) {
9
- this.set("schema", schema);
10
- return this;
13
+ schema && this.set("schema", schema);
14
+ return this.get("schema");
11
15
  }
12
16
  examples(examples) {
13
- this.set("examples", examples);
17
+ examples && this.set("examples", examples);
18
+ return this;
19
+ }
20
+ type(type) {
21
+ if (type) {
22
+ if (isArray(type)) {
23
+ this.schema().oneOf(type.map((type) => ({ type })));
24
+ }
25
+ else {
26
+ if (isClass(type)) {
27
+ this.schema().type("object");
28
+ this.schema().itemSchema(type);
29
+ }
30
+ else {
31
+ this.schema().type(type);
32
+ }
33
+ }
34
+ }
14
35
  return this;
15
36
  }
16
37
  }
@@ -1,5 +1,5 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import { DecoratorTypes, deepMerge, descriptorOf, isCollection, isFunction, isPromise, Metadata, prototypeOf, Store } from "@tsed/core";
2
+ import { DecoratorTypes, deepMerge, descriptorOf, isClass, isCollection, isFunction, isPromise, Metadata, prototypeOf, Store } from "@tsed/core";
3
3
  import { JsonEntityComponent } from "../decorators/config/jsonEntityComponent.js";
4
4
  import { JsonEntityStore } from "./JsonEntityStore.js";
5
5
  import { JsonOperation } from "./JsonOperation.js";
@@ -59,15 +59,21 @@ let JsonMethodStore = class JsonMethodStore extends JsonEntityStore {
59
59
  descriptor = descriptor || descriptorOf(prototypeOf(target), propertyKey);
60
60
  return JsonEntityStore.from(prototypeOf(target), propertyKey, descriptor);
61
61
  }
62
+ /**
63
+ * TODO must be located on JsonOperation level directly
64
+ * @param status
65
+ * @param contentType
66
+ * @param includes
67
+ */
62
68
  getResponseOptions(status, { contentType = "application/json", includes } = {}) {
63
69
  const media = this.operation.getResponseOf(status).getMedia(contentType, false);
64
70
  if (media && media.has("schema")) {
65
- const schema = media.get("schema");
66
- let groups = media.groups;
67
- if (includes && media.allowedGroups?.size) {
68
- groups = [...(groups || []), ...includes.filter((include) => media.allowedGroups.has(include))];
71
+ const allowedGroups = media.schema().getAllowedGroups();
72
+ let groups = media.schema().getGroups();
73
+ if (includes && allowedGroups?.size) {
74
+ groups = [...(groups || []), ...includes.filter((include) => allowedGroups.has(include))];
69
75
  }
70
- return { type: schema.getComputedItemType(), groups };
76
+ return { type: media.schema().collectionClass, groups };
71
77
  }
72
78
  return { type: this.type };
73
79
  }
@@ -126,12 +132,25 @@ let JsonMethodStore = class JsonMethodStore extends JsonEntityStore {
126
132
  // @ts-ignore
127
133
  delete this._type;
128
134
  }
129
- this._schema = JsonSchema.from({
130
- type: this.collectionType || this.type
131
- });
135
+ // TODO est-ce que c'est tjrs d'actualité car on doit utiliser le decorator @Returns pour affecter correctement les data
136
+ // peut etre que c'est pour les get/setter ou méthod n'étant pas un endpoint?
132
137
  if (this.collectionType) {
138
+ this._schema = JsonSchema.from({
139
+ type: this.collectionType
140
+ });
133
141
  this._schema.itemSchema(this.type);
134
142
  }
143
+ else if (isClass(this.type)) {
144
+ this._schema = JsonSchema.from({
145
+ type: "object"
146
+ });
147
+ this._schema.itemSchema(this.type);
148
+ }
149
+ else {
150
+ this._schema = JsonSchema.from({
151
+ type: this.type
152
+ });
153
+ }
135
154
  this.parent.schema.addProperty(this.propertyName, this.schema);
136
155
  }
137
156
  };
@@ -1,7 +1,9 @@
1
1
  import { deepMerge, uniq, uniqBy } from "@tsed/core";
2
2
  import { isRedirectionStatus, isSuccessStatus } from "../utils/isSuccessStatus.js";
3
3
  import { JsonMap } from "./JsonMap.js";
4
+ import { JsonParameter } from "./JsonParameter.js";
4
5
  import { JsonResponse } from "./JsonResponse.js";
6
+ import { JsonSchema } from "./JsonSchema.js";
5
7
  export class JsonMethodPath extends JsonMap {
6
8
  constructor(method, path) {
7
9
  super();
@@ -127,6 +129,19 @@ export class JsonOperation extends JsonMap {
127
129
  super.set("deprecated", deprecated);
128
130
  return this;
129
131
  }
132
+ addAllowedGroupsParameter(allowedGroups) {
133
+ const jsonParameter = new JsonParameter();
134
+ jsonParameter.in("query").name("includes");
135
+ jsonParameter.schema(JsonSchema.from({
136
+ type: "array",
137
+ items: {
138
+ type: "string",
139
+ enum: [...allowedGroups]
140
+ }
141
+ }));
142
+ this.addParameter(-1, jsonParameter);
143
+ return this;
144
+ }
130
145
  parameters(parameters) {
131
146
  super.set("parameters", parameters);
132
147
  return this;
@@ -3,11 +3,12 @@ import { JsonMap } from "./JsonMap.js";
3
3
  import { formatParameterType } from "./JsonParameterTypes.js";
4
4
  import { JsonSchema } from "./JsonSchema.js";
5
5
  export class JsonParameter extends JsonMap {
6
- constructor() {
7
- super(...arguments);
6
+ constructor(obj = {}) {
7
+ super(obj);
8
8
  this.$kind = "operationInParameter";
9
- this.nestedGenerics = [];
10
- this.$schema = new JsonSchema();
9
+ if (!this.has("schema")) {
10
+ this.set("schema", new JsonSchema());
11
+ }
11
12
  }
12
13
  getName() {
13
14
  const name = this.get("name");
@@ -39,18 +40,18 @@ export class JsonParameter extends JsonMap {
39
40
  }
40
41
  schema(schema) {
41
42
  if (schema) {
42
- this.$schema = schema;
43
+ this.set("schema", schema);
43
44
  return this;
44
45
  }
45
- return this.$schema;
46
+ return this.get("schema");
46
47
  }
47
48
  itemSchema(schema) {
48
- if (this.$schema.isCollection) {
49
- schema && this.$schema.itemSchema(schema);
50
- return this.$schema.itemSchema();
49
+ if (this.schema().isCollection) {
50
+ schema && this.schema().itemSchema(schema);
51
+ return this.schema().itemSchema();
51
52
  }
52
53
  schema && this.schema(schema);
53
- // non-collection: delegate to main schema would
54
+ // non-collection: delegate to the main schema
54
55
  return this.schema();
55
56
  }
56
57
  toJSON(options) {
@@ -16,12 +16,6 @@ let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
16
16
  this.expression = options.expression || this.expression;
17
17
  this.dataPath = options.dataPath || this.dataPath;
18
18
  }
19
- get nestedGenerics() {
20
- return this.parameter.nestedGenerics;
21
- }
22
- set nestedGenerics(nestedGenerics) {
23
- this.parameter.nestedGenerics = nestedGenerics;
24
- }
25
19
  /**
26
20
  * Return the required state.
27
21
  * @returns {boolean}
@@ -33,10 +27,10 @@ let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
33
27
  this.parameter.required(value);
34
28
  }
35
29
  get allowedRequiredValues() {
36
- return this.schema.$allow;
30
+ return this.schema.getAllowedRequiredValues();
37
31
  }
38
32
  get schema() {
39
- return this.parameter.$schema;
33
+ return this.parameter.schema();
40
34
  }
41
35
  static getParams(target, propertyKey) {
42
36
  const params = [];
@@ -76,7 +70,7 @@ let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
76
70
  this.parameter.schema().type(this.collectionType);
77
71
  }
78
72
  if (isClass(this._type)) {
79
- this.parameter.itemSchema(JsonEntityStore.from(this._type).schema);
73
+ this.parameter.schema().itemSchema(this._type);
80
74
  }
81
75
  else {
82
76
  this.parameter.itemSchema().type(this._type);