@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 class JsonMethodPath extends JsonMap {
|
|
8
17
|
constructor(method, path) {
|
|
9
18
|
super();
|
|
@@ -19,6 +28,40 @@ export class JsonMethodPath extends JsonMap {
|
|
|
19
28
|
return this;
|
|
20
29
|
}
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Represents an HTTP operation (endpoint) with complete OpenAPI metadata.
|
|
33
|
+
*
|
|
34
|
+
* JsonOperation is the core class for defining HTTP endpoints in Ts.ED, storing all
|
|
35
|
+
* operation-level information required for OpenAPI specification generation including:
|
|
36
|
+
*
|
|
37
|
+
* - Request parameters (path, query, header, body)
|
|
38
|
+
* - Response definitions with status codes
|
|
39
|
+
* - Security requirements
|
|
40
|
+
* - Tags and categorization
|
|
41
|
+
* - Media type handling (consumes/produces)
|
|
42
|
+
* - Operation metadata (summary, description, operationId)
|
|
43
|
+
*
|
|
44
|
+
* ### Usage
|
|
45
|
+
*
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const operation = new JsonOperation()
|
|
48
|
+
* .summary("Create a user")
|
|
49
|
+
* .description("Creates a new user in the system")
|
|
50
|
+
* .addTags([{name: "Users"}])
|
|
51
|
+
* .addParameter(0, parameterMetadata)
|
|
52
|
+
* .addResponse(201, responseMetadata);
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* ### Key Features
|
|
56
|
+
*
|
|
57
|
+
* - **Parameters**: Manage operation parameters by index or name
|
|
58
|
+
* - **Responses**: Define responses for different HTTP status codes
|
|
59
|
+
* - **Security**: Configure authentication and authorization
|
|
60
|
+
* - **Media Types**: Specify accepted and produced content types
|
|
61
|
+
* - **Routing**: Multiple path/method combinations per operation
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
22
65
|
export class JsonOperation extends JsonMap {
|
|
23
66
|
#status;
|
|
24
67
|
#redirection;
|
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map container for storing HTTP operation paths indexed by method and path.
|
|
3
|
+
*
|
|
4
|
+
* JsonOperationPathsMap maintains a collection of operation paths (HTTP method + URL path
|
|
5
|
+
* combinations) for a controller. It provides efficient lookup and prevents duplicate
|
|
6
|
+
* operations from being registered.
|
|
7
|
+
*
|
|
8
|
+
* ### Key Features
|
|
9
|
+
*
|
|
10
|
+
* - **Unique Keys**: Stores operations using `method-path` composite keys
|
|
11
|
+
* - **Method Safety**: Ensures operations are uniquely identified
|
|
12
|
+
* - **Efficient Lookup**: Fast retrieval of operations by method and path
|
|
13
|
+
* - **Type Safety**: Extends Map with JsonMethodPath values
|
|
14
|
+
*
|
|
15
|
+
* ### Usage
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const pathsMap = new JsonOperationPathsMap();
|
|
19
|
+
*
|
|
20
|
+
* // Add operation path
|
|
21
|
+
* const methodPath = { method: "GET", path: "/users" };
|
|
22
|
+
* pathsMap.setOperationPath(methodPath);
|
|
23
|
+
*
|
|
24
|
+
* // Retrieve by composite key
|
|
25
|
+
* const operation = pathsMap.get("GET-/users");
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ### Key Generation
|
|
29
|
+
*
|
|
30
|
+
* The map uses a composite key format: `{method}-{path}`
|
|
31
|
+
* - Example: `"GET-/users/:id"` for a GET operation on `/users/:id`
|
|
32
|
+
* - Example: `"POST-/users"` for a POST operation on `/users`
|
|
33
|
+
*
|
|
34
|
+
* This ensures that different HTTP methods on the same path are treated as
|
|
35
|
+
* distinct operations.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
1
39
|
export class JsonOperationPathsMap extends Map {
|
|
2
40
|
constructor() {
|
|
3
41
|
super(...arguments);
|
|
@@ -1,4 +1,58 @@
|
|
|
1
1
|
import { concatPath } from "../utils/concatPath.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a fully resolved HTTP route combining controller and method metadata.
|
|
4
|
+
*
|
|
5
|
+
* JsonOperationRoute provides a unified view of an HTTP endpoint by combining:
|
|
6
|
+
* - Controller class information (token, basePath)
|
|
7
|
+
* - Method metadata (endpoint store)
|
|
8
|
+
* - Operation details (HTTP method, path, parameters)
|
|
9
|
+
* - Full URL computation
|
|
10
|
+
*
|
|
11
|
+
* ### Responsibilities
|
|
12
|
+
*
|
|
13
|
+
* - **URL Resolution**: Combines base path and operation path into full URL
|
|
14
|
+
* - **Metadata Access**: Provides convenient access to operation, parameters, and store
|
|
15
|
+
* - **Route Identification**: Computes route names and operation IDs
|
|
16
|
+
* - **Parameter Type Tracking**: Maintains map of parameter types (query, body, etc.)
|
|
17
|
+
*
|
|
18
|
+
* ### Usage
|
|
19
|
+
*
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Routes are typically created during framework initialization
|
|
22
|
+
* const route = new JsonOperationRoute({
|
|
23
|
+
* token: MyController,
|
|
24
|
+
* endpoint: methodStore,
|
|
25
|
+
* operationPath: { method: "GET", path: "/:id" },
|
|
26
|
+
* basePath: "/users"
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Access route information
|
|
30
|
+
* console.log(route.fullPath); // "/users/:id"
|
|
31
|
+
* console.log(route.method); // "GET"
|
|
32
|
+
* console.log(route.name); // "MyController.getUser()"
|
|
33
|
+
* console.log(route.operationId); // "getUser"
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* ### URL Construction
|
|
37
|
+
*
|
|
38
|
+
* The route combines controller base path with operation path:
|
|
39
|
+
* - Base path: `/users` (from `@Controller("/users")`)
|
|
40
|
+
* - Operation path: `/:id` (from `@Get("/:id")`)
|
|
41
|
+
* - Full path: `/users/:id`
|
|
42
|
+
*
|
|
43
|
+
* ### Parameter Type Detection
|
|
44
|
+
*
|
|
45
|
+
* The route maintains a map of parameter types present in the operation:
|
|
46
|
+
* ```typescript
|
|
47
|
+
* route.has("query") // true if operation has @QueryParams
|
|
48
|
+
* route.has("body") // true if operation has @BodyParams
|
|
49
|
+
* route.has("path") // true if operation has @PathParams
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @typeParam Entity - The type of JsonMethodStore (default: JsonMethodStore)
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
2
56
|
export class JsonOperationRoute {
|
|
3
57
|
constructor(options) {
|
|
4
58
|
Object.assign(this, options);
|
|
@@ -2,6 +2,41 @@ import { execMapper } from "../registries/JsonSchemaMapperContainer.js";
|
|
|
2
2
|
import { JsonMap } from "./JsonMap.js";
|
|
3
3
|
import { formatParameterType } from "./JsonParameterTypes.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 class JsonParameter extends JsonMap {
|
|
6
41
|
constructor(obj = {}) {
|
|
7
42
|
super(obj);
|
|
@@ -3,6 +3,77 @@ import { ancestorsOf, DecoratorTypes, isClass, isMethodDescriptor, Metadata, pro
|
|
|
3
3
|
import { JsonEntityComponent } from "../decorators/config/jsonEntityComponent.js";
|
|
4
4
|
import { JsonEntityStore } from "./JsonEntityStore.js";
|
|
5
5
|
import { JsonParameter } from "./JsonParameter.js";
|
|
6
|
+
/**
|
|
7
|
+
* Store for method parameter metadata and schema information.
|
|
8
|
+
*
|
|
9
|
+
* JsonParameterStore manages metadata for method parameters decorated with decorators
|
|
10
|
+
* like `@BodyParams()`, `@PathParams()`, `@QueryParams()`, etc. It handles parameter
|
|
11
|
+
* validation, transformation pipes, and OpenAPI parameter generation.
|
|
12
|
+
*
|
|
13
|
+
* ### Responsibilities
|
|
14
|
+
*
|
|
15
|
+
* - **Parameter Definition**: Maintains JsonParameter for OpenAPI spec generation
|
|
16
|
+
* - **Type Resolution**: Resolves parameter types from TypeScript metadata
|
|
17
|
+
* - **Validation**: Manages required/optional state and validation rules
|
|
18
|
+
* - **Transformation**: Coordinates pipe execution for value transformation
|
|
19
|
+
* - **Location Tracking**: Stores where the parameter comes from (path, query, body, etc.)
|
|
20
|
+
*
|
|
21
|
+
* ### Usage
|
|
22
|
+
*
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Get parameter store
|
|
25
|
+
* const paramStore = JsonParameterStore.get(MyController, "myMethod", 0);
|
|
26
|
+
*
|
|
27
|
+
* // Access parameter definition
|
|
28
|
+
* const parameter = paramStore.parameter;
|
|
29
|
+
*
|
|
30
|
+
* // Check if required
|
|
31
|
+
* const isRequired = paramStore.required;
|
|
32
|
+
*
|
|
33
|
+
* // Get all parameters for a method
|
|
34
|
+
* const params = JsonParameterStore.getParams(MyController, "myMethod");
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* ### Parameter Types
|
|
38
|
+
*
|
|
39
|
+
* Parameters can come from different locations:
|
|
40
|
+
* - **path**: URL path parameters (`/users/:id`)
|
|
41
|
+
* - **query**: Query string parameters (`?page=1`)
|
|
42
|
+
* - **body**: Request body
|
|
43
|
+
* - **header**: HTTP headers
|
|
44
|
+
* - **cookies**: Cookie values
|
|
45
|
+
* - **files**: File uploads
|
|
46
|
+
*
|
|
47
|
+
* ### Validation
|
|
48
|
+
*
|
|
49
|
+
* The store provides validation helpers:
|
|
50
|
+
* - `required`: Marks parameter as required
|
|
51
|
+
* - `allowedRequiredValues`: Values that bypass required check
|
|
52
|
+
* - `isRequired(value)`: Checks if a value satisfies required constraint
|
|
53
|
+
*
|
|
54
|
+
* ### Transformation Pipes
|
|
55
|
+
*
|
|
56
|
+
* Parameters can have transformation pipes that process values:
|
|
57
|
+
* ```typescript
|
|
58
|
+
* @Controller("/")
|
|
59
|
+
* class MyController {
|
|
60
|
+
* @Get("/:id")
|
|
61
|
+
* get(@PathParams("id") @UsePipe(ParseIntPipe) id: number) {
|
|
62
|
+
* // id is automatically transformed to number
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* ### Expression Binding
|
|
68
|
+
*
|
|
69
|
+
* Parameters can use expressions to extract nested values:
|
|
70
|
+
* ```typescript
|
|
71
|
+
* @BodyParams("user.address.city") city: string
|
|
72
|
+
* // Extracts: request.body.user.address.city
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
6
77
|
let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
|
|
7
78
|
constructor(options) {
|
|
8
79
|
super(options);
|
|
@@ -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 var JsonParameterTypes;
|
|
2
28
|
(function (JsonParameterTypes) {
|
|
3
29
|
JsonParameterTypes["BODY"] = "body";
|
|
@@ -3,6 +3,50 @@ import { DecoratorTypes, isClass, Metadata, prototypeOf } from "@tsed/core";
|
|
|
3
3
|
import { JsonEntityComponent } from "../decorators/config/jsonEntityComponent.js";
|
|
4
4
|
import { JsonEntityStore } from "./JsonEntityStore.js";
|
|
5
5
|
import { JsonSchema } from "./JsonSchema.js";
|
|
6
|
+
/**
|
|
7
|
+
* Store for property metadata and schema information.
|
|
8
|
+
*
|
|
9
|
+
* JsonPropertyStore manages metadata for class properties decorated with schema decorators
|
|
10
|
+
* like `@Property()`, `@Required()`, `@MinLength()`, etc. It handles schema generation,
|
|
11
|
+
* type resolution, and integration with the parent class schema.
|
|
12
|
+
*
|
|
13
|
+
* ### Responsibilities
|
|
14
|
+
*
|
|
15
|
+
* - **Schema Generation**: Creates and maintains the JsonSchema for the property
|
|
16
|
+
* - **Type Resolution**: Resolves property types including primitives, classes, and collections
|
|
17
|
+
* - **Parent Integration**: Registers the property schema with the parent class schema
|
|
18
|
+
* - **Collection Handling**: Special handling for arrays, Sets, Maps, and other collections
|
|
19
|
+
*
|
|
20
|
+
* ### Usage
|
|
21
|
+
*
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Get property store
|
|
24
|
+
* const propertyStore = JsonPropertyStore.get(MyClass, "propertyName");
|
|
25
|
+
*
|
|
26
|
+
* // Access property schema
|
|
27
|
+
* const schema = propertyStore.schema;
|
|
28
|
+
*
|
|
29
|
+
* // Check property type
|
|
30
|
+
* const type = propertyStore.type;
|
|
31
|
+
* const isCollection = propertyStore.isCollection;
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* ### Schema Integration
|
|
35
|
+
*
|
|
36
|
+
* When a property is decorated, this store:
|
|
37
|
+
* 1. Resolves the property's TypeScript type
|
|
38
|
+
* 2. Creates an appropriate JsonSchema
|
|
39
|
+
* 3. Registers it in the parent class's `properties` object
|
|
40
|
+
* 4. Handles collection item schemas for arrays/collections
|
|
41
|
+
*
|
|
42
|
+
* ### Type Handling
|
|
43
|
+
*
|
|
44
|
+
* - **Primitives**: Creates schema with appropriate type (string, number, boolean, etc.)
|
|
45
|
+
* - **Classes**: Creates object schema with reference to the class schema
|
|
46
|
+
* - **Collections**: Creates array schema with item type schema
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
6
50
|
let JsonPropertyStore = class JsonPropertyStore extends JsonEntityStore {
|
|
7
51
|
constructor() {
|
|
8
52
|
super(...arguments);
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import { toJsonMapCollection } from "../utils/toJsonMapCollection.js";
|
|
2
2
|
import { JsonMap } from "./JsonMap.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents an HTTP request body definition for OpenAPI specifications.
|
|
5
|
+
*
|
|
6
|
+
* JsonRequestBody defines the structure and content types accepted by an HTTP
|
|
7
|
+
* operation's request body. It provides a fluent API for specifying request
|
|
8
|
+
* body schemas, media types, and examples.
|
|
9
|
+
*
|
|
10
|
+
* ### Usage
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const requestBody = new JsonRequestBody()
|
|
14
|
+
* .description("User creation payload")
|
|
15
|
+
* .addContent("application/json", userSchema, {
|
|
16
|
+
* example1: {name: "John", email: "john@example.com"}
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* ### Key Features
|
|
21
|
+
*
|
|
22
|
+
* - **Content Types**: Support for multiple media types (JSON, XML, form data, etc.)
|
|
23
|
+
* - **Schema Integration**: JSON schemas for request validation
|
|
24
|
+
* - **Examples**: Request body examples for documentation
|
|
25
|
+
* - **Required Flag**: Mark request body as required or optional
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
3
29
|
export class JsonRequestBody extends JsonMap {
|
|
4
30
|
constructor(obj = {}) {
|
|
5
31
|
super(obj);
|
|
@@ -2,6 +2,35 @@ import { mapHeaders } from "../utils/mapHeaders.js";
|
|
|
2
2
|
import { toJsonMapCollection } from "../utils/toJsonMapCollection.js";
|
|
3
3
|
import { JsonMap } from "./JsonMap.js";
|
|
4
4
|
import { JsonMedia } from "./JsonMedia.js";
|
|
5
|
+
/**
|
|
6
|
+
* Represents an HTTP response definition for OpenAPI specifications.
|
|
7
|
+
*
|
|
8
|
+
* JsonResponse defines the structure of an HTTP response including status code,
|
|
9
|
+
* description, headers, and content types. It provides a fluent API for building
|
|
10
|
+
* response metadata compatible with OpenAPI 3 specifications.
|
|
11
|
+
*
|
|
12
|
+
* ### Usage
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const response = new JsonResponse()
|
|
16
|
+
* .description("User created successfully")
|
|
17
|
+
* .headers({"X-Rate-Limit": "100"})
|
|
18
|
+
* .content({
|
|
19
|
+
* "application/json": {
|
|
20
|
+
* schema: userSchema
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* ### Key Features
|
|
26
|
+
*
|
|
27
|
+
* - **Status Codes**: Associated HTTP status code
|
|
28
|
+
* - **Headers**: Response header definitions
|
|
29
|
+
* - **Content Types**: Multiple media type support
|
|
30
|
+
* - **Schema Integration**: JSON schemas for response bodies
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
5
34
|
export class JsonResponse extends JsonMap {
|
|
6
35
|
constructor(obj = {}) {
|
|
7
36
|
super(obj);
|