@tsed/schema 8.19.2 → 8.19.4
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/components/open-spec/nullableMapper.js +6 -2
- 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
|
@@ -4,6 +4,15 @@ import { JsonMap } from "./JsonMap.js";
|
|
|
4
4
|
import { JsonParameter } from "./JsonParameter.js";
|
|
5
5
|
import { JsonResponse } from "./JsonResponse.js";
|
|
6
6
|
import { JsonSchema } from "./JsonSchema.js";
|
|
7
|
+
/**
|
|
8
|
+
* Represents an HTTP operation path with metadata for OpenAPI specifications.
|
|
9
|
+
*
|
|
10
|
+
* This class associates an HTTP method and path with operation-level metadata
|
|
11
|
+
* such as summary and description. It's used internally to manage routing
|
|
12
|
+
* information for API endpoints.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
7
16
|
export declare class JsonMethodPath extends JsonMap<any> {
|
|
8
17
|
method: string;
|
|
9
18
|
path: string | RegExp;
|
|
@@ -11,10 +20,52 @@ export declare class JsonMethodPath extends JsonMap<any> {
|
|
|
11
20
|
summary(summary: string): this;
|
|
12
21
|
description(description: string): this;
|
|
13
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration options for JSON operations compatible with OpenAPI 3 specifications.
|
|
25
|
+
*
|
|
26
|
+
* Extends the OpenAPI 3 operation specification with Ts.ED-specific media type
|
|
27
|
+
* declarations (consumes/produces) for request and response handling.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
14
31
|
export interface JsonOperationOptions extends OS3Operation<JsonSchema, JsonParameter, JsonMap<JsonResponse>> {
|
|
15
32
|
consumes: string[];
|
|
16
33
|
produces: string[];
|
|
17
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Represents an HTTP operation (endpoint) with complete OpenAPI metadata.
|
|
37
|
+
*
|
|
38
|
+
* JsonOperation is the core class for defining HTTP endpoints in Ts.ED, storing all
|
|
39
|
+
* operation-level information required for OpenAPI specification generation including:
|
|
40
|
+
*
|
|
41
|
+
* - Request parameters (path, query, header, body)
|
|
42
|
+
* - Response definitions with status codes
|
|
43
|
+
* - Security requirements
|
|
44
|
+
* - Tags and categorization
|
|
45
|
+
* - Media type handling (consumes/produces)
|
|
46
|
+
* - Operation metadata (summary, description, operationId)
|
|
47
|
+
*
|
|
48
|
+
* ### Usage
|
|
49
|
+
*
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const operation = new JsonOperation()
|
|
52
|
+
* .summary("Create a user")
|
|
53
|
+
* .description("Creates a new user in the system")
|
|
54
|
+
* .addTags([{name: "Users"}])
|
|
55
|
+
* .addParameter(0, parameterMetadata)
|
|
56
|
+
* .addResponse(201, responseMetadata);
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* ### Key Features
|
|
60
|
+
*
|
|
61
|
+
* - **Parameters**: Manage operation parameters by index or name
|
|
62
|
+
* - **Responses**: Define responses for different HTTP status codes
|
|
63
|
+
* - **Security**: Configure authentication and authorization
|
|
64
|
+
* - **Media Types**: Specify accepted and produced content types
|
|
65
|
+
* - **Routing**: Multiple path/method combinations per operation
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
18
69
|
export declare class JsonOperation extends JsonMap<JsonOperationOptions> {
|
|
19
70
|
#private;
|
|
20
71
|
$kind: string;
|
|
@@ -1,4 +1,42 @@
|
|
|
1
1
|
import { JsonMethodPath } from "./JsonOperation.js";
|
|
2
|
+
/**
|
|
3
|
+
* Map container for storing HTTP operation paths indexed by method and path.
|
|
4
|
+
*
|
|
5
|
+
* JsonOperationPathsMap maintains a collection of operation paths (HTTP method + URL path
|
|
6
|
+
* combinations) for a controller. It provides efficient lookup and prevents duplicate
|
|
7
|
+
* operations from being registered.
|
|
8
|
+
*
|
|
9
|
+
* ### Key Features
|
|
10
|
+
*
|
|
11
|
+
* - **Unique Keys**: Stores operations using `method-path` composite keys
|
|
12
|
+
* - **Method Safety**: Ensures operations are uniquely identified
|
|
13
|
+
* - **Efficient Lookup**: Fast retrieval of operations by method and path
|
|
14
|
+
* - **Type Safety**: Extends Map with JsonMethodPath values
|
|
15
|
+
*
|
|
16
|
+
* ### Usage
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const pathsMap = new JsonOperationPathsMap();
|
|
20
|
+
*
|
|
21
|
+
* // Add operation path
|
|
22
|
+
* const methodPath = { method: "GET", path: "/users" };
|
|
23
|
+
* pathsMap.setOperationPath(methodPath);
|
|
24
|
+
*
|
|
25
|
+
* // Retrieve by composite key
|
|
26
|
+
* const operation = pathsMap.get("GET-/users");
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ### Key Generation
|
|
30
|
+
*
|
|
31
|
+
* The map uses a composite key format: `{method}-{path}`
|
|
32
|
+
* - Example: `"GET-/users/:id"` for a GET operation on `/users/:id`
|
|
33
|
+
* - Example: `"POST-/users"` for a POST operation on `/users`
|
|
34
|
+
*
|
|
35
|
+
* This ensures that different HTTP methods on the same path are treated as
|
|
36
|
+
* distinct operations.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
2
40
|
export declare class JsonOperationPathsMap extends Map<string, JsonMethodPath> {
|
|
3
41
|
$kind: string;
|
|
4
42
|
readonly $isJsonDocument = true;
|
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
2
|
import { JsonMethodStore } from "./JsonMethodStore.js";
|
|
3
3
|
import { JsonMethodPath, JsonOperation } from "./JsonOperation.js";
|
|
4
|
+
/**
|
|
5
|
+
* Represents a fully resolved HTTP route combining controller and method metadata.
|
|
6
|
+
*
|
|
7
|
+
* JsonOperationRoute provides a unified view of an HTTP endpoint by combining:
|
|
8
|
+
* - Controller class information (token, basePath)
|
|
9
|
+
* - Method metadata (endpoint store)
|
|
10
|
+
* - Operation details (HTTP method, path, parameters)
|
|
11
|
+
* - Full URL computation
|
|
12
|
+
*
|
|
13
|
+
* ### Responsibilities
|
|
14
|
+
*
|
|
15
|
+
* - **URL Resolution**: Combines base path and operation path into full URL
|
|
16
|
+
* - **Metadata Access**: Provides convenient access to operation, parameters, and store
|
|
17
|
+
* - **Route Identification**: Computes route names and operation IDs
|
|
18
|
+
* - **Parameter Type Tracking**: Maintains map of parameter types (query, body, etc.)
|
|
19
|
+
*
|
|
20
|
+
* ### Usage
|
|
21
|
+
*
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Routes are typically created during framework initialization
|
|
24
|
+
* const route = new JsonOperationRoute({
|
|
25
|
+
* token: MyController,
|
|
26
|
+
* endpoint: methodStore,
|
|
27
|
+
* operationPath: { method: "GET", path: "/:id" },
|
|
28
|
+
* basePath: "/users"
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Access route information
|
|
32
|
+
* console.log(route.fullPath); // "/users/:id"
|
|
33
|
+
* console.log(route.method); // "GET"
|
|
34
|
+
* console.log(route.name); // "MyController.getUser()"
|
|
35
|
+
* console.log(route.operationId); // "getUser"
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* ### URL Construction
|
|
39
|
+
*
|
|
40
|
+
* The route combines controller base path with operation path:
|
|
41
|
+
* - Base path: `/users` (from `@Controller("/users")`)
|
|
42
|
+
* - Operation path: `/:id` (from `@Get("/:id")`)
|
|
43
|
+
* - Full path: `/users/:id`
|
|
44
|
+
*
|
|
45
|
+
* ### Parameter Type Detection
|
|
46
|
+
*
|
|
47
|
+
* The route maintains a map of parameter types present in the operation:
|
|
48
|
+
* ```typescript
|
|
49
|
+
* route.has("query") // true if operation has @QueryParams
|
|
50
|
+
* route.has("body") // true if operation has @BodyParams
|
|
51
|
+
* route.has("path") // true if operation has @PathParams
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @typeParam Entity - The type of JsonMethodStore (default: JsonMethodStore)
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
4
58
|
export declare class JsonOperationRoute<Entity extends JsonMethodStore = JsonMethodStore> {
|
|
5
59
|
readonly token: Type<any>;
|
|
6
60
|
readonly endpoint: Entity;
|
|
@@ -2,6 +2,41 @@ import { OpenSpecHash, OpenSpecRef, OS3Example, OS3Parameter } from "@tsed/opens
|
|
|
2
2
|
import { JsonSchemaOptions } from "../interfaces/JsonSchemaOptions.js";
|
|
3
3
|
import { JsonMap } from "./JsonMap.js";
|
|
4
4
|
import { JsonSchema } from "./JsonSchema.js";
|
|
5
|
+
/**
|
|
6
|
+
* Represents an HTTP operation parameter for OpenAPI specifications.
|
|
7
|
+
*
|
|
8
|
+
* JsonParameter defines a single parameter for an HTTP operation, supporting
|
|
9
|
+
* various parameter locations (path, query, header, body, files) and providing
|
|
10
|
+
* a fluent API for building parameter metadata compatible with OpenAPI 3.
|
|
11
|
+
*
|
|
12
|
+
* ### Parameter Types
|
|
13
|
+
*
|
|
14
|
+
* - **path**: Parameter in the URL path (e.g., `/users/{id}`)
|
|
15
|
+
* - **query**: Query string parameter (e.g., `?page=1`)
|
|
16
|
+
* - **header**: HTTP header parameter
|
|
17
|
+
* - **body**: Request body parameter
|
|
18
|
+
* - **files**: File upload parameter
|
|
19
|
+
*
|
|
20
|
+
* ### Usage
|
|
21
|
+
*
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const param = new JsonParameter()
|
|
24
|
+
* .name("userId")
|
|
25
|
+
* .in("path")
|
|
26
|
+
* .required(true)
|
|
27
|
+
* .description("The user identifier")
|
|
28
|
+
* .schema(JsonSchema.from(String));
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* ### Key Features
|
|
32
|
+
*
|
|
33
|
+
* - **Schema Integration**: Associated JSON schema for validation
|
|
34
|
+
* - **Examples**: Support for parameter examples
|
|
35
|
+
* - **Expression**: Custom parameter expressions for complex bindings
|
|
36
|
+
* - **Validation**: Required/optional flags and schema constraints
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
5
40
|
export declare class JsonParameter extends JsonMap<OS3Parameter<JsonSchema>> {
|
|
6
41
|
$kind: string;
|
|
7
42
|
expression: string;
|
|
@@ -2,14 +2,111 @@ import { Type } from "@tsed/core";
|
|
|
2
2
|
import { JsonEntityStore, JsonEntityStoreOptions } from "./JsonEntityStore.js";
|
|
3
3
|
import type { JsonMethodStore } from "./JsonMethodStore.js";
|
|
4
4
|
import { JsonParameter } from "./JsonParameter.js";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for creating a JsonParameterStore.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
5
10
|
export interface JsonParameterStoreOptions extends JsonEntityStoreOptions {
|
|
6
11
|
dataPath?: string;
|
|
7
12
|
paramType?: string;
|
|
8
13
|
expression?: string;
|
|
9
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Interface for pipe classes that transform parameter values.
|
|
17
|
+
*
|
|
18
|
+
* Pipes are called by the framework to transform or validate parameter values
|
|
19
|
+
* before they reach the method handler.
|
|
20
|
+
*
|
|
21
|
+
* ### Usage
|
|
22
|
+
*
|
|
23
|
+
* ```typescript
|
|
24
|
+
* class ParseIntPipe implements PipeMethods<string, number> {
|
|
25
|
+
* transform(value: string, metadata: JsonParameterStore): number {
|
|
26
|
+
* return parseInt(value, 10);
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @typeParam T - The input type
|
|
32
|
+
* @typeParam R - The output type after transformation
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
10
36
|
export interface PipeMethods<T = any, R = any> {
|
|
11
37
|
transform(value: T, metadata: JsonParameterStore): R;
|
|
12
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Store for method parameter metadata and schema information.
|
|
41
|
+
*
|
|
42
|
+
* JsonParameterStore manages metadata for method parameters decorated with decorators
|
|
43
|
+
* like `@BodyParams()`, `@PathParams()`, `@QueryParams()`, etc. It handles parameter
|
|
44
|
+
* validation, transformation pipes, and OpenAPI parameter generation.
|
|
45
|
+
*
|
|
46
|
+
* ### Responsibilities
|
|
47
|
+
*
|
|
48
|
+
* - **Parameter Definition**: Maintains JsonParameter for OpenAPI spec generation
|
|
49
|
+
* - **Type Resolution**: Resolves parameter types from TypeScript metadata
|
|
50
|
+
* - **Validation**: Manages required/optional state and validation rules
|
|
51
|
+
* - **Transformation**: Coordinates pipe execution for value transformation
|
|
52
|
+
* - **Location Tracking**: Stores where the parameter comes from (path, query, body, etc.)
|
|
53
|
+
*
|
|
54
|
+
* ### Usage
|
|
55
|
+
*
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // Get parameter store
|
|
58
|
+
* const paramStore = JsonParameterStore.get(MyController, "myMethod", 0);
|
|
59
|
+
*
|
|
60
|
+
* // Access parameter definition
|
|
61
|
+
* const parameter = paramStore.parameter;
|
|
62
|
+
*
|
|
63
|
+
* // Check if required
|
|
64
|
+
* const isRequired = paramStore.required;
|
|
65
|
+
*
|
|
66
|
+
* // Get all parameters for a method
|
|
67
|
+
* const params = JsonParameterStore.getParams(MyController, "myMethod");
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* ### Parameter Types
|
|
71
|
+
*
|
|
72
|
+
* Parameters can come from different locations:
|
|
73
|
+
* - **path**: URL path parameters (`/users/:id`)
|
|
74
|
+
* - **query**: Query string parameters (`?page=1`)
|
|
75
|
+
* - **body**: Request body
|
|
76
|
+
* - **header**: HTTP headers
|
|
77
|
+
* - **cookies**: Cookie values
|
|
78
|
+
* - **files**: File uploads
|
|
79
|
+
*
|
|
80
|
+
* ### Validation
|
|
81
|
+
*
|
|
82
|
+
* The store provides validation helpers:
|
|
83
|
+
* - `required`: Marks parameter as required
|
|
84
|
+
* - `allowedRequiredValues`: Values that bypass required check
|
|
85
|
+
* - `isRequired(value)`: Checks if a value satisfies required constraint
|
|
86
|
+
*
|
|
87
|
+
* ### Transformation Pipes
|
|
88
|
+
*
|
|
89
|
+
* Parameters can have transformation pipes that process values:
|
|
90
|
+
* ```typescript
|
|
91
|
+
* @Controller("/")
|
|
92
|
+
* class MyController {
|
|
93
|
+
* @Get("/:id")
|
|
94
|
+
* get(@PathParams("id") @UsePipe(ParseIntPipe) id: number) {
|
|
95
|
+
* // id is automatically transformed to number
|
|
96
|
+
* }
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* ### Expression Binding
|
|
101
|
+
*
|
|
102
|
+
* Parameters can use expressions to extract nested values:
|
|
103
|
+
* ```typescript
|
|
104
|
+
* @BodyParams("user.address.city") city: string
|
|
105
|
+
* // Extracts: request.body.user.address.city
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
13
110
|
export declare class JsonParameterStore extends JsonEntityStore {
|
|
14
111
|
paramType: string;
|
|
15
112
|
expression: string;
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP operation parameter location types.
|
|
3
|
+
*
|
|
4
|
+
* This enum defines where parameters can be located in an HTTP request.
|
|
5
|
+
* These types are used for both JSON Schema and OpenAPI parameter definitions.
|
|
6
|
+
*
|
|
7
|
+
* ### Parameter Locations
|
|
8
|
+
*
|
|
9
|
+
* - **BODY**: Request body parameter (payload)
|
|
10
|
+
* - **PATH**: URL path parameter (e.g., `/users/{id}`)
|
|
11
|
+
* - **QUERY**: URL query string parameter (e.g., `?page=1`)
|
|
12
|
+
* - **HEADER**: HTTP header parameter (e.g., `Authorization`)
|
|
13
|
+
* - **COOKIES**: Cookie parameter
|
|
14
|
+
* - **FILES**: File upload parameter (multipart/form-data)
|
|
15
|
+
*
|
|
16
|
+
* ### Usage
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import {JsonParameterTypes} from "@tsed/schema";
|
|
20
|
+
*
|
|
21
|
+
* parameter.in(JsonParameterTypes.QUERY);
|
|
22
|
+
* parameter.in(JsonParameterTypes.PATH);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
1
27
|
export declare enum JsonParameterTypes {
|
|
2
28
|
BODY = "body",
|
|
3
29
|
PATH = "path",
|
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
2
|
import type { JsonClassStore } from "./JsonClassStore.js";
|
|
3
3
|
import { JsonEntityStore } from "./JsonEntityStore.js";
|
|
4
|
+
/**
|
|
5
|
+
* Store for property metadata and schema information.
|
|
6
|
+
*
|
|
7
|
+
* JsonPropertyStore manages metadata for class properties decorated with schema decorators
|
|
8
|
+
* like `@Property()`, `@Required()`, `@MinLength()`, etc. It handles schema generation,
|
|
9
|
+
* type resolution, and integration with the parent class schema.
|
|
10
|
+
*
|
|
11
|
+
* ### Responsibilities
|
|
12
|
+
*
|
|
13
|
+
* - **Schema Generation**: Creates and maintains the JsonSchema for the property
|
|
14
|
+
* - **Type Resolution**: Resolves property types including primitives, classes, and collections
|
|
15
|
+
* - **Parent Integration**: Registers the property schema with the parent class schema
|
|
16
|
+
* - **Collection Handling**: Special handling for arrays, Sets, Maps, and other collections
|
|
17
|
+
*
|
|
18
|
+
* ### Usage
|
|
19
|
+
*
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Get property store
|
|
22
|
+
* const propertyStore = JsonPropertyStore.get(MyClass, "propertyName");
|
|
23
|
+
*
|
|
24
|
+
* // Access property schema
|
|
25
|
+
* const schema = propertyStore.schema;
|
|
26
|
+
*
|
|
27
|
+
* // Check property type
|
|
28
|
+
* const type = propertyStore.type;
|
|
29
|
+
* const isCollection = propertyStore.isCollection;
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* ### Schema Integration
|
|
33
|
+
*
|
|
34
|
+
* When a property is decorated, this store:
|
|
35
|
+
* 1. Resolves the property's TypeScript type
|
|
36
|
+
* 2. Creates an appropriate JsonSchema
|
|
37
|
+
* 3. Registers it in the parent class's `properties` object
|
|
38
|
+
* 4. Handles collection item schemas for arrays/collections
|
|
39
|
+
*
|
|
40
|
+
* ### Type Handling
|
|
41
|
+
*
|
|
42
|
+
* - **Primitives**: Creates schema with appropriate type (string, number, boolean, etc.)
|
|
43
|
+
* - **Classes**: Creates object schema with reference to the class schema
|
|
44
|
+
* - **Collections**: Creates array schema with item type schema
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
4
48
|
export declare class JsonPropertyStore extends JsonEntityStore {
|
|
5
49
|
readonly parent: JsonClassStore;
|
|
6
50
|
static get(target: Type<any>, propertyKey: string | symbol): JsonPropertyStore;
|
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
import { OpenSpecHash, OS3MediaType, OS3RequestBody } from "@tsed/openspec";
|
|
2
2
|
import { JsonMap } from "./JsonMap.js";
|
|
3
3
|
import { JsonSchema } from "./JsonSchema.js";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for HTTP request body definitions compatible with OpenAPI 3.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
4
9
|
export type JsonRequestBodyOptions = OS3RequestBody<JsonSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* Represents an HTTP request body definition for OpenAPI specifications.
|
|
12
|
+
*
|
|
13
|
+
* JsonRequestBody defines the structure and content types accepted by an HTTP
|
|
14
|
+
* operation's request body. It provides a fluent API for specifying request
|
|
15
|
+
* body schemas, media types, and examples.
|
|
16
|
+
*
|
|
17
|
+
* ### Usage
|
|
18
|
+
*
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const requestBody = new JsonRequestBody()
|
|
21
|
+
* .description("User creation payload")
|
|
22
|
+
* .addContent("application/json", userSchema, {
|
|
23
|
+
* example1: {name: "John", email: "john@example.com"}
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ### Key Features
|
|
28
|
+
*
|
|
29
|
+
* - **Content Types**: Support for multiple media types (JSON, XML, form data, etc.)
|
|
30
|
+
* - **Schema Integration**: JSON schemas for request validation
|
|
31
|
+
* - **Examples**: Request body examples for documentation
|
|
32
|
+
* - **Required Flag**: Mark request body as required or optional
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
5
36
|
export declare class JsonRequestBody extends JsonMap<JsonRequestBodyOptions> {
|
|
6
37
|
$kind: string;
|
|
7
38
|
constructor(obj?: Partial<JsonRequestBodyOptions>);
|
|
@@ -3,7 +3,41 @@ import { JsonHeader } from "../interfaces/JsonOpenSpec.js";
|
|
|
3
3
|
import { JsonMap } from "./JsonMap.js";
|
|
4
4
|
import { JsonMedia } from "./JsonMedia.js";
|
|
5
5
|
import { JsonSchema } from "./JsonSchema.js";
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for HTTP response definitions compatible with OpenAPI 3.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
6
11
|
export type JsonResponseOptions = OS3Response<JsonSchema, string | JsonHeader>;
|
|
12
|
+
/**
|
|
13
|
+
* Represents an HTTP response definition for OpenAPI specifications.
|
|
14
|
+
*
|
|
15
|
+
* JsonResponse defines the structure of an HTTP response including status code,
|
|
16
|
+
* description, headers, and content types. It provides a fluent API for building
|
|
17
|
+
* response metadata compatible with OpenAPI 3 specifications.
|
|
18
|
+
*
|
|
19
|
+
* ### Usage
|
|
20
|
+
*
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const response = new JsonResponse()
|
|
23
|
+
* .description("User created successfully")
|
|
24
|
+
* .headers({"X-Rate-Limit": "100"})
|
|
25
|
+
* .content({
|
|
26
|
+
* "application/json": {
|
|
27
|
+
* schema: userSchema
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* ### Key Features
|
|
33
|
+
*
|
|
34
|
+
* - **Status Codes**: Associated HTTP status code
|
|
35
|
+
* - **Headers**: Response header definitions
|
|
36
|
+
* - **Content Types**: Multiple media type support
|
|
37
|
+
* - **Schema Integration**: JSON schemas for response bodies
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
7
41
|
export declare class JsonResponse extends JsonMap<JsonResponseOptions> {
|
|
8
42
|
$kind: string;
|
|
9
43
|
status: number;
|