@tsed/schema 8.1.0 → 8.3.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.
- package/lib/browser/schema.umd.min.js +1 -1
- package/lib/browser/schema.umd.min.js.map +1 -1
- package/lib/esm/components/default/anyMapper.js +2 -2
- package/lib/esm/components/default/anyMapper.js.map +1 -1
- package/lib/esm/components/default/inheritedClassMapper.js +16 -2
- package/lib/esm/components/default/inheritedClassMapper.js.map +1 -1
- package/lib/esm/decorators/common/labelledAs.js +35 -0
- package/lib/esm/decorators/common/labelledAs.js.map +1 -0
- package/lib/esm/decorators/generics/genericOf.js +1 -1
- package/lib/esm/decorators/generics/genericOf.js.map +1 -1
- package/lib/esm/decorators/operations/returns.js +1 -1
- package/lib/esm/decorators/operations/returns.js.map +1 -1
- package/lib/esm/fn/allOf.js +12 -0
- package/lib/esm/fn/allOf.js.map +1 -0
- package/lib/esm/fn/any.js +10 -0
- package/lib/esm/fn/any.js.map +1 -0
- package/lib/esm/fn/anyOf.js +12 -0
- package/lib/esm/fn/anyOf.js.map +1 -0
- package/lib/esm/fn/boolean.js +10 -0
- package/lib/esm/fn/boolean.js.map +1 -0
- package/lib/esm/fn/collection.js +50 -0
- package/lib/esm/fn/collection.js.map +1 -0
- package/lib/esm/fn/date.js +27 -0
- package/lib/esm/fn/date.js.map +1 -0
- package/lib/esm/fn/email.js +18 -0
- package/lib/esm/fn/email.js.map +1 -0
- package/lib/esm/fn/enums.js +8 -0
- package/lib/esm/fn/enums.js.map +1 -0
- package/lib/esm/fn/from.js +28 -0
- package/lib/esm/fn/from.js.map +1 -0
- package/lib/esm/fn/integer.js +13 -0
- package/lib/esm/fn/integer.js.map +1 -0
- package/lib/esm/fn/lazyRef.js +17 -0
- package/lib/esm/fn/lazyRef.js.map +1 -0
- package/lib/esm/fn/number.js +10 -0
- package/lib/esm/fn/number.js.map +1 -0
- package/lib/esm/fn/object.js +22 -0
- package/lib/esm/fn/object.js.map +1 -0
- package/lib/esm/fn/oneOf.js +13 -0
- package/lib/esm/fn/oneOf.js.map +1 -0
- package/lib/esm/fn/string.js +10 -0
- package/lib/esm/fn/string.js.map +1 -0
- package/lib/esm/fn/uri.js +13 -0
- package/lib/esm/fn/uri.js.map +1 -0
- package/lib/esm/fn/url.js +11 -0
- package/lib/esm/fn/url.js.map +1 -0
- package/lib/esm/index.js +18 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/registries/JsonSchemaMapperContainer.js +1 -1
- package/lib/esm/registries/JsonSchemaMapperContainer.js.map +1 -1
- package/lib/esm/utils/ref.js.map +1 -1
- package/lib/types/decorators/common/labelledAs.d.ts +24 -0
- package/lib/types/fn/allOf.d.ts +9 -0
- package/lib/types/fn/any.d.ts +7 -0
- package/lib/types/fn/anyOf.d.ts +9 -0
- package/lib/types/fn/boolean.d.ts +7 -0
- package/lib/types/fn/collection.d.ts +43 -0
- package/lib/types/fn/date.d.ts +19 -0
- package/lib/types/fn/email.d.ts +14 -0
- package/lib/types/fn/enums.d.ts +1 -0
- package/lib/types/fn/from.d.ts +14 -0
- package/lib/types/fn/integer.d.ts +10 -0
- package/lib/types/fn/lazyRef.d.ts +5 -0
- package/lib/types/fn/number.d.ts +6 -0
- package/lib/types/fn/object.d.ts +21 -0
- package/lib/types/fn/oneOf.d.ts +10 -0
- package/lib/types/fn/string.d.ts +7 -0
- package/lib/types/fn/uri.d.ts +9 -0
- package/lib/types/fn/url.d.ts +7 -0
- package/lib/types/index.d.ts +18 -1
- package/lib/types/registries/JsonSchemaMapperContainer.d.ts +1 -1
- package/package.json +10 -10
- package/src/components/default/anyMapper.ts +2 -2
- package/src/components/default/inheritedClassMapper.ts +19 -2
- package/src/decorators/collections/collectionOf.spec.ts +2 -1
- package/src/decorators/common/allOf.spec.ts +2 -1
- package/src/decorators/common/anyOf.spec.ts +2 -1
- package/src/decorators/common/enum.spec.ts +1 -1
- package/src/decorators/common/labelledAs.spec.ts +85 -0
- package/src/decorators/common/labelledAs.ts +34 -0
- package/src/decorators/common/oneOf.spec.ts +2 -1
- package/src/decorators/generics/genericOf.ts +1 -1
- package/src/decorators/operations/returns.ts +1 -1
- package/src/fn/allOf.ts +13 -0
- package/src/fn/any.ts +11 -0
- package/src/fn/anyOf.ts +13 -0
- package/src/fn/boolean.ts +11 -0
- package/src/fn/collection.ts +53 -0
- package/src/fn/date.ts +30 -0
- package/src/fn/email.ts +19 -0
- package/src/fn/enums.ts +9 -0
- package/src/{utils → fn}/from.spec.ts +14 -83
- package/src/fn/from.ts +33 -0
- package/src/fn/integer.ts +13 -0
- package/src/fn/layzRef.spec.ts +70 -0
- package/src/fn/lazyRef.ts +19 -0
- package/src/fn/number.ts +10 -0
- package/src/fn/object.ts +23 -0
- package/src/fn/oneOf.ts +14 -0
- package/src/fn/string.ts +11 -0
- package/src/fn/uri.ts +14 -0
- package/src/fn/url.ts +12 -0
- package/src/index.ts +18 -1
- package/src/registries/JsonSchemaMapperContainer.ts +1 -1
- package/src/utils/ref.ts +0 -1
- package/lib/esm/utils/from.js +0 -256
- package/lib/esm/utils/from.js.map +0 -1
- package/lib/types/utils/from.d.ts +0 -190
- package/src/utils/from.ts +0 -281
package/src/fn/anyOf.ts
ADDED
|
@@ -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.27
|
|
6
|
+
*
|
|
7
|
+
* * See @@JsonSchema@@ to discover available methods.
|
|
8
|
+
*
|
|
9
|
+
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27
|
|
10
|
+
*/
|
|
11
|
+
export function anyOf(...anyOf: AnyJsonSchema[]): JsonSchema {
|
|
12
|
+
return from().anyOf(anyOf);
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
2
|
+
import {from} from "./from.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Declare a new boolean model.
|
|
6
|
+
*
|
|
7
|
+
* * See @@JsonSchema@@ to discover available methods.
|
|
8
|
+
*/
|
|
9
|
+
export function boolean(): JsonSchema {
|
|
10
|
+
return from(Boolean);
|
|
11
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
2
|
+
import {from} from "./from.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Declare a new object model with `additionalProperties: true`.
|
|
6
|
+
*
|
|
7
|
+
* ```json
|
|
8
|
+
* {
|
|
9
|
+
* "type": "array"
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* * See @@JsonSchema@@ to discover available methods.
|
|
14
|
+
*
|
|
15
|
+
* @schemaFunctional
|
|
16
|
+
*/
|
|
17
|
+
export function array(): JsonSchema {
|
|
18
|
+
return from(Array);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Declare a new object model with `additionalProperties: true`.
|
|
23
|
+
*
|
|
24
|
+
* ```json
|
|
25
|
+
* {
|
|
26
|
+
* "type": "object",
|
|
27
|
+
* "additionalProperties": true
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* * See @@JsonSchema@@ to discover available methods.
|
|
32
|
+
*
|
|
33
|
+
* @schemaFunctional
|
|
34
|
+
*/
|
|
35
|
+
export function map(): JsonSchema {
|
|
36
|
+
return from(Map).unknown(true);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Declare a new array model with `uniqueItems: true`.
|
|
41
|
+
*
|
|
42
|
+
* ```json
|
|
43
|
+
* {
|
|
44
|
+
* "type": "array",
|
|
45
|
+
* "uniqueItems": true
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* * See @@JsonSchema@@ to discover available methods.
|
|
50
|
+
*/
|
|
51
|
+
export function set(): JsonSchema {
|
|
52
|
+
return from(Array).uniqueItems(true);
|
|
53
|
+
}
|
package/src/fn/date.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {JsonFormatTypes} from "../domain/JsonFormatTypes.js";
|
|
2
|
+
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
3
|
+
import {from} from "./from.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Declare a new string model with `format: date`.
|
|
7
|
+
*
|
|
8
|
+
* See @@JsonSchema@@ to discover available methods.
|
|
9
|
+
*/
|
|
10
|
+
export function date(): JsonSchema {
|
|
11
|
+
return from(Date).format(JsonFormatTypes.DATE);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Declare a new string model with `format: datetime`.
|
|
16
|
+
*
|
|
17
|
+
* See @@JsonSchema@@ to discover available methods.
|
|
18
|
+
*/
|
|
19
|
+
export function datetime(): JsonSchema {
|
|
20
|
+
return from(Date).format(JsonFormatTypes.DATE_TIME);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Declare a new string model with `format: time`.
|
|
25
|
+
*
|
|
26
|
+
* See @@JsonSchema@@ to discover available methods.
|
|
27
|
+
*/
|
|
28
|
+
export function time(): JsonSchema {
|
|
29
|
+
return from(Date).format(JsonFormatTypes.TIME);
|
|
30
|
+
}
|
package/src/fn/email.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {JsonFormatTypes} from "../domain/JsonFormatTypes.js";
|
|
2
|
+
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
3
|
+
import {from} from "./from.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Declare a new string model with `format: email`.
|
|
7
|
+
*
|
|
8
|
+
* See @@JsonSchema@@ to discover available methods.
|
|
9
|
+
*
|
|
10
|
+
* ### Example
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const schema = email();
|
|
14
|
+
* // Results in: { type: "string", format: "email" }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function email(): JsonSchema {
|
|
18
|
+
return from(String).format(JsonFormatTypes.EMAIL);
|
|
19
|
+
}
|
package/src/fn/enums.ts
ADDED
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
import "../index.js";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
map,
|
|
18
|
-
number,
|
|
19
|
-
object,
|
|
20
|
-
set,
|
|
21
|
-
string,
|
|
22
|
-
time,
|
|
23
|
-
uri,
|
|
24
|
-
url
|
|
25
|
-
} from "./from.js";
|
|
3
|
+
import {allOf} from "./allOf.js";
|
|
4
|
+
import {any} from "./any.js";
|
|
5
|
+
import {anyOf} from "./anyOf.js";
|
|
6
|
+
import {boolean} from "./boolean.js";
|
|
7
|
+
import {array, map, set} from "./collection.js";
|
|
8
|
+
import {date, datetime, time} from "./date.js";
|
|
9
|
+
import {email} from "./email.js";
|
|
10
|
+
import {from} from "./from.js";
|
|
11
|
+
import {integer} from "./integer.js";
|
|
12
|
+
import {number} from "./number.js";
|
|
13
|
+
import {object} from "./object.js";
|
|
14
|
+
import {string} from "./string.js";
|
|
15
|
+
import {uri} from "./uri.js";
|
|
16
|
+
import {url} from "./url.js";
|
|
26
17
|
|
|
27
18
|
describe("from", () => {
|
|
28
19
|
it("should declare a model", () => {
|
|
@@ -180,64 +171,4 @@ describe("from", () => {
|
|
|
180
171
|
type: "object"
|
|
181
172
|
});
|
|
182
173
|
});
|
|
183
|
-
it("should declare a lazyRef", () => {
|
|
184
|
-
const schema1 = object({
|
|
185
|
-
owners: array().items(lazyRef(() => Owner))
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
class Post {
|
|
189
|
-
@Property()
|
|
190
|
-
id: string;
|
|
191
|
-
|
|
192
|
-
@Property(() => Owner)
|
|
193
|
-
owner: typeof Owner;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
class Owner {
|
|
197
|
-
@Property()
|
|
198
|
-
id: string;
|
|
199
|
-
|
|
200
|
-
@CollectionOf(() => Post)
|
|
201
|
-
posts: Post[];
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
expect(schema1.toJSON()).toEqual({
|
|
205
|
-
definitions: {
|
|
206
|
-
Owner: {
|
|
207
|
-
properties: {
|
|
208
|
-
id: {
|
|
209
|
-
type: "string"
|
|
210
|
-
},
|
|
211
|
-
posts: {
|
|
212
|
-
items: {
|
|
213
|
-
$ref: "#/definitions/Post"
|
|
214
|
-
},
|
|
215
|
-
type: "array"
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
type: "object"
|
|
219
|
-
},
|
|
220
|
-
Post: {
|
|
221
|
-
properties: {
|
|
222
|
-
id: {
|
|
223
|
-
type: "string"
|
|
224
|
-
},
|
|
225
|
-
owner: {
|
|
226
|
-
$ref: "#/definitions/Owner"
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
type: "object"
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
properties: {
|
|
233
|
-
owners: {
|
|
234
|
-
items: {
|
|
235
|
-
$ref: "#/definitions/Owner"
|
|
236
|
-
},
|
|
237
|
-
type: "array"
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
type: "object"
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
174
|
});
|
package/src/fn/from.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {isClass, Type} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonSchema} from "../domain/JsonSchema.js";
|
|
4
|
+
import {getJsonEntityStore} from "../utils/getJsonEntityStore.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a new model from the given type.
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* from(String)
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* * See @@JsonSchema@@ to discover available methods.
|
|
14
|
+
*
|
|
15
|
+
* @schemaFunctional
|
|
16
|
+
*/
|
|
17
|
+
export function from(type: Type<any> = Object) {
|
|
18
|
+
if (isClass(type)) {
|
|
19
|
+
const {schema} = getJsonEntityStore(type);
|
|
20
|
+
|
|
21
|
+
schema.properties = function properties(obj: {[key: string]: JsonSchema}) {
|
|
22
|
+
Object.entries(obj).forEach(([propertyKey, propSchema]) => {
|
|
23
|
+
getJsonEntityStore(type.prototype, propertyKey).schema.assign(propSchema);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return schema;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return JsonSchema.from({type});
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
2
|
+
import {from} from "./from.js";
|
|
3
|
+
/**
|
|
4
|
+
* Declare a new integer model.
|
|
5
|
+
*
|
|
6
|
+
* See @@JsonSchema@@ to discover available methods.
|
|
7
|
+
*
|
|
8
|
+
* @returns {JsonSchema} A schema configured for integer values
|
|
9
|
+
* @function
|
|
10
|
+
*/
|
|
11
|
+
export function integer(): JsonSchema {
|
|
12
|
+
return from(Number).integer();
|
|
13
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import "../index.js";
|
|
2
|
+
|
|
3
|
+
import {CollectionOf} from "../decorators/collections/collectionOf.js";
|
|
4
|
+
import {Property} from "../decorators/common/property.js";
|
|
5
|
+
import {array} from "./collection.js";
|
|
6
|
+
import {lazyRef} from "./lazyRef.js";
|
|
7
|
+
import {object} from "./object.js";
|
|
8
|
+
|
|
9
|
+
describe("lazyRef", () => {
|
|
10
|
+
it("should declare a lazyRef", () => {
|
|
11
|
+
const schema1 = object({
|
|
12
|
+
owners: array().items(lazyRef(() => Owner))
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
class Post {
|
|
16
|
+
@Property()
|
|
17
|
+
id: string;
|
|
18
|
+
|
|
19
|
+
@Property(() => Owner)
|
|
20
|
+
owner: typeof Owner;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class Owner {
|
|
24
|
+
@Property()
|
|
25
|
+
id: string;
|
|
26
|
+
|
|
27
|
+
@CollectionOf(() => Post)
|
|
28
|
+
posts: Post[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
expect(schema1.toJSON()).toEqual({
|
|
32
|
+
definitions: {
|
|
33
|
+
Owner: {
|
|
34
|
+
properties: {
|
|
35
|
+
id: {
|
|
36
|
+
type: "string"
|
|
37
|
+
},
|
|
38
|
+
posts: {
|
|
39
|
+
items: {
|
|
40
|
+
$ref: "#/definitions/Post"
|
|
41
|
+
},
|
|
42
|
+
type: "array"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
type: "object"
|
|
46
|
+
},
|
|
47
|
+
Post: {
|
|
48
|
+
properties: {
|
|
49
|
+
id: {
|
|
50
|
+
type: "string"
|
|
51
|
+
},
|
|
52
|
+
owner: {
|
|
53
|
+
$ref: "#/definitions/Owner"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
type: "object"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
properties: {
|
|
60
|
+
owners: {
|
|
61
|
+
items: {
|
|
62
|
+
$ref: "#/definitions/Owner"
|
|
63
|
+
},
|
|
64
|
+
type: "array"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
type: "object"
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type {Type} from "@tsed/core";
|
|
2
|
+
|
|
3
|
+
import {JsonEntityStore} from "../domain/JsonEntityStore.js";
|
|
4
|
+
import {JsonLazyRef} from "../domain/JsonLazyRef.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Declare a sub schema which will be resolved later. Use this function when you have a circular reference between two schemes.
|
|
8
|
+
*/
|
|
9
|
+
export function lazyRef(cb: () => Type<any>) {
|
|
10
|
+
try {
|
|
11
|
+
// solve issue with a self referenced model
|
|
12
|
+
if (cb()) {
|
|
13
|
+
// type is already accessible
|
|
14
|
+
return JsonEntityStore.from(cb()).schema as any;
|
|
15
|
+
}
|
|
16
|
+
} catch (er) {}
|
|
17
|
+
|
|
18
|
+
return new JsonLazyRef(cb);
|
|
19
|
+
}
|
package/src/fn/number.ts
ADDED
package/src/fn/object.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {JsonSchema} from "../domain/JsonSchema.js";
|
|
2
|
+
import {from} from "./from.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Declare a new object model.
|
|
6
|
+
*
|
|
7
|
+
* See @@JsonSchema@@ to discover available methods.
|
|
8
|
+
*
|
|
9
|
+
* ### Example
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const userSchema = object({
|
|
13
|
+
* name: string(),
|
|
14
|
+
* age: number()
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param properties - An object containing property definitions where each value is a JsonSchema
|
|
19
|
+
* @returns {JsonSchema} A new object model with the specified properties
|
|
20
|
+
*/
|
|
21
|
+
export function object(properties: {[key: string]: JsonSchema} = {}): JsonSchema {
|
|
22
|
+
return from(Object).properties(properties);
|
|
23
|
+
}
|
package/src/fn/oneOf.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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.28
|
|
6
|
+
*
|
|
7
|
+
* * See @@JsonSchema@@ to discover available methods.
|
|
8
|
+
*
|
|
9
|
+
* @schemaFunctional
|
|
10
|
+
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28
|
|
11
|
+
*/
|
|
12
|
+
export function oneOf(...oneOf: AnyJsonSchema[]): JsonSchema {
|
|
13
|
+
return from().oneOf(oneOf);
|
|
14
|
+
}
|
package/src/fn/string.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
2
|
+
import {from} from "./from.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Declare a new string model.
|
|
6
|
+
*
|
|
7
|
+
* See @@JsonSchema@@ to discover available methods.
|
|
8
|
+
*/
|
|
9
|
+
export function string(): JsonSchema {
|
|
10
|
+
return from(String);
|
|
11
|
+
}
|
package/src/fn/uri.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {JsonFormatTypes} from "../domain/JsonFormatTypes.js";
|
|
2
|
+
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
3
|
+
import {from} from "./from.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Declare a new string model with `format: uri`.
|
|
7
|
+
*
|
|
8
|
+
* * See @@JsonSchema@@ to discover available methods.
|
|
9
|
+
*
|
|
10
|
+
* @schemaFunctional
|
|
11
|
+
*/
|
|
12
|
+
export function uri(): JsonSchema {
|
|
13
|
+
return from(String).format(JsonFormatTypes.URI);
|
|
14
|
+
}
|
package/src/fn/url.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {JsonFormatTypes} from "../domain/JsonFormatTypes.js";
|
|
2
|
+
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
3
|
+
import {from} from "./from.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Declare a new string model with `format: url`.
|
|
7
|
+
*
|
|
8
|
+
* See @@JsonSchema@@ to discover available methods.
|
|
9
|
+
*/
|
|
10
|
+
export function url(): JsonSchema {
|
|
11
|
+
return from(String).format(JsonFormatTypes.URL);
|
|
12
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -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";
|
|
@@ -44,7 +44,7 @@ export function hasMapper(type: string) {
|
|
|
44
44
|
return JsonSchemaMappersContainer.has(type);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export function
|
|
47
|
+
export function execOneOfMapper(types: string[], options: any): string {
|
|
48
48
|
return (
|
|
49
49
|
types.find((type) => JsonSchemaMappersContainer.has(`${options?.specType}:${type}`)) ||
|
|
50
50
|
types.find((type) => JsonSchemaMappersContainer.has(type))!
|
package/src/utils/ref.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {pascalCase} from "change-case";
|
|
|
4
4
|
import type {JsonSchema} from "../domain/JsonSchema.js";
|
|
5
5
|
import {SpecTypes} from "../domain/SpecTypes.js";
|
|
6
6
|
import {JsonSchemaOptions} from "../interfaces/JsonSchemaOptions.js";
|
|
7
|
-
import {anyOf} from "./from.js";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* ignore
|