@tsed/schema 8.27.0 → 8.28.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.
- package/lib/esm/decorators/common/customKey.js +4 -4
- package/lib/esm/decorators/common/ref.js +15 -0
- package/lib/esm/decorators/generics/generics.js +1 -1
- package/lib/esm/domain/SpecTypes.js +1 -1
- package/lib/esm/fn/index.js +2 -0
- package/lib/esm/fn/ref.js +17 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/registries/JsonSchemaMapperContainer.js +2 -2
- package/lib/esm/utils/compile.js +13 -0
- package/lib/esm/utils/getJsonSchema.js +5 -0
- package/lib/types/decorators/common/customKey.d.ts +4 -4
- package/lib/types/decorators/common/ref.d.ts +9 -0
- package/lib/types/decorators/generics/generics.d.ts +1 -1
- package/lib/types/domain/SpecTypes.d.ts +1 -1
- package/lib/types/fn/index.d.ts +2 -0
- package/lib/types/fn/ref.d.ts +15 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/interfaces/JsonSchemaOptions.d.ts +2 -2
- package/lib/types/registries/JsonSchemaMapperContainer.d.ts +1 -1
- package/lib/types/utils/compile.d.ts +14 -0
- package/lib/types/utils/getJsonSchema.d.ts +2 -1
- package/package.json +7 -7
|
@@ -4,7 +4,7 @@ import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
|
4
4
|
*
|
|
5
5
|
* The `@CustomKey()` decorator allows adding vendor-specific extensions or custom metadata
|
|
6
6
|
* to schemas. These custom keys are only included in the generated schema when explicitly
|
|
7
|
-
* requested with the `customKeys: true` option in `
|
|
7
|
+
* requested with the `customKeys: true` option in `compile()`.
|
|
8
8
|
*
|
|
9
9
|
* ### Basic Usage
|
|
10
10
|
*
|
|
@@ -56,12 +56,12 @@ import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
|
56
56
|
* Custom keys must be explicitly requested:
|
|
57
57
|
*
|
|
58
58
|
* ```typescript
|
|
59
|
-
* import {
|
|
59
|
+
* import { compile } from "@tsed/schema";
|
|
60
60
|
*
|
|
61
|
-
* const schema =
|
|
61
|
+
* const schema = compile(UserModel, { customKeys: true });
|
|
62
62
|
* // Schema will include x-internal-id and other custom keys
|
|
63
63
|
*
|
|
64
|
-
* const standardSchema =
|
|
64
|
+
* const standardSchema = compile(UserModel);
|
|
65
65
|
* // Custom keys are omitted by default
|
|
66
66
|
* ```
|
|
67
67
|
*
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { JsonEntityFn } from "./jsonEntityFn.js";
|
|
2
|
+
/**
|
|
3
|
+
* Set a `$ref` value on the current schema property/parameter.
|
|
4
|
+
*
|
|
5
|
+
* Supports local references (`#/...`) and external URLs.
|
|
6
|
+
*
|
|
7
|
+
* @param ref - Reference URI
|
|
8
|
+
* @decorator
|
|
9
|
+
*/
|
|
10
|
+
export function Ref(ref) {
|
|
11
|
+
return JsonEntityFn((entity) => {
|
|
12
|
+
entity.itemSchema.delete("type");
|
|
13
|
+
entity.itemSchema.$ref(ref);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JsonEntityStore } from "../../domain/JsonEntityStore.js";
|
|
2
2
|
/**
|
|
3
|
-
* Define generics list. This list is used by @@GenericOf@@ and the @@
|
|
3
|
+
* Define generics list. This list is used by @@GenericOf@@ and the @@compile@@ function to build the correct JsonSchema.
|
|
4
4
|
*
|
|
5
5
|
* See @@GenericOf@@ decorator for more details.
|
|
6
6
|
*
|
package/lib/esm/fn/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { lazyRef } from "./lazyRef.js";
|
|
|
12
12
|
import { number } from "./number.js";
|
|
13
13
|
import { object } from "./object.js";
|
|
14
14
|
import { oneOf } from "./oneOf.js";
|
|
15
|
+
import { ref } from "./ref.js";
|
|
15
16
|
import { string } from "./string.js";
|
|
16
17
|
import { uri } from "./uri.js";
|
|
17
18
|
import { url } from "./url.js";
|
|
@@ -39,6 +40,7 @@ export const s = {
|
|
|
39
40
|
lazyRef,
|
|
40
41
|
object,
|
|
41
42
|
oneOf,
|
|
43
|
+
$ref: ref,
|
|
42
44
|
string,
|
|
43
45
|
uri,
|
|
44
46
|
url
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { JsonSchema } from "../domain/JsonSchema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create a schema reference from an external or internal `$ref` URI.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const UserRef = ref("https://api.example.com/doc/swagger.json#/components/schemas/User");
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param path - The reference URI
|
|
12
|
+
* @returns A JsonSchema containing the `$ref`
|
|
13
|
+
* @schemaFunctional
|
|
14
|
+
*/
|
|
15
|
+
export function ref(path) {
|
|
16
|
+
return new JsonSchema().$ref(path);
|
|
17
|
+
}
|
package/lib/esm/index.js
CHANGED
|
@@ -80,6 +80,7 @@ export * from "./decorators/common/pattern.js";
|
|
|
80
80
|
export * from "./decorators/common/property.js";
|
|
81
81
|
export * from "./decorators/common/readOnly.js";
|
|
82
82
|
export * from "./decorators/common/recordOf.js";
|
|
83
|
+
export * from "./decorators/common/ref.js";
|
|
83
84
|
export * from "./decorators/common/required.js";
|
|
84
85
|
export * from "./decorators/common/requiredGroups.js";
|
|
85
86
|
export * from "./decorators/common/schema.js";
|
|
@@ -150,6 +151,7 @@ export * from "./fn/lazyRef.js";
|
|
|
150
151
|
export * from "./fn/number.js";
|
|
151
152
|
export * from "./fn/object.js";
|
|
152
153
|
export * from "./fn/oneOf.js";
|
|
154
|
+
export * from "./fn/ref.js";
|
|
153
155
|
export * from "./fn/string.js";
|
|
154
156
|
export * from "./fn/uri.js";
|
|
155
157
|
export * from "./fn/url.js";
|
|
@@ -163,6 +165,7 @@ export * from "./interfaces/JsonSchemaOptions.js";
|
|
|
163
165
|
export * from "./registries/enumRegistries.js";
|
|
164
166
|
export * from "./registries/JsonSchemaMapperContainer.js";
|
|
165
167
|
export * from "./utils/buildPath.js";
|
|
168
|
+
export * from "./utils/compile.js";
|
|
166
169
|
export * from "./utils/concatParameters.js";
|
|
167
170
|
export * from "./utils/concatPath.js";
|
|
168
171
|
export * from "./utils/defineStatusModel.js";
|
|
@@ -11,7 +11,7 @@ export function registerJsonSchemaMapper(type, mapper, spec) {
|
|
|
11
11
|
/**
|
|
12
12
|
* @ignore
|
|
13
13
|
*/
|
|
14
|
-
export function
|
|
14
|
+
export function compileMapper(type, options) {
|
|
15
15
|
const mapper = JsonSchemaMappersContainer.get(`${options?.specType}:${type}`) || JsonSchemaMappersContainer.get(type);
|
|
16
16
|
if (mapper) {
|
|
17
17
|
return mapper;
|
|
@@ -23,7 +23,7 @@ export function getJsonSchemaMapper(type, options) {
|
|
|
23
23
|
* @ignore
|
|
24
24
|
*/
|
|
25
25
|
export function execMapper(type, args, options, parent) {
|
|
26
|
-
return
|
|
26
|
+
return compileMapper(type, options)(...args, options, parent);
|
|
27
27
|
}
|
|
28
28
|
export function hasMapper(type) {
|
|
29
29
|
return JsonSchemaMappersContainer.has(type);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getJsonSchema } from "./getJsonSchema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compile a class, parameter store, or `JsonSchema` into a plain JSON schema object.
|
|
4
|
+
*
|
|
5
|
+
* This is an alias of `getJsonSchema(...)`.
|
|
6
|
+
*
|
|
7
|
+
* @param model Class, parameter store, or `JsonSchema` to compile.
|
|
8
|
+
* @param options JSON schema generation options.
|
|
9
|
+
* @returns Compiled JSON schema object.
|
|
10
|
+
*/
|
|
11
|
+
export function compile(model, options = {}) {
|
|
12
|
+
return getJsonSchema(model, options);
|
|
13
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "../components/index.js";
|
|
2
2
|
import { getValue, isClass, isPlainObject, nameOf } from "@tsed/core";
|
|
3
3
|
import { JsonParameterStore } from "../domain/JsonParameterStore.js";
|
|
4
|
+
import { JsonSchema } from "../domain/JsonSchema.js";
|
|
4
5
|
import { SpecTypes } from "../domain/SpecTypes.js";
|
|
5
6
|
import { execMapper } from "../registries/JsonSchemaMapperContainer.js";
|
|
6
7
|
import { getJsonEntityStore } from "./getJsonEntityStore.js";
|
|
@@ -27,6 +28,10 @@ function get(model, options) {
|
|
|
27
28
|
CACHES.set(model, cache);
|
|
28
29
|
const key = getKey(options);
|
|
29
30
|
if (!cache.has(key)) {
|
|
31
|
+
if (model instanceof JsonSchema) {
|
|
32
|
+
cache.set(key, model.toJSON(options));
|
|
33
|
+
return cache.get(key);
|
|
34
|
+
}
|
|
30
35
|
const entity = getJsonEntityStore(model);
|
|
31
36
|
let mapper = "schema";
|
|
32
37
|
if (entity instanceof JsonParameterStore) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The `@CustomKey()` decorator allows adding vendor-specific extensions or custom metadata
|
|
5
5
|
* to schemas. These custom keys are only included in the generated schema when explicitly
|
|
6
|
-
* requested with the `customKeys: true` option in `
|
|
6
|
+
* requested with the `customKeys: true` option in `compile()`.
|
|
7
7
|
*
|
|
8
8
|
* ### Basic Usage
|
|
9
9
|
*
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
* Custom keys must be explicitly requested:
|
|
56
56
|
*
|
|
57
57
|
* ```typescript
|
|
58
|
-
* import {
|
|
58
|
+
* import { compile } from "@tsed/schema";
|
|
59
59
|
*
|
|
60
|
-
* const schema =
|
|
60
|
+
* const schema = compile(UserModel, { customKeys: true });
|
|
61
61
|
* // Schema will include x-internal-id and other custom keys
|
|
62
62
|
*
|
|
63
|
-
* const standardSchema =
|
|
63
|
+
* const standardSchema = compile(UserModel);
|
|
64
64
|
* // Custom keys are omitted by default
|
|
65
65
|
* ```
|
|
66
66
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Define generics list. This list is used by @@GenericOf@@ and the @@
|
|
2
|
+
* Define generics list. This list is used by @@GenericOf@@ and the @@compile@@ function to build the correct JsonSchema.
|
|
3
3
|
*
|
|
4
4
|
* See @@GenericOf@@ decorator for more details.
|
|
5
5
|
*
|
package/lib/types/fn/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { lazyRef } from "./lazyRef.js";
|
|
|
13
13
|
import { number } from "./number.js";
|
|
14
14
|
import { object } from "./object.js";
|
|
15
15
|
import { oneOf } from "./oneOf.js";
|
|
16
|
+
import { ref } from "./ref.js";
|
|
16
17
|
import { string } from "./string.js";
|
|
17
18
|
import { uri } from "./uri.js";
|
|
18
19
|
import { url } from "./url.js";
|
|
@@ -40,6 +41,7 @@ export declare const s: {
|
|
|
40
41
|
readonly lazyRef: typeof lazyRef;
|
|
41
42
|
readonly object: typeof object;
|
|
42
43
|
readonly oneOf: typeof oneOf;
|
|
44
|
+
readonly $ref: typeof ref;
|
|
43
45
|
readonly string: typeof string;
|
|
44
46
|
readonly uri: typeof uri;
|
|
45
47
|
readonly url: typeof url;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { JsonSchema } from "../domain/JsonSchema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create a schema reference from an external or internal `$ref` URI.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const UserRef = ref("https://api.example.com/doc/swagger.json#/components/schemas/User");
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param path - The reference URI
|
|
12
|
+
* @returns A JsonSchema containing the `$ref`
|
|
13
|
+
* @schemaFunctional
|
|
14
|
+
*/
|
|
15
|
+
export declare function ref<T = unknown>(path: string): JsonSchema<T>;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -80,6 +80,7 @@ export * from "./decorators/common/pattern.js";
|
|
|
80
80
|
export * from "./decorators/common/property.js";
|
|
81
81
|
export * from "./decorators/common/readOnly.js";
|
|
82
82
|
export * from "./decorators/common/recordOf.js";
|
|
83
|
+
export * from "./decorators/common/ref.js";
|
|
83
84
|
export * from "./decorators/common/required.js";
|
|
84
85
|
export * from "./decorators/common/requiredGroups.js";
|
|
85
86
|
export * from "./decorators/common/schema.js";
|
|
@@ -150,6 +151,7 @@ export * from "./fn/lazyRef.js";
|
|
|
150
151
|
export * from "./fn/number.js";
|
|
151
152
|
export * from "./fn/object.js";
|
|
152
153
|
export * from "./fn/oneOf.js";
|
|
154
|
+
export * from "./fn/ref.js";
|
|
153
155
|
export * from "./fn/string.js";
|
|
154
156
|
export * from "./fn/uri.js";
|
|
155
157
|
export * from "./fn/url.js";
|
|
@@ -163,6 +165,7 @@ export * from "./interfaces/JsonSchemaOptions.js";
|
|
|
163
165
|
export * from "./registries/enumRegistries.js";
|
|
164
166
|
export * from "./registries/JsonSchemaMapperContainer.js";
|
|
165
167
|
export * from "./utils/buildPath.js";
|
|
168
|
+
export * from "./utils/compile.js";
|
|
166
169
|
export * from "./utils/concatParameters.js";
|
|
167
170
|
export * from "./utils/concatPath.js";
|
|
168
171
|
export * from "./utils/defineStatusModel.js";
|
|
@@ -11,7 +11,7 @@ import type { GenericsMap } from "../utils/generics.js";
|
|
|
11
11
|
* ### Usage
|
|
12
12
|
*
|
|
13
13
|
* ```typescript
|
|
14
|
-
* import {
|
|
14
|
+
* import {compile, JsonSchemaOptions} from "@tsed/schema";
|
|
15
15
|
*
|
|
16
16
|
* const options: JsonSchemaOptions = {
|
|
17
17
|
* specType: SpecTypes.OPENAPI,
|
|
@@ -21,7 +21,7 @@ import type { GenericsMap } from "../utils/generics.js";
|
|
|
21
21
|
* customKeys: true
|
|
22
22
|
* };
|
|
23
23
|
*
|
|
24
|
-
* const schema =
|
|
24
|
+
* const schema = compile(MyModel, options);
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
27
|
* @public
|
|
@@ -12,7 +12,7 @@ export declare function registerJsonSchemaMapper(type: string, mapper: JsonSchem
|
|
|
12
12
|
/**
|
|
13
13
|
* @ignore
|
|
14
14
|
*/
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function compileMapper(type: string, options: any): JsonSchemaMapper;
|
|
16
16
|
/**
|
|
17
17
|
* @ignore
|
|
18
18
|
*/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
import { JsonParameterStore } from "../domain/JsonParameterStore.js";
|
|
3
|
+
import { JsonSchema } from "../domain/JsonSchema.js";
|
|
4
|
+
import { JsonSchemaOptions } from "../interfaces/JsonSchemaOptions.js";
|
|
5
|
+
/**
|
|
6
|
+
* Compile a class, parameter store, or `JsonSchema` into a plain JSON schema object.
|
|
7
|
+
*
|
|
8
|
+
* This is an alias of `getJsonSchema(...)`.
|
|
9
|
+
*
|
|
10
|
+
* @param model Class, parameter store, or `JsonSchema` to compile.
|
|
11
|
+
* @param options JSON schema generation options.
|
|
12
|
+
* @returns Compiled JSON schema object.
|
|
13
|
+
*/
|
|
14
|
+
export declare function compile(model: Type<any> | JsonParameterStore | JsonSchema, options?: JsonSchemaOptions): any;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "../components/index.js";
|
|
2
2
|
import { Type } from "@tsed/core";
|
|
3
3
|
import { JsonParameterStore } from "../domain/JsonParameterStore.js";
|
|
4
|
+
import { JsonSchema } from "../domain/JsonSchema.js";
|
|
4
5
|
import { JsonSchemaOptions } from "../interfaces/JsonSchemaOptions.js";
|
|
5
|
-
export declare function getJsonSchema(model: Type<any> | JsonParameterStore, options?: JsonSchemaOptions): any;
|
|
6
|
+
export declare function getJsonSchema(model: Type<any> | JsonParameterStore | JsonSchema, options?: JsonSchemaOptions): any;
|
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.
|
|
5
|
+
"version": "8.28.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.
|
|
37
|
+
"@tsed/openspec": "8.28.1",
|
|
38
38
|
"change-case": "^5.4.4",
|
|
39
39
|
"json-schema": "0.4.0",
|
|
40
40
|
"picomatch": "4.0.4",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@apidevtools/swagger-parser": "10.1.0",
|
|
46
|
-
"@tsed/barrels": "8.
|
|
47
|
-
"@tsed/core": "8.
|
|
48
|
-
"@tsed/hooks": "8.
|
|
49
|
-
"@tsed/openspec": "8.
|
|
50
|
-
"@tsed/typescript": "8.
|
|
46
|
+
"@tsed/barrels": "8.28.1",
|
|
47
|
+
"@tsed/core": "8.28.1",
|
|
48
|
+
"@tsed/hooks": "8.28.1",
|
|
49
|
+
"@tsed/openspec": "8.28.1",
|
|
50
|
+
"@tsed/typescript": "8.28.1",
|
|
51
51
|
"@types/fs-extra": "11.0.4",
|
|
52
52
|
"@types/json-schema": "7.0.15",
|
|
53
53
|
"@types/picomatch": "3.0.2",
|