@tsed/schema 8.13.5 → 8.14.0-rc.1

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 +11 -8
  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
@@ -24,8 +24,6 @@ export declare class JsonParameterStore extends JsonEntityStore {
24
24
  readonly parameter: JsonParameter;
25
25
  readonly parent: JsonMethodStore;
26
26
  constructor(options: JsonParameterStoreOptions);
27
- get nestedGenerics(): Type<any>[][];
28
- set nestedGenerics(nestedGenerics: Type<any>[][]);
29
27
  /**
30
28
  * Return the required state.
31
29
  * @returns {boolean}
@@ -3,27 +3,8 @@ import type { JsonClassStore } from "./JsonClassStore.js";
3
3
  import { JsonEntityStore } from "./JsonEntityStore.js";
4
4
  export declare class JsonPropertyStore extends JsonEntityStore {
5
5
  readonly parent: JsonClassStore;
6
- /**
7
- * Return the required state.
8
- * @returns {boolean}
9
- */
10
- get required(): boolean;
11
- /**
12
- * Change the state of the required data.
13
- * @param value
14
- */
15
- set required(value: boolean);
16
- get allowedRequiredValues(): any[];
17
- discriminatorKey(): this;
18
- isDiscriminatorKey(): boolean;
19
- /**
20
- * Check precondition between value, required and allowedRequiredValues to know if the entity is required.
21
- * @param value
22
- * @returns {boolean}
23
- */
24
- isRequired(value: any): boolean;
25
- protected build(): void;
26
6
  static get(target: Type<any>, propertyKey: string | symbol): JsonPropertyStore;
7
+ protected build(): void;
27
8
  }
28
9
  /**
29
10
  * @alias JsonPropertyStore
@@ -1,68 +1,100 @@
1
1
  import { Type, ValueOf } from "@tsed/core";
2
2
  import { Hooks } from "@tsed/hooks";
3
- import type { JSONSchema6, JSONSchema6Definition, JSONSchema6Type, JSONSchema6TypeName, JSONSchema6Version } from "json-schema";
3
+ import type { JSONSchema7, JSONSchema7Definition, JSONSchema7Type, JSONSchema7TypeName, JSONSchema7Version } from "json-schema";
4
+ import { VendorKeys } from "../constants/VendorKeys.js";
4
5
  import { IgnoreCallback } from "../interfaces/IgnoreCallback.js";
5
6
  import { JsonSchemaOptions } from "../interfaces/JsonSchemaOptions.js";
6
- import { NestedGenerics } from "../utils/generics.js";
7
+ import { type GenericsMap, GenericValue } from "../utils/generics.js";
7
8
  import { AliasMap, AliasType } from "./JsonAliasMap.js";
8
9
  import { Discriminator } from "./JsonDiscriminator.js";
9
10
  import { JsonFormatTypes } from "./JsonFormatTypes.js";
10
11
  import { JsonLazyRef } from "./JsonLazyRef.js";
11
- export interface JsonSchemaObject extends JSONSchema6, Record<string, any> {
12
- type: (any | JSONSchema6TypeName) | (any | JSONSchema6TypeName)[];
13
- additionalProperties?: boolean | JSONSchema6 | any;
14
- propertyNames?: boolean | JSONSchema6 | any;
15
- items?: (any | JSONSchema6Definition) | (any | JSONSchema6Definition)[];
12
+ export interface JsonSchemaObject extends Omit<JSONSchema7, "type" | "additionalProperties" | "items"> {
13
+ type?: Type | JSONSchema7["type"] | null | (String | null | Date | Number | Object | Boolean)[];
14
+ additionalProperties?: boolean | JSONSchema7 | Type | JsonSchema;
15
+ items?: (Type | JSONSchema7Definition | JsonSchema) | (Type | JSONSchema7Definition | JsonSchema)[];
16
16
  }
17
- export type AnyJsonSchema = Partial<JsonSchemaObject> | JsonSchema | JsonLazyRef | any;
18
- export declare class JsonSchema extends Map<string, any> implements NestedGenerics {
17
+ export type AnyJsonSchema = JsonSchemaObject | JSONSchema7 | JsonSchema | JsonLazyRef | {
18
+ label?: string;
19
+ } | Type;
20
+ export declare class JsonSchema extends Map<string, any> {
19
21
  #private;
20
22
  readonly $kind: string;
21
23
  readonly $isJsonDocument = true;
22
24
  readonly $hooks: Hooks;
23
- readonly $required: Set<string>;
24
25
  readonly $allow: any[];
25
26
  $selfRequired: boolean;
26
- $forwardGroups: boolean;
27
27
  $ignore: boolean | IgnoreCallback;
28
28
  isDiscriminatorKey: boolean;
29
29
  isDiscriminator: boolean;
30
30
  constructor(obj?: JsonSchema | Partial<JsonSchemaObject>);
31
31
  get alias(): AliasMap;
32
- get nestedGenerics(): any[];
33
- set nestedGenerics(value: any[]);
34
- get genericLabels(): string[];
35
- set genericLabels(value: string[]);
36
32
  get isClass(): boolean;
37
33
  /**
38
- * Current schema is a collection
34
+ * The current schema is a collection
39
35
  */
40
36
  get isCollection(): boolean;
37
+ /**
38
+ * The current schema is a reference to another schema
39
+ * to link property/param to a class schema (if the reference exists).
40
+ */
41
+ get isLocalSchema(): boolean;
41
42
  /**
42
43
  * Current schema is a generic
43
44
  */
44
45
  get isGeneric(): boolean;
45
46
  get discriminatorAncestor(): any;
46
47
  /**
47
- * Current schema has generics items
48
+ * Return the itemSchema computed type.
49
+ * If the type is a function used for a recursive model,
50
+ * the function will be called to get the right type.
51
+ */
52
+ get class(): Type<any>;
53
+ /**
54
+ * Return the itemSchema computed type.
48
55
  */
49
- get hasGenerics(): boolean;
50
- get genericType(): string;
51
- get class(): any;
56
+ get collectionClass(): Type<any>;
52
57
  get canRef(): boolean;
53
58
  get isNullable(): boolean;
54
59
  get isReadOnly(): any;
55
60
  get isWriteOnly(): any;
56
61
  get hasDiscriminator(): boolean;
57
- static from(obj?: Partial<JsonSchemaObject>): JsonSchema;
58
- nullable(value: boolean): void;
62
+ static from(item?: Partial<JsonSchemaObject> | Type<any> | JsonSchema): JsonSchema;
63
+ /**
64
+ * Check if the schema as key, #key or x-key
65
+ * @param key
66
+ */
67
+ has(key: string): boolean;
68
+ /**
69
+ * Get the value of the schema by key, #key or x-key.
70
+ * @param key
71
+ * @param defaultValue
72
+ */
73
+ get<T = any>(key: string, defaultValue: T): T;
74
+ get<T = any>(key: string, defaultValue?: T): T | undefined;
75
+ forwardGroups(bool?: boolean): this;
76
+ groups(groups?: string[], isProperty?: boolean): this;
77
+ groupsName(groupsName?: string): this;
78
+ allowedGroups(groups?: string[]): this;
79
+ /**
80
+ * Assign the Generic Labels used over a class or a schema.
81
+ * @param genericLabels
82
+ */
83
+ genericLabels(genericLabels: string[]): this;
84
+ genericLabel(genericLabel: string): this;
85
+ /**
86
+ * Assign the types of the generics that must be used for the property
87
+ * @param generics
88
+ */
89
+ genericOf(...generics: GenericValue[][]): this;
90
+ nullable(value: boolean): this;
59
91
  itemSchema(obj?: AnyJsonSchema): JsonSchema;
60
92
  getAliasOf(property: AliasType): AliasType | undefined;
61
93
  addAlias(property: AliasType, alias: AliasType): this;
62
94
  removeAlias(property: AliasType): this;
63
95
  $id($id: string): this;
64
96
  $ref($ref: string): this;
65
- $schema($schema: JSONSchema6Version): this;
97
+ $schema($schema: JSONSchema7Version): this;
66
98
  /**
67
99
  * Create a ref and use name to sharing schema
68
100
  * @param name
@@ -75,12 +107,12 @@ export declare class JsonSchema extends Map<string, any> implements NestedGeneri
75
107
  * It is RECOMMENDED that a default value be valid against the associated schema.
76
108
  * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.3
77
109
  */
78
- default(value: JSONSchema6Type | undefined | (() => JSONSchema6Type)): this;
110
+ default(value: JSONSchema7Type | undefined | (() => JSONSchema7Type)): this;
79
111
  /**
80
112
  * More readible form of a one-element "enum"
81
113
  * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.24
82
114
  */
83
- const(value: JSONSchema6Type): this;
115
+ const(value: JSONSchema7Type): this;
84
116
  /**
85
117
  * This attribute is a string that provides a full description of the of purpose the instance property.
86
118
  *
@@ -104,17 +136,17 @@ export declare class JsonSchema extends Map<string, any> implements NestedGeneri
104
136
  * An array instance is valid against "contains" if at least one of its elements is valid against the given schema.
105
137
  * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.14
106
138
  */
107
- contains(contains: JSONSchema6Definition): this;
139
+ contains(contains: JSONSchema7Definition): this;
108
140
  /**
109
141
  * Array of examples with no validation effect the value of "default" is usable as an example without repeating it under this keyword
110
142
  * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.4
111
143
  */
112
- examples(examples: JSONSchema6Type[]): this;
144
+ examples(examples: JSONSchema7Type[]): this;
113
145
  /**
114
146
  * Array of examples with no validation effect the value of "default" is usable as an example without repeating it under this keyword
115
147
  * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.4
116
148
  */
117
- example(...examples: JSONSchema6Type[]): this;
149
+ example(...examples: JSONSchema7Type[]): this;
118
150
  /**
119
151
  * This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself.
120
152
  * Omitting this keyword has the same behavior as an empty schema.
@@ -167,6 +199,7 @@ export declare class JsonSchema extends Map<string, any> implements NestedGeneri
167
199
  addRequired(property: string): this;
168
200
  removeRequired(property: string): this;
169
201
  isRequired(property: string): boolean;
202
+ getRequiredFields(): string[];
170
203
  /**
171
204
  * This keyword determines how child instances validate for objects, and does not directly validate the immediate instance itself.
172
205
  * Validation succeeds if, for each name that appears in both the instance and as a name within this keyword's value,
@@ -211,7 +244,7 @@ export declare class JsonSchema extends Map<string, any> implements NestedGeneri
211
244
  * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.21
212
245
  */
213
246
  dependencies(dependencies: {
214
- [p: string]: JSONSchema6Definition | JsonSchema | string[];
247
+ [p: string]: JSONSchema7Definition | JsonSchema | string[];
215
248
  }): this;
216
249
  /**
217
250
  * Takes a schema which validates the names of all properties rather than their values.
@@ -219,7 +252,7 @@ export declare class JsonSchema extends Map<string, any> implements NestedGeneri
219
252
  * Omitting this keyword has the same behavior as an empty schema.
220
253
  * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.22
221
254
  */
222
- propertyNames(propertyNames: JSONSchema6Definition | JsonSchema): this;
255
+ propertyNames(propertyNames: JSONSchema7Definition | JsonSchema): this;
223
256
  /**
224
257
  * This provides an enumeration of all possible values that are valid
225
258
  * for the instance property. This MUST be an array, and each item in
@@ -304,7 +337,7 @@ export declare class JsonSchema extends Map<string, any> implements NestedGeneri
304
337
  * A single type, or a union of simple types
305
338
  * @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.25
306
339
  */
307
- type(type: any | JSONSchema6TypeName | JSONSchema6TypeName[]): this;
340
+ type(type: any | JSONSchema7TypeName | JSONSchema7TypeName[]): this;
308
341
  any(...types: any[]): this;
309
342
  integer(): this;
310
343
  /**
@@ -316,26 +349,36 @@ export declare class JsonSchema extends Map<string, any> implements NestedGeneri
316
349
  readOnly(readOnly: boolean): this;
317
350
  writeOnly(readOnly: boolean): this;
318
351
  customKey(key: string, value: any): this;
352
+ vendorKey(key: VendorKeys, value: any): this;
319
353
  toObject(options?: JsonSchemaOptions): any;
320
354
  toJSON(options?: JsonSchemaOptions): any;
321
- assign(obj?: JsonSchema | Partial<JsonSchemaObject>): this;
355
+ assign(obj?: AnyJsonSchema): this;
322
356
  set(key: string, value: any): this;
323
- /**
324
- * Return the itemSchema computed type.
325
- * If the type is a function used for recursive model,
326
- * the function will be called to get the right type.
327
- */
328
- getComputedType(): any;
329
- getComputedItemType(): any;
330
357
  /**
331
358
  * Return the Json type as string
332
359
  */
333
360
  getJsonType(): string | string[];
334
361
  getTarget(): Type<any>;
362
+ getAllowedGroups(): Set<string> | undefined;
363
+ getAllowedRequiredValues(): any[];
364
+ getGroups(): string[] | undefined;
365
+ getGroupsName(): string | undefined;
335
366
  /**
336
367
  * Get the symbolic name of the entity
337
368
  */
338
369
  getName(): any;
339
370
  clone(): JsonSchema;
371
+ getGenericLabels(): string[] | undefined;
372
+ getGenericOf(): GenericsMap | undefined;
373
+ /**
374
+ * Returns the reference schema for class-based schemas.
375
+ * Used to get the original schema definition when this schema is a local reference.
376
+ * @returns The reference schema or undefined if not applicable
377
+ */
378
+ getRefSchema(): JsonSchema | undefined;
379
+ propertyKey(s: string): this;
380
+ getPropertyKey(): string | symbol | undefined;
381
+ target(target: any): void;
382
+ isRequiredValue(property: string, value: any): boolean;
340
383
  protected setManyOf(keyword: "oneOf" | "anyOf" | "allOf", value: AnyJsonSchema[]): this | undefined;
341
384
  }
@@ -1,24 +1,18 @@
1
1
  /**
2
2
  * @file Automatically generated by @tsed/barrels.
3
3
  */
4
- export * from "./components/async-api/channelsMapper.js";
5
- export * from "./components/async-api/generate.js";
6
- export * from "./components/async-api/messageMapper.js";
7
- export * from "./components/async-api/payloadMapper.js";
8
- export * from "./components/async-api/responseMapper.js";
9
4
  export * from "./components/default/anyMapper.js";
10
5
  export * from "./components/default/classMapper.js";
11
6
  export * from "./components/default/discriminatorMappingMapper.js";
12
7
  export * from "./components/default/enumsMapper.js";
13
8
  export * from "./components/default/genericsMapper.js";
14
9
  export * from "./components/default/inheritedClassMapper.js";
15
- export * from "./components/default/itemMapper.js";
16
10
  export * from "./components/default/lazyRefMapper.js";
17
11
  export * from "./components/default/mapMapper.js";
12
+ export * from "./components/default/nextMapper.js";
18
13
  export * from "./components/default/nullableMapper.js";
19
14
  export * from "./components/default/objectMapper.js";
20
15
  export * from "./components/default/ofMapper.js";
21
- export * from "./components/default/propertiesMapper.js";
22
16
  export * from "./components/default/requiredMapper.js";
23
17
  export * from "./components/default/schemaMapper.js";
24
18
  export * from "./components/index.js";
@@ -38,6 +32,7 @@ export * from "./components/open-spec/pathsMapper.js";
38
32
  export * from "./constants/httpStatusMessages.js";
39
33
  export * from "./constants/jsonSchemaProperties.js";
40
34
  export * from "./constants/OperationVerbs.js";
35
+ export * from "./constants/VendorKeys.js";
41
36
  export * from "./decorators/class/children.js";
42
37
  export * from "./decorators/class/discriminatorValue.js";
43
38
  export * from "./decorators/collections/collectionContains.js";
@@ -190,12 +185,12 @@ export * from "./utils/mapOpenSpec3.js";
190
185
  export * from "./utils/mapOpenSpecInfo.js";
191
186
  export * from "./utils/mapOperationOptions.js";
192
187
  export * from "./utils/matchGroups.js";
188
+ export * from "./utils/mergeSchema.js";
193
189
  export * from "./utils/mergeSpec.js";
194
190
  export * from "./utils/operationIdFormatter.js";
195
191
  export * from "./utils/ref.js";
196
192
  export * from "./utils/removeHiddenOperation.js";
197
193
  export * from "./utils/serializeEnumValues.js";
198
- export * from "./utils/somethingOf.js";
199
194
  export * from "./utils/toJsonMapCollection.js";
200
195
  export * from "./utils/toJsonRegex.js";
201
196
  export * from "./utils/transformToOS2.js";
@@ -1,4 +1,5 @@
1
1
  import { SpecTypes } from "../domain/SpecTypes.js";
2
+ import type { GenericsMap } from "../utils/generics.js";
2
3
  export interface JsonSchemaOptions {
3
4
  /**
4
5
  * Map properties with the alias name. By default, false
@@ -13,12 +14,16 @@ export interface JsonSchemaOptions {
13
14
  */
14
15
  specType?: SpecTypes;
15
16
  /**
16
- * Define a groups restriction to generate the JsonSchema.
17
+ * Define the spec version for OPENAPI (3.1.0, 3.0.3, 3.0.2, 3.0.1, 3.0.0)
18
+ */
19
+ specVersion?: string;
20
+ /**
21
+ * Define a group restriction to generate the JsonSchema.
17
22
  * Set false to disable groups.
18
23
  */
19
24
  groups?: string[] | false;
20
25
  /**
21
- * Set the postfix groups name for generated model and ref.
26
+ * Set the postfix groups name for a generated model and ref.
22
27
  */
23
28
  groupsName?: string;
24
29
  /**
@@ -29,5 +34,14 @@ export interface JsonSchemaOptions {
29
34
  * Inline enums when enum instead of using $ref.
30
35
  */
31
36
  inlineEnums?: boolean;
37
+ /**
38
+ * Represents optional generic definitions that adhere to the JSON Schema standard.
39
+ *
40
+ * This property allows the specification of generics when constructing or representing a JSON schema.
41
+ * It can be used to define reusable and parameterized components within the schema structure.
42
+ *
43
+ * @type {GenericsMap|undefined}
44
+ */
45
+ generics?: GenericsMap;
32
46
  [key: string]: any;
33
47
  }
@@ -1,50 +1,9 @@
1
1
  import { Type } from "@tsed/core";
2
2
  import { JsonSchema } from "../domain/JsonSchema.js";
3
- export type GenericValue = Type<any> | JsonSchema | any;
4
- /**
5
- * @ignore
6
- */
7
- export type GenericsMap = Map<string, GenericValue>;
8
- /**
9
- * @ignore
10
- */
11
- export interface GenericTypes {
12
- genericTypes: Type<any>[];
13
- [key: string]: any;
14
- }
15
- /**
16
- * @ignore
17
- */
18
- export interface GenericLabels {
19
- genericLabels: string[];
20
- [key: string]: any;
21
- }
22
- /**
23
- * @ignore
24
- */
25
- export interface NestedGenerics {
26
- nestedGenerics: GenericValue[][];
27
- [key: string]: any;
28
- }
29
- /**
30
- * @ignore
31
- */
32
- export interface GenericsContext extends GenericTypes, GenericLabels, NestedGenerics {
33
- generics: GenericsMap;
34
- }
35
- /**
36
- * @ignore
37
- * @param genericLabels
38
- * @param genericTypes
39
- */
40
- export declare function getGenericsMap(genericLabels: string[], genericTypes: GenericValue[]): GenericsMap;
41
- /**
42
- * @ignore
43
- * @param options
44
- */
45
- export declare function mapGenericsOptions(options: Partial<GenericTypes & GenericLabels>): Partial<GenericTypes & GenericLabels>;
46
- /**
47
- * @ignore
48
- * @param value
49
- */
50
- export declare function popGenerics(value: NestedGenerics): NestedGenerics & GenericTypes;
3
+ import { JsonSchemaOptions } from "../interfaces/JsonSchemaOptions.js";
4
+ export type GenericValue = Type<any> | JsonSchema | String | Number | Boolean | Object | Date;
5
+ export type GenericsMap = Record<string, [GenericValue] | [GenericValue, GenericsMap]>;
6
+ export declare function getGenericsOptions(value: JsonSchema, options: JsonSchemaOptions): {
7
+ generics: GenericsMap | undefined;
8
+ mapper: string;
9
+ };
@@ -1,4 +1,5 @@
1
1
  import "../components/index.js";
2
2
  import { Type } from "@tsed/core";
3
+ import { JsonParameterStore } from "../domain/JsonParameterStore.js";
3
4
  import { JsonSchemaOptions } from "../interfaces/JsonSchemaOptions.js";
4
- export declare function getJsonSchema(model: Type<any> | any, options?: JsonSchemaOptions): any;
5
+ export declare function getJsonSchema(model: Type<any> | JsonParameterStore, options?: JsonSchemaOptions): any;
@@ -0,0 +1,2 @@
1
+ import type { JSONSchema7 } from "json-schema";
2
+ export declare function mergeSchema(schema1: JSONSchema7, schema2: JSONSchema7): JSONSchema7;
@@ -1,5 +1,7 @@
1
+ import type { JSONSchema7 } from "json-schema";
1
2
  import type { JsonSchema } from "../domain/JsonSchema.js";
2
3
  import { JsonSchemaOptions } from "../interfaces/JsonSchemaOptions.js";
4
+ export declare function getSchemaFromRef($ref: string | undefined, options: JsonSchemaOptions): JSONSchema7 | undefined;
3
5
  /**
4
6
  * @ignore
5
7
  */
@@ -7,8 +9,8 @@ export declare function createRefName(name: string, options: JsonSchemaOptions):
7
9
  /**
8
10
  * @ignore
9
11
  */
10
- export declare function createRef(name: string, schema: JsonSchema, options: JsonSchemaOptions): any;
12
+ export declare function createRef(name: string, schema: JsonSchema, options: JsonSchemaOptions): JSONSchema7;
11
13
  /**
12
14
  * @ignore
13
15
  */
14
- export declare function toRef(value: JsonSchema, schema: unknown | undefined, options: JsonSchemaOptions): any;
16
+ export declare function toRef(value: JsonSchema, schema: JSONSchema7 | undefined | null, options: JsonSchemaOptions): JSONSchema7;
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.13.5",
5
+ "version": "8.14.0-rc.1",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -34,7 +34,7 @@
34
34
  "tsed"
35
35
  ],
36
36
  "dependencies": {
37
- "@tsed/openspec": "8.13.5",
37
+ "@tsed/openspec": "8.14.0-rc.1",
38
38
  "change-case": "^5.4.4",
39
39
  "json-schema": "0.4.0",
40
40
  "picomatch": "4.0.2",
@@ -43,11 +43,11 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@apidevtools/swagger-parser": "10.1.0",
46
- "@tsed/barrels": "8.13.5",
47
- "@tsed/core": "8.13.5",
48
- "@tsed/hooks": "8.13.5",
49
- "@tsed/openspec": "8.13.5",
50
- "@tsed/typescript": "8.13.5",
46
+ "@tsed/barrels": "8.14.0-rc.1",
47
+ "@tsed/core": "8.14.0-rc.1",
48
+ "@tsed/hooks": "8.14.0-rc.1",
49
+ "@tsed/openspec": "8.14.0-rc.1",
50
+ "@tsed/typescript": "8.14.0-rc.1",
51
51
  "@types/fs-extra": "11.0.4",
52
52
  "@types/json-schema": "7.0.15",
53
53
  "@types/picomatch": "3.0.2",
@@ -76,5 +76,8 @@
76
76
  },
77
77
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/specs/schema",
78
78
  "author": "Romain Lenzotti",
79
- "license": "MIT"
79
+ "license": "MIT",
80
+ "publishConfig": {
81
+ "tag": "rc"
82
+ }
80
83
  }
@@ -1,57 +0,0 @@
1
- import { camelCase } from "change-case";
2
- import { OperationVerbs } from "../../constants/OperationVerbs.js";
3
- import { execMapper, registerJsonSchemaMapper } from "../../registries/JsonSchemaMapperContainer.js";
4
- import { buildPath } from "../../utils/buildPath.js";
5
- import { getJsonEntityStore } from "../../utils/getJsonEntityStore.js";
6
- import { getOperationsStores } from "../../utils/getOperationsStores.js";
7
- import { removeHiddenOperation } from "../../utils/removeHiddenOperation.js";
8
- const ALLOWED_VERBS = [OperationVerbs.PUBLISH, OperationVerbs.SUBSCRIBE];
9
- function pushToChannels(options) {
10
- return (channels, { operationPath, operationStore }) => {
11
- const path = options.ctrlRootPath || "/";
12
- const method = operationPath.method.toLowerCase();
13
- const operationId = camelCase(`${method.toLowerCase()} ${operationStore.parent.schema.getName()}`);
14
- const message = execMapper("message", [operationStore, operationPath], options);
15
- return {
16
- ...channels,
17
- [path]: {
18
- ...channels[path],
19
- [method]: {
20
- ...channels[path]?.[method],
21
- operationId,
22
- message: {
23
- oneOf: [...(channels[path]?.[method]?.message?.oneOf || []), message]
24
- }
25
- }
26
- }
27
- };
28
- };
29
- }
30
- function expandOperationPaths(options) {
31
- return (operationStore) => {
32
- const operationPaths = operationStore.operation.getAllowedOperationPath(ALLOWED_VERBS);
33
- if (operationPaths.length === 0) {
34
- return [];
35
- }
36
- return operationPaths.map((operationPath) => {
37
- return {
38
- operationPath,
39
- operationStore
40
- };
41
- });
42
- };
43
- }
44
- export function channelsMapper(model, { channels, rootPath, ...options }) {
45
- const store = getJsonEntityStore(model);
46
- const ctrlPath = store.path;
47
- const ctrlRootPath = buildPath(rootPath + ctrlPath);
48
- options = {
49
- ...options,
50
- ctrlRootPath
51
- };
52
- return [...getOperationsStores(model).values()]
53
- .filter(removeHiddenOperation)
54
- .flatMap(expandOperationPaths(options))
55
- .reduce(pushToChannels(options), channels);
56
- }
57
- registerJsonSchemaMapper("channels", channelsMapper);
@@ -1,17 +0,0 @@
1
- import { uniqBy } from "@tsed/core";
2
- import { SpecTypes } from "../../domain/SpecTypes.js";
3
- import { execMapper, registerJsonSchemaMapper } from "../../registries/JsonSchemaMapperContainer.js";
4
- function generate(model, options) {
5
- const specJson = {
6
- channels: execMapper("channels", [model], options)
7
- };
8
- specJson.tags = uniqBy(options.tags, "name");
9
- if (options.components?.schemas && Object.keys(options.components.schemas).length) {
10
- specJson.components = {
11
- ...options.components,
12
- schemas: options.components.schemas
13
- };
14
- }
15
- return specJson;
16
- }
17
- registerJsonSchemaMapper("generate", generate, SpecTypes.ASYNCAPI);
@@ -1,39 +0,0 @@
1
- import { cleanObject, getValue } from "@tsed/core";
2
- import { OperationVerbs } from "../../constants/OperationVerbs.js";
3
- import { SpecTypes } from "../../domain/SpecTypes.js";
4
- import { execMapper, registerJsonSchemaMapper } from "../../registries/JsonSchemaMapperContainer.js";
5
- import { makeOf } from "../../utils/somethingOf.js";
6
- export function messageMapper(jsonOperationStore, operationPath, { tags = [], defaultTags = [], ...options } = {}) {
7
- const { path: event, method } = operationPath;
8
- const messageKey = String(event);
9
- let message = getValue(options.components, "messages." + event, cleanObject({
10
- description: jsonOperationStore.operation.get("description"),
11
- summary: jsonOperationStore.operation.get("summary")
12
- }));
13
- if (method.toUpperCase() === OperationVerbs.PUBLISH) {
14
- const payload = execMapper("payload", [jsonOperationStore, operationPath], options);
15
- if (payload) {
16
- message.payload = payload;
17
- }
18
- const responses = jsonOperationStore.operation
19
- .getAllowedOperationPath([OperationVerbs.SUBSCRIBE])
20
- .map((operationPath) => {
21
- return execMapper("message", [jsonOperationStore, operationPath], options);
22
- })
23
- .filter(Boolean);
24
- const responsesSchema = makeOf("oneOf", responses);
25
- if (responsesSchema) {
26
- message["x-response"] = responsesSchema;
27
- }
28
- }
29
- else {
30
- const response = execMapper("response", [jsonOperationStore, operationPath], options);
31
- if (response) {
32
- message["x-response"] = response;
33
- }
34
- }
35
- options.components.messages = options.components.messages || {};
36
- options.components.messages[messageKey] = message;
37
- return { $ref: `#/components/messages/${messageKey}` };
38
- }
39
- registerJsonSchemaMapper("message", messageMapper, SpecTypes.ASYNCAPI);
@@ -1,47 +0,0 @@
1
- import { setValue } from "@tsed/core";
2
- import { pascalCase } from "change-case";
3
- import { isParameterType, JsonParameterTypes } from "../../domain/JsonParameterTypes.js";
4
- import { SpecTypes } from "../../domain/SpecTypes.js";
5
- import { execMapper, registerJsonSchemaMapper } from "../../registries/JsonSchemaMapperContainer.js";
6
- import { popGenerics } from "../../utils/generics.js";
7
- import { makeOf } from "../../utils/somethingOf.js";
8
- function mapOptions(parameter, options = {}) {
9
- return {
10
- ...options,
11
- groups: parameter.groups,
12
- groupsName: parameter.groupsName
13
- };
14
- }
15
- function getParameters(jsonOperation, options) {
16
- return jsonOperation.get("parameters").filter((parameter) => isParameterType(parameter.get("in")));
17
- }
18
- export function payloadMapper(jsonOperationStore, operationPath, options) {
19
- const parameters = getParameters(jsonOperationStore.operation, options);
20
- const payloadName = pascalCase([operationPath.path, operationPath.method, "Payload"].join(" "));
21
- setValue(options, `components.schemas.${payloadName}`, {});
22
- const allOf = parameters
23
- .map((parameter) => {
24
- const opts = mapOptions(parameter, options);
25
- const jsonSchema = execMapper("item", [parameter.$schema], {
26
- ...opts,
27
- ...popGenerics(parameter)
28
- });
29
- switch (parameter.get("in")) {
30
- case JsonParameterTypes.BODY:
31
- return jsonSchema;
32
- case JsonParameterTypes.QUERY:
33
- case JsonParameterTypes.PATH:
34
- case JsonParameterTypes.HEADER:
35
- return {
36
- type: "object",
37
- properties: {
38
- [parameter.get("name")]: jsonSchema
39
- }
40
- };
41
- }
42
- return jsonSchema;
43
- }, {})
44
- .filter(Boolean);
45
- return makeOf("allOf", allOf);
46
- }
47
- registerJsonSchemaMapper("payload", payloadMapper, SpecTypes.ASYNCAPI);