@tsed/schema 8.1.0 → 8.2.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 (109) hide show
  1. package/lib/browser/schema.umd.min.js +1 -1
  2. package/lib/browser/schema.umd.min.js.map +1 -1
  3. package/lib/esm/components/default/anyMapper.js +2 -2
  4. package/lib/esm/components/default/anyMapper.js.map +1 -1
  5. package/lib/esm/components/default/inheritedClassMapper.js +16 -2
  6. package/lib/esm/components/default/inheritedClassMapper.js.map +1 -1
  7. package/lib/esm/decorators/common/labelledAs.js +35 -0
  8. package/lib/esm/decorators/common/labelledAs.js.map +1 -0
  9. package/lib/esm/decorators/generics/genericOf.js +1 -1
  10. package/lib/esm/decorators/generics/genericOf.js.map +1 -1
  11. package/lib/esm/decorators/operations/returns.js +1 -1
  12. package/lib/esm/decorators/operations/returns.js.map +1 -1
  13. package/lib/esm/fn/allOf.js +12 -0
  14. package/lib/esm/fn/allOf.js.map +1 -0
  15. package/lib/esm/fn/any.js +10 -0
  16. package/lib/esm/fn/any.js.map +1 -0
  17. package/lib/esm/fn/anyOf.js +12 -0
  18. package/lib/esm/fn/anyOf.js.map +1 -0
  19. package/lib/esm/fn/boolean.js +10 -0
  20. package/lib/esm/fn/boolean.js.map +1 -0
  21. package/lib/esm/fn/collection.js +50 -0
  22. package/lib/esm/fn/collection.js.map +1 -0
  23. package/lib/esm/fn/date.js +27 -0
  24. package/lib/esm/fn/date.js.map +1 -0
  25. package/lib/esm/fn/email.js +18 -0
  26. package/lib/esm/fn/email.js.map +1 -0
  27. package/lib/esm/fn/enums.js +8 -0
  28. package/lib/esm/fn/enums.js.map +1 -0
  29. package/lib/esm/fn/from.js +28 -0
  30. package/lib/esm/fn/from.js.map +1 -0
  31. package/lib/esm/fn/integer.js +13 -0
  32. package/lib/esm/fn/integer.js.map +1 -0
  33. package/lib/esm/fn/lazyRef.js +17 -0
  34. package/lib/esm/fn/lazyRef.js.map +1 -0
  35. package/lib/esm/fn/number.js +10 -0
  36. package/lib/esm/fn/number.js.map +1 -0
  37. package/lib/esm/fn/object.js +22 -0
  38. package/lib/esm/fn/object.js.map +1 -0
  39. package/lib/esm/fn/oneOf.js +13 -0
  40. package/lib/esm/fn/oneOf.js.map +1 -0
  41. package/lib/esm/fn/string.js +10 -0
  42. package/lib/esm/fn/string.js.map +1 -0
  43. package/lib/esm/fn/uri.js +13 -0
  44. package/lib/esm/fn/uri.js.map +1 -0
  45. package/lib/esm/fn/url.js +11 -0
  46. package/lib/esm/fn/url.js.map +1 -0
  47. package/lib/esm/index.js +18 -1
  48. package/lib/esm/index.js.map +1 -1
  49. package/lib/esm/registries/JsonSchemaMapperContainer.js +1 -1
  50. package/lib/esm/registries/JsonSchemaMapperContainer.js.map +1 -1
  51. package/lib/esm/utils/ref.js.map +1 -1
  52. package/lib/types/decorators/common/labelledAs.d.ts +24 -0
  53. package/lib/types/fn/allOf.d.ts +9 -0
  54. package/lib/types/fn/any.d.ts +7 -0
  55. package/lib/types/fn/anyOf.d.ts +9 -0
  56. package/lib/types/fn/boolean.d.ts +7 -0
  57. package/lib/types/fn/collection.d.ts +43 -0
  58. package/lib/types/fn/date.d.ts +19 -0
  59. package/lib/types/fn/email.d.ts +14 -0
  60. package/lib/types/fn/enums.d.ts +1 -0
  61. package/lib/types/fn/from.d.ts +14 -0
  62. package/lib/types/fn/integer.d.ts +10 -0
  63. package/lib/types/fn/lazyRef.d.ts +5 -0
  64. package/lib/types/fn/number.d.ts +6 -0
  65. package/lib/types/fn/object.d.ts +21 -0
  66. package/lib/types/fn/oneOf.d.ts +10 -0
  67. package/lib/types/fn/string.d.ts +7 -0
  68. package/lib/types/fn/uri.d.ts +9 -0
  69. package/lib/types/fn/url.d.ts +7 -0
  70. package/lib/types/index.d.ts +18 -1
  71. package/lib/types/registries/JsonSchemaMapperContainer.d.ts +1 -1
  72. package/package.json +10 -10
  73. package/src/components/default/anyMapper.ts +2 -2
  74. package/src/components/default/inheritedClassMapper.ts +19 -2
  75. package/src/decorators/collections/collectionOf.spec.ts +2 -1
  76. package/src/decorators/common/allOf.spec.ts +2 -1
  77. package/src/decorators/common/anyOf.spec.ts +2 -1
  78. package/src/decorators/common/enum.spec.ts +1 -1
  79. package/src/decorators/common/labelledAs.spec.ts +85 -0
  80. package/src/decorators/common/labelledAs.ts +34 -0
  81. package/src/decorators/common/oneOf.spec.ts +2 -1
  82. package/src/decorators/generics/genericOf.ts +1 -1
  83. package/src/decorators/operations/returns.ts +1 -1
  84. package/src/fn/allOf.ts +13 -0
  85. package/src/fn/any.ts +11 -0
  86. package/src/fn/anyOf.ts +13 -0
  87. package/src/fn/boolean.ts +11 -0
  88. package/src/fn/collection.ts +53 -0
  89. package/src/fn/date.ts +30 -0
  90. package/src/fn/email.ts +19 -0
  91. package/src/fn/enums.ts +9 -0
  92. package/src/{utils → fn}/from.spec.ts +14 -83
  93. package/src/fn/from.ts +33 -0
  94. package/src/fn/integer.ts +13 -0
  95. package/src/fn/layzRef.spec.ts +70 -0
  96. package/src/fn/lazyRef.ts +19 -0
  97. package/src/fn/number.ts +10 -0
  98. package/src/fn/object.ts +23 -0
  99. package/src/fn/oneOf.ts +14 -0
  100. package/src/fn/string.ts +11 -0
  101. package/src/fn/uri.ts +14 -0
  102. package/src/fn/url.ts +12 -0
  103. package/src/index.ts +18 -1
  104. package/src/registries/JsonSchemaMapperContainer.ts +1 -1
  105. package/src/utils/ref.ts +0 -1
  106. package/lib/esm/utils/from.js +0 -256
  107. package/lib/esm/utils/from.js.map +0 -1
  108. package/lib/types/utils/from.d.ts +0 -190
  109. package/src/utils/from.ts +0 -281
@@ -28,7 +28,7 @@ export function execMapper(type, args, options, parent) {
28
28
  export function hasMapper(type) {
29
29
  return JsonSchemaMappersContainer.has(type);
30
30
  }
31
- export function oneOfMapper(types, options) {
31
+ export function execOneOfMapper(types, options) {
32
32
  return (types.find((type) => JsonSchemaMappersContainer.has(`${options?.specType}:${type}`)) ||
33
33
  types.find((type) => JsonSchemaMappersContainer.has(type)));
34
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"JsonSchemaMapperContainer.js","sourceRoot":"","sources":["../../../src/registries/JsonSchemaMapperContainer.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,0BAA0B,GAAkC,IAAI,GAAG,EAAE,CAAC;AAE5E;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAY,EAAE,MAAwB,EAAE,IAAgB;IAC/F,OAAO,0BAA0B,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,OAAY;IAC5D,MAAM,MAAM,GAAG,0BAA0B,CAAC,GAAG,CAAC,GAAG,OAAO,EAAE,QAAQ,IAAI,IAAI,EAAE,CAAE,IAAI,0BAA0B,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;IAExH,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,uBAAuB;IACvB,MAAM,IAAI,KAAK,CAAC,cAAc,IAAI,wBAAwB,CAAC,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,IAAW,EAAE,OAAY,EAAE,MAAY;IAC9E,OAAO,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,0BAA0B,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAe,EAAE,OAAY;IACvD,OAAO,CACL,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,0BAA0B,CA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AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,KAAiB,EAAE,MAA2B,EAAE,OAA0B;IAC9F,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IAErD,IAAI,MAAM,EAAE,CAAC;QACX,QAAQ,CAAC,OAAO,EAAE,sBAAsB,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Use label to create ref on the current decorated property.
3
+ *
4
+ * ### Example
5
+ *
6
+ * ```ts
7
+ * class Model {
8
+ * // For single property
9
+ * @LabelledAs("UserSchema")
10
+ * name: string;
11
+ *
12
+ * // For collection
13
+ * @LabelledAs("UserCollectionSchema", "collection")
14
+ * users: User[];
15
+ * }
16
+ * ```
17
+ *
18
+ * @param label The name of the label
19
+ * @param includeCollection Add the label to the collection. By default, the label is added to the item of the collection it the property is a collection.
20
+ * @returns PropertyDecorator
21
+ *
22
+ * @decorator
23
+ */
24
+ export declare function LabelledAs(label: string, includeCollection?: false | "collection"): PropertyDecorator;
@@ -0,0 +1,9 @@
1
+ import type { AnyJsonSchema, JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26
4
+ *
5
+ * * See @@JsonSchema@@ to discover available methods.
6
+ *
7
+ * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26
8
+ */
9
+ export declare function allOf(...allOf: AnyJsonSchema[]): JsonSchema;
@@ -0,0 +1,7 @@
1
+ import type { AnyJsonSchema, JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a model with any type (By default: `integer`, `number`, `string`, `boolean`, `array`, `object`, `null`)
4
+ *
5
+ * See @@JsonSchema@@ to discover available methods.
6
+ */
7
+ export declare function any(...types: AnyJsonSchema[]): JsonSchema;
@@ -0,0 +1,9 @@
1
+ import type { AnyJsonSchema, JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27
4
+ *
5
+ * * See @@JsonSchema@@ to discover available methods.
6
+ *
7
+ * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27
8
+ */
9
+ export declare function anyOf(...anyOf: AnyJsonSchema[]): JsonSchema;
@@ -0,0 +1,7 @@
1
+ import type { JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a new boolean model.
4
+ *
5
+ * * See @@JsonSchema@@ to discover available methods.
6
+ */
7
+ export declare function boolean(): JsonSchema;
@@ -0,0 +1,43 @@
1
+ import type { JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a new object model with `additionalProperties: true`.
4
+ *
5
+ * ```json
6
+ * {
7
+ * "type": "array"
8
+ * }
9
+ * ```
10
+ *
11
+ * * See @@JsonSchema@@ to discover available methods.
12
+ *
13
+ * @schemaFunctional
14
+ */
15
+ export declare function array(): JsonSchema;
16
+ /**
17
+ * Declare a new object model with `additionalProperties: true`.
18
+ *
19
+ * ```json
20
+ * {
21
+ * "type": "object",
22
+ * "additionalProperties": true
23
+ * }
24
+ * ```
25
+ *
26
+ * * See @@JsonSchema@@ to discover available methods.
27
+ *
28
+ * @schemaFunctional
29
+ */
30
+ export declare function map(): JsonSchema;
31
+ /**
32
+ * Declare a new array model with `uniqueItems: true`.
33
+ *
34
+ * ```json
35
+ * {
36
+ * "type": "array",
37
+ * "uniqueItems": true
38
+ * }
39
+ * ```
40
+ *
41
+ * * See @@JsonSchema@@ to discover available methods.
42
+ */
43
+ export declare function set(): JsonSchema;
@@ -0,0 +1,19 @@
1
+ import type { JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a new string model with `format: date`.
4
+ *
5
+ * See @@JsonSchema@@ to discover available methods.
6
+ */
7
+ export declare function date(): JsonSchema;
8
+ /**
9
+ * Declare a new string model with `format: datetime`.
10
+ *
11
+ * See @@JsonSchema@@ to discover available methods.
12
+ */
13
+ export declare function datetime(): JsonSchema;
14
+ /**
15
+ * Declare a new string model with `format: time`.
16
+ *
17
+ * See @@JsonSchema@@ to discover available methods.
18
+ */
19
+ export declare function time(): JsonSchema;
@@ -0,0 +1,14 @@
1
+ import type { JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a new string model with `format: email`.
4
+ *
5
+ * See @@JsonSchema@@ to discover available methods.
6
+ *
7
+ * ### Example
8
+ *
9
+ * ```typescript
10
+ * const schema = email();
11
+ * // Results in: { type: "string", format: "email" }
12
+ * ```
13
+ */
14
+ export declare function email(): JsonSchema;
@@ -0,0 +1 @@
1
+ export declare function enums(e: Record<string, any>): import("../index.js").JsonSchema;
@@ -0,0 +1,14 @@
1
+ import { Type } from "@tsed/core";
2
+ import { JsonSchema } from "../domain/JsonSchema.js";
3
+ /**
4
+ * Create a new model from the given type.
5
+ *
6
+ * ```typescript
7
+ * from(String)
8
+ * ```
9
+ *
10
+ * * See @@JsonSchema@@ to discover available methods.
11
+ *
12
+ * @schemaFunctional
13
+ */
14
+ export declare function from(type?: Type<any>): JsonSchema;
@@ -0,0 +1,10 @@
1
+ import type { JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a new integer model.
4
+ *
5
+ * See @@JsonSchema@@ to discover available methods.
6
+ *
7
+ * @returns {JsonSchema} A schema configured for integer values
8
+ * @function
9
+ */
10
+ export declare function integer(): JsonSchema;
@@ -0,0 +1,5 @@
1
+ import type { Type } from "@tsed/core";
2
+ /**
3
+ * Declare a sub schema which will be resolved later. Use this function when you have a circular reference between two schemes.
4
+ */
5
+ export declare function lazyRef(cb: () => Type<any>): any;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Declare a new number model.
3
+ *
4
+ * * See @@JsonSchema@@ to discover available methods.
5
+ */
6
+ export declare function number(): import("../index.js").JsonSchema;
@@ -0,0 +1,21 @@
1
+ import { JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a new object model.
4
+ *
5
+ * See @@JsonSchema@@ to discover available methods.
6
+ *
7
+ * ### Example
8
+ *
9
+ * ```typescript
10
+ * const userSchema = object({
11
+ * name: string(),
12
+ * age: number()
13
+ * });
14
+ * ```
15
+ *
16
+ * @param properties - An object containing property definitions where each value is a JsonSchema
17
+ * @returns {JsonSchema} A new object model with the specified properties
18
+ */
19
+ export declare function object(properties?: {
20
+ [key: string]: JsonSchema;
21
+ }): JsonSchema;
@@ -0,0 +1,10 @@
1
+ import type { AnyJsonSchema, JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28
4
+ *
5
+ * * See @@JsonSchema@@ to discover available methods.
6
+ *
7
+ * @schemaFunctional
8
+ * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28
9
+ */
10
+ export declare function oneOf(...oneOf: AnyJsonSchema[]): JsonSchema;
@@ -0,0 +1,7 @@
1
+ import type { JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a new string model.
4
+ *
5
+ * See @@JsonSchema@@ to discover available methods.
6
+ */
7
+ export declare function string(): JsonSchema;
@@ -0,0 +1,9 @@
1
+ import type { JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a new string model with `format: uri`.
4
+ *
5
+ * * See @@JsonSchema@@ to discover available methods.
6
+ *
7
+ * @schemaFunctional
8
+ */
9
+ export declare function uri(): JsonSchema;
@@ -0,0 +1,7 @@
1
+ import type { JsonSchema } from "../domain/JsonSchema.js";
2
+ /**
3
+ * Declare a new string model with `format: url`.
4
+ *
5
+ * See @@JsonSchema@@ to discover available methods.
6
+ */
7
+ export declare function url(): JsonSchema;
@@ -71,6 +71,7 @@ export * from "./decorators/common/hidden.js";
71
71
  export * from "./decorators/common/ignore.js";
72
72
  export * from "./decorators/common/integer.js";
73
73
  export * from "./decorators/common/jsonEntityFn.js";
74
+ export * from "./decorators/common/labelledAs.js";
74
75
  export * from "./decorators/common/maximum.js";
75
76
  export * from "./decorators/common/maxLength.js";
76
77
  export * from "./decorators/common/minimum.js";
@@ -138,6 +139,23 @@ export * from "./domain/JsonRequestBody.js";
138
139
  export * from "./domain/JsonResponse.js";
139
140
  export * from "./domain/JsonSchema.js";
140
141
  export * from "./domain/SpecTypes.js";
142
+ export * from "./fn/allOf.js";
143
+ export * from "./fn/any.js";
144
+ export * from "./fn/anyOf.js";
145
+ export * from "./fn/boolean.js";
146
+ export * from "./fn/collection.js";
147
+ export * from "./fn/date.js";
148
+ export * from "./fn/email.js";
149
+ export * from "./fn/enums.js";
150
+ export * from "./fn/from.js";
151
+ export * from "./fn/integer.js";
152
+ export * from "./fn/lazyRef.js";
153
+ export * from "./fn/number.js";
154
+ export * from "./fn/object.js";
155
+ export * from "./fn/oneOf.js";
156
+ export * from "./fn/string.js";
157
+ export * from "./fn/uri.js";
158
+ export * from "./fn/url.js";
141
159
  export * from "./hooks/alterIgnore.js";
142
160
  export * from "./hooks/alterOneOf.js";
143
161
  export * from "./hooks/alterRequiredGroups.js";
@@ -151,7 +169,6 @@ export * from "./utils/buildPath.js";
151
169
  export * from "./utils/concatParameters.js";
152
170
  export * from "./utils/concatPath.js";
153
171
  export * from "./utils/defineStatusModel.js";
154
- export * from "./utils/from.js";
155
172
  export * from "./utils/generateSpec.js";
156
173
  export * from "./utils/generics.js";
157
174
  export * from "./utils/getComputedType.js";
@@ -18,4 +18,4 @@ export declare function getJsonSchemaMapper(type: string, options: any): JsonSch
18
18
  */
19
19
  export declare function execMapper(type: string, args: any[], options: any, parent?: any): any;
20
20
  export declare function hasMapper(type: string): boolean;
21
- export declare function oneOfMapper(types: string[], options: any): string;
21
+ export declare function execOneOfMapper(types: string[], options: any): string;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/schema",
3
3
  "description": "JsonSchema module for Ts.ED Framework",
4
4
  "type": "module",
5
- "version": "8.1.0",
5
+ "version": "8.2.0",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -37,7 +37,7 @@
37
37
  "tsed"
38
38
  ],
39
39
  "dependencies": {
40
- "@tsed/openspec": "8.1.0",
40
+ "@tsed/openspec": "8.2.0",
41
41
  "change-case": "^5.4.4",
42
42
  "json-schema": "0.4.0",
43
43
  "picomatch": "2.3.1",
@@ -46,11 +46,11 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@apidevtools/swagger-parser": "10.1.0",
49
- "@tsed/barrels": "8.1.0",
50
- "@tsed/core": "8.1.0",
51
- "@tsed/hooks": "8.1.0",
52
- "@tsed/openspec": "8.1.0",
53
- "@tsed/typescript": "8.1.0",
49
+ "@tsed/barrels": "8.2.0",
50
+ "@tsed/core": "8.2.0",
51
+ "@tsed/hooks": "8.2.0",
52
+ "@tsed/openspec": "8.2.0",
53
+ "@tsed/typescript": "8.2.0",
54
54
  "@types/fs-extra": "11.0.4",
55
55
  "@types/json-schema": "7.0.15",
56
56
  "@types/picomatch": "3.0.1",
@@ -63,9 +63,9 @@
63
63
  "webpack": "^5.75.0"
64
64
  },
65
65
  "peerDependencies": {
66
- "@tsed/core": "8.1.0",
67
- "@tsed/hooks": "8.1.0",
68
- "@tsed/openspec": "8.1.0"
66
+ "@tsed/core": "8.2.0",
67
+ "@tsed/hooks": "8.2.0",
68
+ "@tsed/openspec": "8.2.0"
69
69
  },
70
70
  "peerDependenciesMeta": {
71
71
  "@tsed/core": {
@@ -1,7 +1,7 @@
1
1
  import {JsonLazyRef} from "../../domain/JsonLazyRef.js";
2
2
  import {JsonSchema} from "../../domain/JsonSchema.js";
3
3
  import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
4
- import {execMapper, oneOfMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
4
+ import {execMapper, execOneOfMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
5
5
  import {mapGenericsOptions} from "../../utils/generics.js";
6
6
  import {toRef} from "../../utils/ref.js";
7
7
 
@@ -21,7 +21,7 @@ export function anyMapper(input: any, options: JsonSchemaOptions = {}): any {
21
21
  }
22
22
 
23
23
  if (input.$kind && input.$isJsonDocument) {
24
- const kind = oneOfMapper([input.$kind, "map"], options);
24
+ const kind = execOneOfMapper([input.$kind, "map"], options);
25
25
  const schema = execMapper(kind, [input], mapGenericsOptions(options));
26
26
 
27
27
  return input.canRef ? toRef(input, schema, options) : schema;
@@ -4,6 +4,23 @@ import {JsonSchemaOptions} from "../../interfaces/JsonSchemaOptions.js";
4
4
  import {execMapper, registerJsonSchemaMapper} from "../../registries/JsonSchemaMapperContainer.js";
5
5
  import {getInheritedStores} from "../../utils/getInheritedStores.js";
6
6
 
7
+ function alterMerge(_: string, obj: any) {
8
+ if (obj?.type && obj?.$ref) {
9
+ const {$ref, ...schema} = obj;
10
+
11
+ obj = {
12
+ allOf: [
13
+ {
14
+ $ref
15
+ },
16
+ schema
17
+ ]
18
+ };
19
+ }
20
+
21
+ return obj;
22
+ }
23
+
7
24
  /**
8
25
  * @ignore
9
26
  */
@@ -12,10 +29,10 @@ export function inheritedClassMapper(obj: any, {target, ...options}: JsonSchemaO
12
29
 
13
30
  if (stores.length) {
14
31
  const schema = stores.reduce((obj, [, store]) => {
15
- return deepMerge(obj, execMapper("schema", [store.schema], options));
32
+ return deepMerge(obj, execMapper("schema", [store.schema], options), {alter: alterMerge});
16
33
  }, {});
17
34
 
18
- obj = deepMerge(schema, obj);
35
+ return deepMerge(schema, obj, {alter: alterMerge});
19
36
  }
20
37
 
21
38
  return obj;
@@ -1,7 +1,8 @@
1
1
  import {catchError} from "@tsed/core";
2
2
 
3
3
  import {JsonEntityStore} from "../../domain/JsonEntityStore.js";
4
- import {array, map, string} from "../../utils/from.js";
4
+ import {array, map} from "../../fn/collection.js";
5
+ import {string} from "../../fn/string.js";
5
6
  import {getJsonSchema} from "../../utils/getJsonSchema.js";
6
7
  import {Property} from "../common/property.js";
7
8
  import {Schema} from "../common/schema.js";
@@ -1,6 +1,7 @@
1
1
  import {JsonEntityStore} from "../../domain/JsonEntityStore.js";
2
2
  import {SpecTypes} from "../../domain/SpecTypes.js";
3
- import {number, string} from "../../utils/from.js";
3
+ import {number} from "../../fn/number.js";
4
+ import {string} from "../../fn/string.js";
4
5
  import {getJsonSchema} from "../../utils/getJsonSchema.js";
5
6
  import {getSpec} from "../../utils/getSpec.js";
6
7
  import {In} from "../operations/in.js";
@@ -1,6 +1,7 @@
1
1
  import {JsonEntityStore} from "../../domain/JsonEntityStore.js";
2
+ import {number} from "../../fn/number.js";
3
+ import {string} from "../../fn/string.js";
2
4
  import {AllOf, getJsonSchema, getSpec, In, OneOf, OperationPath, Path, Property, SpecTypes} from "../../index.js";
3
- import {number, string} from "../../utils/from.js";
4
5
  import {AnyOf} from "./anyOf.js";
5
6
 
6
7
  describe("@AnyOf", () => {
@@ -1,4 +1,4 @@
1
- import {enums} from "../../utils/from.js";
1
+ import {enums} from "../../fn/enums.js";
2
2
  import {getJsonSchema} from "../../utils/getJsonSchema.js";
3
3
  import {Enum} from "./enum.js";
4
4
 
@@ -0,0 +1,85 @@
1
+ import {getJsonSchema} from "../../utils/getJsonSchema.js";
2
+ import {MaxItems} from "../collections/maxItems.js";
3
+ import {Enum} from "./enum.js";
4
+ import {LabelledAs} from "./labelledAs.js";
5
+
6
+ describe("LabelledAs", () => {
7
+ it("should create label on item schema", () => {
8
+ enum Test {
9
+ VALUE = "VALUE",
10
+ TEST = "TEST"
11
+ }
12
+
13
+ class Model {
14
+ @Enum(Test)
15
+ @MaxItems(3)
16
+ @LabelledAs("ModelPropItem")
17
+ prop: Test[];
18
+ }
19
+
20
+ const schema = getJsonSchema(Model);
21
+
22
+ expect(schema).toMatchInlineSnapshot(`
23
+ {
24
+ "definitions": {
25
+ "ModelPropItem": {
26
+ "enum": [
27
+ "VALUE",
28
+ "TEST",
29
+ ],
30
+ "type": "string",
31
+ },
32
+ },
33
+ "properties": {
34
+ "prop": {
35
+ "items": {
36
+ "$ref": "#/definitions/ModelPropItem",
37
+ },
38
+ "maxItems": 3,
39
+ "type": "array",
40
+ },
41
+ },
42
+ "type": "object",
43
+ }
44
+ `);
45
+ });
46
+ it("should create label on collection", () => {
47
+ enum Test {
48
+ VALUE = "VALUE",
49
+ TEST = "TEST"
50
+ }
51
+
52
+ class Model {
53
+ @Enum(Test)
54
+ @MaxItems(3)
55
+ @LabelledAs("ModelPropItem", "collection")
56
+ prop: Test[];
57
+ }
58
+
59
+ const schema = getJsonSchema(Model);
60
+
61
+ expect(schema).toMatchInlineSnapshot(`
62
+ {
63
+ "definitions": {
64
+ "ModelPropItem": {
65
+ "items": {
66
+ "enum": [
67
+ "VALUE",
68
+ "TEST",
69
+ ],
70
+ "type": "string",
71
+ },
72
+ "maxItems": 3,
73
+ "type": "array",
74
+ },
75
+ },
76
+ "properties": {
77
+ "prop": {
78
+ "$ref": "#/definitions/ModelPropItem",
79
+ },
80
+ },
81
+ "type": "object",
82
+ }
83
+ `);
84
+ });
85
+ });
@@ -0,0 +1,34 @@
1
+ import {JsonEntityFn} from "./jsonEntityFn.js";
2
+
3
+ /**
4
+ * Use label to create ref on the current decorated property.
5
+ *
6
+ * ### Example
7
+ *
8
+ * ```ts
9
+ * class Model {
10
+ * // For single property
11
+ * @LabelledAs("UserSchema")
12
+ * name: string;
13
+ *
14
+ * // For collection
15
+ * @LabelledAs("UserCollectionSchema", "collection")
16
+ * users: User[];
17
+ * }
18
+ * ```
19
+ *
20
+ * @param label The name of the label
21
+ * @param includeCollection Add the label to the collection. By default, the label is added to the item of the collection it the property is a collection.
22
+ * @returns PropertyDecorator
23
+ *
24
+ * @decorator
25
+ */
26
+ export function LabelledAs(label: string, includeCollection: false | "collection" = false): PropertyDecorator {
27
+ return JsonEntityFn((entity) => {
28
+ if (includeCollection) {
29
+ entity.schema.label(label);
30
+ } else {
31
+ entity.itemSchema.label(label);
32
+ }
33
+ });
34
+ }
@@ -1,5 +1,6 @@
1
+ import {number} from "../../fn/number.js";
2
+ import {string} from "../../fn/string.js";
1
3
  import {AllOf, getJsonSchema, getSpec, In, OneOf, OperationPath, Path, Property, SpecTypes} from "../../index.js";
2
- import {number, string} from "../../utils/from.js";
3
4
 
4
5
  describe("@OneOf", () => {
5
6
  it("should declare return schema", () => {
@@ -1,7 +1,7 @@
1
1
  import {isObject, Type} from "@tsed/core";
2
2
 
3
3
  import {JsonEntityStore} from "../../domain/JsonEntityStore.js";
4
- import {string} from "../../utils/from.js";
4
+ import {string} from "../../fn/string.js";
5
5
  import {GenericValue} from "../../utils/generics.js";
6
6
 
7
7
  /**
@@ -18,9 +18,9 @@ import {JsonEntityStore} from "../../domain/JsonEntityStore.js";
18
18
  import {JsonParameter} from "../../domain/JsonParameter.js";
19
19
  import {JsonResponse} from "../../domain/JsonResponse.js";
20
20
  import {JsonSchema, JsonSchemaObject} from "../../domain/JsonSchema.js";
21
+ import {string} from "../../fn/string.js";
21
22
  import {JsonHeader, JsonHeaders} from "../../interfaces/JsonOpenSpec.js";
22
23
  import {getStatusModel} from "../../utils/defineStatusModel.js";
23
- import {string} from "../../utils/from.js";
24
24
  import {GenericValue} from "../../utils/generics.js";
25
25
  import {isSuccessStatus} from "../../utils/isSuccessStatus.js";
26
26
  import {mapHeaders} from "../../utils/mapHeaders.js";
@@ -0,0 +1,13 @@
1
+ import type {AnyJsonSchema, JsonSchema} from "../domain/JsonSchema.js";
2
+ import {from} from "./from.js";
3
+
4
+ /**
5
+ * See https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26
6
+ *
7
+ * * See @@JsonSchema@@ to discover available methods.
8
+ *
9
+ * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26
10
+ */
11
+ export function allOf(...allOf: AnyJsonSchema[]): JsonSchema {
12
+ return from().allOf(allOf);
13
+ }
package/src/fn/any.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type {AnyJsonSchema, JsonSchema} from "../domain/JsonSchema.js";
2
+ import {from} from "./from.js";
3
+
4
+ /**
5
+ * Declare a model with any type (By default: `integer`, `number`, `string`, `boolean`, `array`, `object`, `null`)
6
+ *
7
+ * See @@JsonSchema@@ to discover available methods.
8
+ */
9
+ export function any(...types: AnyJsonSchema[]): JsonSchema {
10
+ return from().any(...types);
11
+ }