@tsed/schema 8.19.2 → 8.19.3
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/constants/OperationVerbs.js +35 -0
- package/lib/esm/constants/VendorKeys.js +29 -0
- package/lib/esm/constants/httpStatusMessages.js +59 -0
- package/lib/esm/constants/jsonSchemaProperties.js +55 -0
- package/lib/esm/decorators/class/children.js +93 -5
- package/lib/esm/decorators/class/discriminatorValue.js +124 -20
- package/lib/esm/decorators/collections/collectionContains.js +91 -10
- package/lib/esm/decorators/collections/maxItems.js +97 -27
- package/lib/esm/decorators/collections/maxProperties.js +96 -30
- package/lib/esm/decorators/collections/minItems.js +122 -27
- package/lib/esm/decorators/collections/minProperties.js +132 -31
- package/lib/esm/decorators/common/additionalProperties.js +59 -4
- package/lib/esm/decorators/common/allOf.js +61 -6
- package/lib/esm/decorators/common/allow.js +56 -12
- package/lib/esm/decorators/common/any.js +58 -18
- package/lib/esm/decorators/common/anyOf.js +65 -9
- package/lib/esm/decorators/common/const.js +72 -30
- package/lib/esm/decorators/common/customKey.js +132 -12
- package/lib/esm/decorators/common/default.js +85 -19
- package/lib/esm/decorators/common/discriminatorKey.js +123 -0
- package/lib/esm/decorators/common/errorMsg.js +48 -2
- package/lib/esm/decorators/common/example.js +68 -6
- package/lib/esm/decorators/common/examples.js +99 -6
- package/lib/esm/decorators/common/format.js +86 -52
- package/lib/esm/decorators/common/nullable.js +77 -11
- package/lib/esm/decorators/common/oneOf.js +93 -9
- package/lib/esm/decorators/common/optional.js +93 -4
- package/lib/esm/decorators/common/property.js +42 -6
- package/lib/esm/decorators/common/readOnly.js +106 -5
- package/lib/esm/decorators/common/required.js +57 -20
- package/lib/esm/decorators/common/writeOnly.js +117 -5
- package/lib/esm/domain/JsonClassStore.js +75 -0
- package/lib/esm/domain/JsonDiscriminator.js +57 -0
- package/lib/esm/domain/JsonEntityStore.js +46 -0
- package/lib/esm/domain/JsonFormatTypes.js +39 -0
- package/lib/esm/domain/JsonLazyRef.js +33 -0
- package/lib/esm/domain/JsonMap.js +32 -0
- package/lib/esm/domain/JsonMedia.js +28 -0
- package/lib/esm/domain/JsonMethodStore.js +56 -0
- package/lib/esm/domain/JsonOperation.js +43 -0
- package/lib/esm/domain/JsonOperationPathsMap.js +38 -0
- package/lib/esm/domain/JsonOperationRoute.js +54 -0
- package/lib/esm/domain/JsonParameter.js +35 -0
- package/lib/esm/domain/JsonParameterStore.js +71 -0
- package/lib/esm/domain/JsonParameterTypes.js +26 -0
- package/lib/esm/domain/JsonPropertyStore.js +44 -0
- package/lib/esm/domain/JsonRequestBody.js +26 -0
- package/lib/esm/domain/JsonResponse.js +29 -0
- package/lib/esm/domain/JsonSchema.js +365 -16
- package/lib/esm/domain/SpecTypes.js +26 -0
- package/lib/esm/fn/boolean.js +39 -3
- package/lib/esm/fn/number.js +45 -3
- package/lib/esm/fn/string.js +43 -3
- package/lib/types/constants/OperationVerbs.d.ts +35 -0
- package/lib/types/constants/VendorKeys.d.ts +29 -0
- package/lib/types/constants/httpStatusMessages.d.ts +59 -0
- package/lib/types/constants/jsonSchemaProperties.d.ts +55 -0
- package/lib/types/decorators/class/children.d.ts +93 -5
- package/lib/types/decorators/class/discriminatorValue.d.ts +124 -20
- package/lib/types/decorators/collections/collectionContains.d.ts +91 -10
- package/lib/types/decorators/collections/maxItems.d.ts +97 -27
- package/lib/types/decorators/collections/maxProperties.d.ts +96 -30
- package/lib/types/decorators/collections/minItems.d.ts +122 -27
- package/lib/types/decorators/collections/minProperties.d.ts +132 -31
- package/lib/types/decorators/common/additionalProperties.d.ts +59 -4
- package/lib/types/decorators/common/allOf.d.ts +61 -6
- package/lib/types/decorators/common/allow.d.ts +56 -12
- package/lib/types/decorators/common/any.d.ts +58 -18
- package/lib/types/decorators/common/anyOf.d.ts +65 -9
- package/lib/types/decorators/common/const.d.ts +72 -30
- package/lib/types/decorators/common/customKey.d.ts +132 -12
- package/lib/types/decorators/common/default.d.ts +85 -19
- package/lib/types/decorators/common/discriminatorKey.d.ts +123 -0
- package/lib/types/decorators/common/errorMsg.d.ts +48 -2
- package/lib/types/decorators/common/example.d.ts +68 -6
- package/lib/types/decorators/common/examples.d.ts +99 -6
- package/lib/types/decorators/common/format.d.ts +86 -52
- package/lib/types/decorators/common/nullable.d.ts +77 -11
- package/lib/types/decorators/common/oneOf.d.ts +93 -9
- package/lib/types/decorators/common/optional.d.ts +93 -4
- package/lib/types/decorators/common/property.d.ts +42 -6
- package/lib/types/decorators/common/readOnly.d.ts +106 -5
- package/lib/types/decorators/common/required.d.ts +57 -20
- package/lib/types/decorators/common/writeOnly.d.ts +117 -5
- package/lib/types/domain/JsonClassStore.d.ts +75 -0
- package/lib/types/domain/JsonDiscriminator.d.ts +57 -0
- package/lib/types/domain/JsonEntityStore.d.ts +51 -0
- package/lib/types/domain/JsonFormatTypes.d.ts +39 -0
- package/lib/types/domain/JsonLazyRef.d.ts +33 -0
- package/lib/types/domain/JsonMap.d.ts +32 -0
- package/lib/types/domain/JsonMedia.d.ts +28 -0
- package/lib/types/domain/JsonMethodStore.d.ts +66 -0
- package/lib/types/domain/JsonOperation.d.ts +51 -0
- package/lib/types/domain/JsonOperationPathsMap.d.ts +38 -0
- package/lib/types/domain/JsonOperationRoute.d.ts +54 -0
- package/lib/types/domain/JsonParameter.d.ts +35 -0
- package/lib/types/domain/JsonParameterStore.d.ts +97 -0
- package/lib/types/domain/JsonParameterTypes.d.ts +26 -0
- package/lib/types/domain/JsonPropertyStore.d.ts +44 -0
- package/lib/types/domain/JsonRequestBody.d.ts +31 -0
- package/lib/types/domain/JsonResponse.d.ts +34 -0
- package/lib/types/domain/JsonSchema.d.ts +422 -19
- package/lib/types/domain/SpecTypes.d.ts +26 -0
- package/lib/types/domain/types.d.ts +90 -0
- package/lib/types/fn/boolean.d.ts +39 -3
- package/lib/types/fn/number.d.ts +45 -3
- package/lib/types/fn/string.d.ts +43 -3
- package/lib/types/interfaces/IgnoreCallback.d.ts +24 -0
- package/lib/types/interfaces/JsonHookContext.d.ts +31 -0
- package/lib/types/interfaces/JsonOpenSpec.d.ts +33 -0
- package/lib/types/interfaces/JsonSchemaOptions.d.ts +26 -0
- package/package.json +7 -7
package/lib/types/fn/number.d.ts
CHANGED
|
@@ -1,8 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Create a number schema programmatically.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* This function provides a fluent API for building number schemas without decorators.
|
|
5
|
+
* It returns a JsonSchema instance configured for number type, which can be further
|
|
6
|
+
* customized with validation constraints and other JSON Schema properties.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
8
|
+
* ### Usage
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import {number} from "@tsed/schema";
|
|
12
|
+
*
|
|
13
|
+
* // Basic number schema
|
|
14
|
+
* const ageSchema = number();
|
|
15
|
+
*
|
|
16
|
+
* // Number with range constraints
|
|
17
|
+
* const priceSchema = number()
|
|
18
|
+
* .minimum(0)
|
|
19
|
+
* .maximum(999999.99)
|
|
20
|
+
* .description("Product price in USD");
|
|
21
|
+
*
|
|
22
|
+
* // Integer with exclusive bounds
|
|
23
|
+
* const scoreSchema = number()
|
|
24
|
+
* .integer()
|
|
25
|
+
* .exclusiveMinimum(0)
|
|
26
|
+
* .exclusiveMaximum(100);
|
|
27
|
+
*
|
|
28
|
+
* // Multiple of constraint
|
|
29
|
+
* const quantitySchema = number()
|
|
30
|
+
* .multipleOf(5)
|
|
31
|
+
* .minimum(0)
|
|
32
|
+
* .description("Quantity in packs of 5");
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* ### Available Methods
|
|
36
|
+
*
|
|
37
|
+
* The returned JsonSchema provides many chainable methods:
|
|
38
|
+
* - `minimum(n)` / `maximum(n)` - Range constraints (inclusive)
|
|
39
|
+
* - `exclusiveMinimum(n)` / `exclusiveMaximum(n)` - Range constraints (exclusive)
|
|
40
|
+
* - `multipleOf(n)` - Value must be multiple of n
|
|
41
|
+
* - `integer()` - Restrict to integers only
|
|
42
|
+
* - `description(text)` - Add description
|
|
43
|
+
* - `default(value)` - Set default value
|
|
44
|
+
* - `nullable()` - Allow null values
|
|
45
|
+
*
|
|
46
|
+
* @returns A new JsonSchema configured as a number type
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
7
49
|
*/
|
|
8
50
|
export declare function number(): import("../index.js").JsonSchema<number>;
|
package/lib/types/fn/string.d.ts
CHANGED
|
@@ -1,8 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Create a string schema programmatically.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* This function provides a fluent API for building string schemas without decorators.
|
|
5
|
+
* It returns a JsonSchema instance configured for string type, which can be further
|
|
6
|
+
* customized with validation constraints, formats, and other JSON Schema properties.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
8
|
+
* ### Usage
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import {string} from "@tsed/schema";
|
|
12
|
+
*
|
|
13
|
+
* // Basic string schema
|
|
14
|
+
* const nameSchema = string();
|
|
15
|
+
*
|
|
16
|
+
* // String with constraints
|
|
17
|
+
* const emailSchema = string()
|
|
18
|
+
* .format("email")
|
|
19
|
+
* .minLength(5)
|
|
20
|
+
* .maxLength(100)
|
|
21
|
+
* .description("User email address");
|
|
22
|
+
*
|
|
23
|
+
* // String with pattern
|
|
24
|
+
* const phoneSchema = string()
|
|
25
|
+
* .pattern(/^\d{3}-\d{3}-\d{4}$/)
|
|
26
|
+
* .description("Phone number in format: 123-456-7890");
|
|
27
|
+
*
|
|
28
|
+
* // Enum string
|
|
29
|
+
* const statusSchema = string()
|
|
30
|
+
* .enum("active", "inactive", "pending");
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ### Available Methods
|
|
34
|
+
*
|
|
35
|
+
* The returned JsonSchema provides many chainable methods:
|
|
36
|
+
* - `minLength(n)` / `maxLength(n)` - Length constraints
|
|
37
|
+
* - `pattern(regex)` - Pattern matching
|
|
38
|
+
* - `format(type)` - Format validation (email, uri, date-time, etc.)
|
|
39
|
+
* - `enum(...values)` - Restrict to specific values
|
|
40
|
+
* - `description(text)` - Add description
|
|
41
|
+
* - `default(value)` - Set default value
|
|
42
|
+
* - `nullable()` - Allow null values
|
|
43
|
+
*
|
|
44
|
+
* @returns A new JsonSchema configured as a string type
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
7
47
|
*/
|
|
8
48
|
export declare function string(): import("../index.js").JsonSchema<string>;
|
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import { JsonHookContext } from "./JsonHookContext.js";
|
|
2
|
+
/**
|
|
3
|
+
* Callback function to determine whether a property should be ignored during serialization.
|
|
4
|
+
*
|
|
5
|
+
* This callback is invoked during schema generation to conditionally ignore properties
|
|
6
|
+
* based on the current context and the default ignore value.
|
|
7
|
+
*
|
|
8
|
+
* ### Usage
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const ignoreCallback: IgnoreCallback = (value, ctx) => {
|
|
12
|
+
* // Ignore properties when specific groups are active
|
|
13
|
+
* if (ctx.groups?.includes('admin')) {
|
|
14
|
+
* return false; // Don't ignore for admin group
|
|
15
|
+
* }
|
|
16
|
+
* return value; // Use default ignore value
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param value - The default ignore value for the property
|
|
21
|
+
* @param ctx - The current JSON hook context containing serialization metadata
|
|
22
|
+
* @returns `true` to ignore the property, `false` to include it
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
2
26
|
export interface IgnoreCallback {
|
|
3
27
|
(value: boolean, ctx: JsonHookContext): boolean;
|
|
4
28
|
}
|
|
@@ -4,13 +4,44 @@ declare global {
|
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Context object passed to JSON schema hooks during serialization and schema generation.
|
|
9
|
+
*
|
|
10
|
+
* This context provides information about the current serialization state, including
|
|
11
|
+
* the target instance, active groups, and extensible custom properties. It enables
|
|
12
|
+
* hooks to make context-aware decisions during schema generation and transformation.
|
|
13
|
+
*
|
|
14
|
+
* The interface is extensible via TypeScript module augmentation, allowing packages
|
|
15
|
+
* to add custom context properties through the `TsED.JsonHookContext` namespace.
|
|
16
|
+
*
|
|
17
|
+
* ### Usage
|
|
18
|
+
*
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import {JsonHookContext} from "@tsed/schema";
|
|
21
|
+
*
|
|
22
|
+
* function myHook(value: any, ctx: JsonHookContext) {
|
|
23
|
+
* // Access the target instance
|
|
24
|
+
* console.log(ctx.self);
|
|
25
|
+
*
|
|
26
|
+
* // Check active groups
|
|
27
|
+
* if (ctx.groups?.includes('admin')) {
|
|
28
|
+
* // Apply admin-specific transformations
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
7
35
|
export interface JsonHookContext extends TsED.JsonHookContext {
|
|
8
36
|
/**
|
|
9
37
|
* The current instance used by serializer function
|
|
10
38
|
*/
|
|
11
39
|
self: any;
|
|
12
40
|
/**
|
|
41
|
+
* Active groups for conditional schema generation.
|
|
13
42
|
*
|
|
43
|
+
* When set to an array, only properties belonging to these groups will be included.
|
|
44
|
+
* When set to `false`, group filtering is disabled.
|
|
14
45
|
*/
|
|
15
46
|
groups?: string[] | false;
|
|
16
47
|
[key: string]: any;
|
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
import { OS3Header } from "@tsed/openspec";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP header in JSON schema format, compatible with OpenAPI Specification 3.
|
|
4
|
+
*
|
|
5
|
+
* This interface extends the OpenAPI 3 header specification, allowing full compatibility
|
|
6
|
+
* with OpenAPI header definitions while providing JSON schema integration.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
2
10
|
export interface JsonHeader extends OS3Header {
|
|
3
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Collection of HTTP headers for OpenAPI operations.
|
|
14
|
+
*
|
|
15
|
+
* Headers can be defined as simple values (number or string) or as detailed header
|
|
16
|
+
* objects with schema information. This flexible structure supports both quick
|
|
17
|
+
* header definitions and comprehensive OpenAPI header specifications.
|
|
18
|
+
*
|
|
19
|
+
* ### Usage
|
|
20
|
+
*
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const headers: JsonHeaders = {
|
|
23
|
+
* // Simple header value
|
|
24
|
+
* "X-Rate-Limit": 100,
|
|
25
|
+
*
|
|
26
|
+
* // Detailed header with schema
|
|
27
|
+
* "X-Request-ID": {
|
|
28
|
+
* description: "Unique request identifier",
|
|
29
|
+
* type: "string",
|
|
30
|
+
* value: "abc-123"
|
|
31
|
+
* }
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
4
37
|
export interface JsonHeaders {
|
|
5
38
|
[key: string]: number | string | (JsonHeader & {
|
|
6
39
|
type?: string;
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import { SpecTypes } from "../domain/SpecTypes.js";
|
|
2
2
|
import type { GenericsMap } from "../utils/generics.js";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for JSON schema generation.
|
|
5
|
+
*
|
|
6
|
+
* These options control how JSON schemas are generated from TypeScript classes,
|
|
7
|
+
* including alias mapping, component references, spec type selection, group filtering,
|
|
8
|
+
* and custom key generation. The options affect both JSON Schema and OpenAPI
|
|
9
|
+
* specification generation.
|
|
10
|
+
*
|
|
11
|
+
* ### Usage
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import {getJsonSchema, JsonSchemaOptions} from "@tsed/schema";
|
|
15
|
+
*
|
|
16
|
+
* const options: JsonSchemaOptions = {
|
|
17
|
+
* specType: SpecTypes.OPENAPI,
|
|
18
|
+
* specVersion: "3.0.3",
|
|
19
|
+
* groups: ["public"],
|
|
20
|
+
* useAlias: true,
|
|
21
|
+
* customKeys: true
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* const schema = getJsonSchema(MyModel, options);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
3
29
|
export interface JsonSchemaOptions {
|
|
4
30
|
/**
|
|
5
31
|
* Map properties with the alias name. By default, false
|
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.19.
|
|
5
|
+
"version": "8.19.3",
|
|
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.19.
|
|
37
|
+
"@tsed/openspec": "8.19.3",
|
|
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.19.
|
|
47
|
-
"@tsed/core": "8.19.
|
|
48
|
-
"@tsed/hooks": "8.19.
|
|
49
|
-
"@tsed/openspec": "8.19.
|
|
50
|
-
"@tsed/typescript": "8.19.
|
|
46
|
+
"@tsed/barrels": "8.19.3",
|
|
47
|
+
"@tsed/core": "8.19.3",
|
|
48
|
+
"@tsed/hooks": "8.19.3",
|
|
49
|
+
"@tsed/openspec": "8.19.3",
|
|
50
|
+
"@tsed/typescript": "8.19.3",
|
|
51
51
|
"@types/fs-extra": "11.0.4",
|
|
52
52
|
"@types/json-schema": "7.0.15",
|
|
53
53
|
"@types/picomatch": "3.0.2",
|