@skmtc/core 0.0.790 → 0.0.791
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/esm/oas/number/Number.d.ts +179 -1
- package/esm/oas/number/Number.d.ts.map +1 -1
- package/esm/oas/number/Number.js +161 -1
- package/esm/oas/response/Response.d.ts +190 -0
- package/esm/oas/response/Response.d.ts.map +1 -1
- package/esm/oas/response/Response.js +183 -0
- package/esm/oas/void/Void.d.ts +130 -3
- package/esm/oas/void/Void.d.ts.map +1 -1
- package/esm/oas/void/Void.js +125 -3
- package/package.json +1 -1
- package/script/oas/number/Number.d.ts +179 -1
- package/script/oas/number/Number.d.ts.map +1 -1
- package/script/oas/number/Number.js +161 -1
- package/script/oas/response/Response.d.ts +190 -0
- package/script/oas/response/Response.d.ts.map +1 -1
- package/script/oas/response/Response.js +183 -0
- package/script/oas/void/Void.d.ts +130 -3
- package/script/oas/void/Void.d.ts.map +1 -1
- package/script/oas/void/Void.js +125 -3
|
@@ -3,7 +3,167 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OasNumber = void 0;
|
|
4
4
|
require("../../_dnt.polyfills.js");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Represents a number schema in the OpenAPI Specification.
|
|
7
|
+
*
|
|
8
|
+
* The `OasNumber` class handles floating-point numeric data types in OpenAPI schemas,
|
|
9
|
+
* supporting comprehensive validation constraints including ranges, precision formats,
|
|
10
|
+
* and mathematical constraints. This class provides type-safe number handling with
|
|
11
|
+
* optional null value support and extensive validation capabilities.
|
|
12
|
+
*
|
|
13
|
+
* ## Key Features
|
|
14
|
+
*
|
|
15
|
+
* - **Range Validation**: Minimum and maximum constraints with exclusive/inclusive options
|
|
16
|
+
* - **Precision Control**: Float and double format support for different precision needs
|
|
17
|
+
* - **Mathematical Constraints**: Multiple-of validation for specific numeric patterns
|
|
18
|
+
* - **Type Safety**: Generic nullable type support with proper TypeScript inference
|
|
19
|
+
* - **Enum Support**: Constrain numbers to specific allowed values
|
|
20
|
+
* - **Null Handling**: Optional null value support for nullable number types
|
|
21
|
+
*
|
|
22
|
+
* @template Nullable - Whether the number value itself can be null
|
|
23
|
+
*
|
|
24
|
+
* @example Basic number schema with range
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { OasNumber } from '@skmtc/core';
|
|
27
|
+
*
|
|
28
|
+
* const ageSchema = new OasNumber({
|
|
29
|
+
* title: 'Age',
|
|
30
|
+
* description: 'Person age in years',
|
|
31
|
+
* minimum: 0,
|
|
32
|
+
* maximum: 150,
|
|
33
|
+
* example: 25,
|
|
34
|
+
* default: 18
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // This represents: number (0 <= value <= 150)
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Price with precision and constraints
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const priceSchema = new OasNumber({
|
|
43
|
+
* title: 'Product Price',
|
|
44
|
+
* description: 'Price in USD with cent precision',
|
|
45
|
+
* format: 'double',
|
|
46
|
+
* minimum: 0,
|
|
47
|
+
* exclusiveMinimum: true, // Must be > 0, not >= 0
|
|
48
|
+
* multipleOf: 0.01, // Must be in cents (e.g., 19.99, 10.50)
|
|
49
|
+
* example: 29.99
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // This represents: number > 0, in multiples of 0.01
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example Percentage with strict bounds
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const percentageSchema = new OasNumber({
|
|
58
|
+
* title: 'Completion Percentage',
|
|
59
|
+
* description: 'Task completion as a percentage',
|
|
60
|
+
* minimum: 0,
|
|
61
|
+
* maximum: 100,
|
|
62
|
+
* multipleOf: 0.1, // One decimal place precision
|
|
63
|
+
* example: 75.5,
|
|
64
|
+
* default: 0
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* // This represents: 0 <= value <= 100, in increments of 0.1
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example Nullable rating system
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const ratingSchema = new OasNumber<true>({
|
|
73
|
+
* title: 'User Rating',
|
|
74
|
+
* description: 'Product rating from 1-5 stars, null if not rated',
|
|
75
|
+
* nullable: true,
|
|
76
|
+
* minimum: 1,
|
|
77
|
+
* maximum: 5,
|
|
78
|
+
* multipleOf: 0.5, // Allow half-star ratings
|
|
79
|
+
* enums: [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, null],
|
|
80
|
+
* example: 4.5,
|
|
81
|
+
* default: null
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* // This represents: (1 | 1.5 | 2 | 2.5 | 3 | 3.5 | 4 | 4.5 | 5) | null
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @example Scientific measurement with high precision
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const temperatureSchema = new OasNumber({
|
|
90
|
+
* title: 'Temperature',
|
|
91
|
+
* description: 'Temperature in Celsius with high precision',
|
|
92
|
+
* format: 'double',
|
|
93
|
+
* minimum: -273.15, // Absolute zero
|
|
94
|
+
* maximum: 1000,
|
|
95
|
+
* multipleOf: 0.001, // Millikelvin precision
|
|
96
|
+
* example: 23.456
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // For scientific applications requiring high precision
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example Currency with regional constraints
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const currencySchema = new OasNumber({
|
|
105
|
+
* title: 'Amount',
|
|
106
|
+
* description: 'Transaction amount in major currency units',
|
|
107
|
+
* format: 'double',
|
|
108
|
+
* minimum: 0,
|
|
109
|
+
* maximum: 999999.99,
|
|
110
|
+
* multipleOf: 0.01,
|
|
111
|
+
* example: 1234.56
|
|
112
|
+
* });
|
|
113
|
+
*
|
|
114
|
+
* // Used in financial applications
|
|
115
|
+
* const transaction = new OasObject({
|
|
116
|
+
* properties: {
|
|
117
|
+
* amount: currencySchema,
|
|
118
|
+
* currency: new OasString({ enum: ['USD', 'EUR', 'GBP'] })
|
|
119
|
+
* }
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @example Coordinate system
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const latitudeSchema = new OasNumber({
|
|
126
|
+
* title: 'Latitude',
|
|
127
|
+
* description: 'Geographic latitude coordinate',
|
|
128
|
+
* format: 'double',
|
|
129
|
+
* minimum: -90,
|
|
130
|
+
* maximum: 90,
|
|
131
|
+
* example: 40.7128
|
|
132
|
+
* });
|
|
133
|
+
*
|
|
134
|
+
* const longitudeSchema = new OasNumber({
|
|
135
|
+
* title: 'Longitude',
|
|
136
|
+
* description: 'Geographic longitude coordinate',
|
|
137
|
+
* format: 'double',
|
|
138
|
+
* minimum: -180,
|
|
139
|
+
* maximum: 180,
|
|
140
|
+
* example: -74.0060
|
|
141
|
+
* });
|
|
142
|
+
*
|
|
143
|
+
* // Used for location data
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @example Probability and statistics
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const probabilitySchema = new OasNumber({
|
|
149
|
+
* title: 'Probability',
|
|
150
|
+
* description: 'Statistical probability value',
|
|
151
|
+
* minimum: 0,
|
|
152
|
+
* maximum: 1,
|
|
153
|
+
* exclusiveMaximum: false, // Can be exactly 1
|
|
154
|
+
* example: 0.75,
|
|
155
|
+
* default: 0.5
|
|
156
|
+
* });
|
|
157
|
+
*
|
|
158
|
+
* const confidenceSchema = new OasNumber({
|
|
159
|
+
* title: 'Confidence Level',
|
|
160
|
+
* description: 'Statistical confidence level as percentage',
|
|
161
|
+
* minimum: 0,
|
|
162
|
+
* maximum: 100,
|
|
163
|
+
* enums: [90, 95, 99], // Common confidence levels
|
|
164
|
+
* example: 95
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
7
167
|
*/
|
|
8
168
|
class OasNumber {
|
|
9
169
|
constructor(fields = {}) {
|
|
@@ -5,12 +5,202 @@ import type { OasRef } from '../ref/Ref.js';
|
|
|
5
5
|
import type { OasSchema } from '../schema/Schema.js';
|
|
6
6
|
import type { ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
7
7
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
8
|
+
/**
|
|
9
|
+
* Constructor fields for {@link OasResponse}.
|
|
10
|
+
*/
|
|
8
11
|
export type ResponseFields = {
|
|
12
|
+
/** A description of the response */
|
|
9
13
|
description?: string | undefined;
|
|
14
|
+
/** Response headers that can be sent */
|
|
10
15
|
headers?: Record<string, OasHeader | OasRef<'header'>> | undefined;
|
|
16
|
+
/** Response content for different media types */
|
|
11
17
|
content?: Record<string, OasMediaType> | undefined;
|
|
18
|
+
/** Custom extension fields (x-* properties) */
|
|
12
19
|
extensionFields?: Record<string, unknown>;
|
|
13
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Represents a Response Object in the OpenAPI Specification.
|
|
23
|
+
*
|
|
24
|
+
* The `OasResponse` class encapsulates the definition of a single HTTP response,
|
|
25
|
+
* including its description, headers, and content for different media types.
|
|
26
|
+
* Responses describe the possible outcomes of API operations and can include
|
|
27
|
+
* both successful and error scenarios.
|
|
28
|
+
*
|
|
29
|
+
* This class provides comprehensive support for response definitions with typed
|
|
30
|
+
* content, custom headers, and multiple media type representations.
|
|
31
|
+
*
|
|
32
|
+
* ## Key Features
|
|
33
|
+
*
|
|
34
|
+
* - **Content Types**: Support for multiple media types (JSON, XML, HTML, etc.)
|
|
35
|
+
* - **Header Definitions**: Custom response headers with validation
|
|
36
|
+
* - **Schema Integration**: Typed response bodies through schema definitions
|
|
37
|
+
* - **Reference Support**: Can reference reusable response components
|
|
38
|
+
* - **Documentation**: Rich description support for API documentation
|
|
39
|
+
* - **JSON Schema**: Converts to standard JSON Schema format for validation
|
|
40
|
+
*
|
|
41
|
+
* @example Basic JSON response
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { OasResponse, OasMediaType, OasObject, OasString } from '@skmtc/core';
|
|
44
|
+
*
|
|
45
|
+
* const successResponse = new OasResponse({
|
|
46
|
+
* description: 'User retrieved successfully',
|
|
47
|
+
* content: {
|
|
48
|
+
* 'application/json': new OasMediaType({
|
|
49
|
+
* schema: new OasObject({
|
|
50
|
+
* properties: {
|
|
51
|
+
* id: new OasString(),
|
|
52
|
+
* name: new OasString(),
|
|
53
|
+
* email: new OasString({ format: 'email' })
|
|
54
|
+
* }
|
|
55
|
+
* })
|
|
56
|
+
* })
|
|
57
|
+
* }
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Response with custom headers
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const paginatedResponse = new OasResponse({
|
|
64
|
+
* description: 'Paginated list of items',
|
|
65
|
+
* headers: {
|
|
66
|
+
* 'X-Total-Count': new OasHeader({
|
|
67
|
+
* description: 'Total number of items',
|
|
68
|
+
* schema: new OasInteger({ minimum: 0 })
|
|
69
|
+
* }),
|
|
70
|
+
* 'X-Page-Number': new OasHeader({
|
|
71
|
+
* description: 'Current page number',
|
|
72
|
+
* schema: new OasInteger({ minimum: 1 })
|
|
73
|
+
* }),
|
|
74
|
+
* 'Link': new OasHeader({
|
|
75
|
+
* description: 'Pagination links',
|
|
76
|
+
* schema: new OasString()
|
|
77
|
+
* })
|
|
78
|
+
* },
|
|
79
|
+
* content: {
|
|
80
|
+
* 'application/json': new OasMediaType({
|
|
81
|
+
* schema: new OasArray({
|
|
82
|
+
* items: new OasRef({ $ref: '#/components/schemas/Item' })
|
|
83
|
+
* })
|
|
84
|
+
* })
|
|
85
|
+
* }
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example Multiple content types
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const multiFormatResponse = new OasResponse({
|
|
92
|
+
* description: 'User data in multiple formats',
|
|
93
|
+
* content: {
|
|
94
|
+
* 'application/json': new OasMediaType({
|
|
95
|
+
* schema: new OasRef({ $ref: '#/components/schemas/User' })
|
|
96
|
+
* }),
|
|
97
|
+
* 'application/xml': new OasMediaType({
|
|
98
|
+
* schema: new OasObject({
|
|
99
|
+
* // XML-specific schema definition
|
|
100
|
+
* properties: {
|
|
101
|
+
* user: new OasRef({ $ref: '#/components/schemas/User' })
|
|
102
|
+
* }
|
|
103
|
+
* })
|
|
104
|
+
* }),
|
|
105
|
+
* 'text/csv': new OasMediaType({
|
|
106
|
+
* schema: new OasString({
|
|
107
|
+
* description: 'User data in CSV format'
|
|
108
|
+
* })
|
|
109
|
+
* })
|
|
110
|
+
* }
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example Error responses
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const errorResponse = new OasResponse({
|
|
117
|
+
* description: 'Validation error occurred',
|
|
118
|
+
* content: {
|
|
119
|
+
* 'application/json': new OasMediaType({
|
|
120
|
+
* schema: new OasObject({
|
|
121
|
+
* properties: {
|
|
122
|
+
* error: new OasString({ description: 'Error message' }),
|
|
123
|
+
* code: new OasString({ description: 'Error code' }),
|
|
124
|
+
* details: new OasArray({
|
|
125
|
+
* items: new OasObject({
|
|
126
|
+
* properties: {
|
|
127
|
+
* field: new OasString(),
|
|
128
|
+
* message: new OasString()
|
|
129
|
+
* }
|
|
130
|
+
* })
|
|
131
|
+
* })
|
|
132
|
+
* },
|
|
133
|
+
* required: ['error', 'code']
|
|
134
|
+
* })
|
|
135
|
+
* })
|
|
136
|
+
* }
|
|
137
|
+
* });
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example File download response
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const fileDownloadResponse = new OasResponse({
|
|
143
|
+
* description: 'File download',
|
|
144
|
+
* headers: {
|
|
145
|
+
* 'Content-Disposition': new OasHeader({
|
|
146
|
+
* description: 'Attachment filename',
|
|
147
|
+
* schema: new OasString({ example: 'attachment; filename="report.pdf"' })
|
|
148
|
+
* }),
|
|
149
|
+
* 'Content-Length': new OasHeader({
|
|
150
|
+
* description: 'File size in bytes',
|
|
151
|
+
* schema: new OasInteger({ minimum: 0 })
|
|
152
|
+
* })
|
|
153
|
+
* },
|
|
154
|
+
* content: {
|
|
155
|
+
* 'application/pdf': new OasMediaType({
|
|
156
|
+
* schema: new OasString({
|
|
157
|
+
* format: 'binary',
|
|
158
|
+
* description: 'PDF file content'
|
|
159
|
+
* })
|
|
160
|
+
* }),
|
|
161
|
+
* 'application/octet-stream': new OasMediaType({
|
|
162
|
+
* schema: new OasString({
|
|
163
|
+
* format: 'binary',
|
|
164
|
+
* description: 'Generic binary content'
|
|
165
|
+
* })
|
|
166
|
+
* })
|
|
167
|
+
* }
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @example No content response
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const noContentResponse = new OasResponse({
|
|
174
|
+
* description: 'Operation completed successfully, no content returned'
|
|
175
|
+
* // No content or headers - represents HTTP 204 No Content
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @example Using in operation definitions
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const getUserOperation = new OasOperation({
|
|
182
|
+
* path: '/users/{id}',
|
|
183
|
+
* method: 'get',
|
|
184
|
+
* responses: {
|
|
185
|
+
* '200': successResponse,
|
|
186
|
+
* '404': new OasResponse({
|
|
187
|
+
* description: 'User not found',
|
|
188
|
+
* content: {
|
|
189
|
+
* 'application/json': new OasMediaType({
|
|
190
|
+
* schema: new OasObject({
|
|
191
|
+
* properties: {
|
|
192
|
+
* error: new OasString({ example: 'User not found' }),
|
|
193
|
+
* code: new OasString({ example: 'USER_NOT_FOUND' })
|
|
194
|
+
* }
|
|
195
|
+
* })
|
|
196
|
+
* })
|
|
197
|
+
* }
|
|
198
|
+
* }),
|
|
199
|
+
* '500': new OasRef({ $ref: '#/components/responses/InternalServerError' })
|
|
200
|
+
* }
|
|
201
|
+
* });
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
14
204
|
export declare class OasResponse {
|
|
15
205
|
oasType: 'response';
|
|
16
206
|
description: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Response.d.ts","sourceRoot":"","sources":["../../../src/oas/response/Response.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,SAAS,CAAA;IAClD,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC1C,CAAA;AAED,qBAAa,WAAW;IACtB,OAAO,EAAE,UAAU,CAAa;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;IACjE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,SAAS,CAAA;IACjD,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;gBACxC,MAAM,EAAE,cAAc;IAOlC,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC;IAInC,OAAO,IAAI,WAAW;IAItB,WAAW,IAAI,WAAW;IAI1B,QAAQ,CAAC,SAAS,GAAE,MAA2B,GAAG,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS;IAI1F,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,cAAc;CAqBrE"}
|
|
1
|
+
{"version":3,"file":"Response.d.ts","sourceRoot":"","sources":["../../../src/oas/response/Response.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,oCAAoC;IACpC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;IAClE,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,SAAS,CAAA;IAClD,+CAA+C;IAC/C,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC1C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsLG;AACH,qBAAa,WAAW;IACtB,OAAO,EAAE,UAAU,CAAa;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;IACjE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,SAAS,CAAA;IACjD,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;gBACxC,MAAM,EAAE,cAAc;IAOlC,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC;IAInC,OAAO,IAAI,WAAW;IAItB,WAAW,IAAI,WAAW;IAI1B,QAAQ,CAAC,SAAS,GAAE,MAA2B,GAAG,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS;IAI1F,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,cAAc;CAqBrE"}
|
|
@@ -2,6 +2,189 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OasResponse = void 0;
|
|
4
4
|
require("../../_dnt.polyfills.js");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Response Object in the OpenAPI Specification.
|
|
7
|
+
*
|
|
8
|
+
* The `OasResponse` class encapsulates the definition of a single HTTP response,
|
|
9
|
+
* including its description, headers, and content for different media types.
|
|
10
|
+
* Responses describe the possible outcomes of API operations and can include
|
|
11
|
+
* both successful and error scenarios.
|
|
12
|
+
*
|
|
13
|
+
* This class provides comprehensive support for response definitions with typed
|
|
14
|
+
* content, custom headers, and multiple media type representations.
|
|
15
|
+
*
|
|
16
|
+
* ## Key Features
|
|
17
|
+
*
|
|
18
|
+
* - **Content Types**: Support for multiple media types (JSON, XML, HTML, etc.)
|
|
19
|
+
* - **Header Definitions**: Custom response headers with validation
|
|
20
|
+
* - **Schema Integration**: Typed response bodies through schema definitions
|
|
21
|
+
* - **Reference Support**: Can reference reusable response components
|
|
22
|
+
* - **Documentation**: Rich description support for API documentation
|
|
23
|
+
* - **JSON Schema**: Converts to standard JSON Schema format for validation
|
|
24
|
+
*
|
|
25
|
+
* @example Basic JSON response
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { OasResponse, OasMediaType, OasObject, OasString } from '@skmtc/core';
|
|
28
|
+
*
|
|
29
|
+
* const successResponse = new OasResponse({
|
|
30
|
+
* description: 'User retrieved successfully',
|
|
31
|
+
* content: {
|
|
32
|
+
* 'application/json': new OasMediaType({
|
|
33
|
+
* schema: new OasObject({
|
|
34
|
+
* properties: {
|
|
35
|
+
* id: new OasString(),
|
|
36
|
+
* name: new OasString(),
|
|
37
|
+
* email: new OasString({ format: 'email' })
|
|
38
|
+
* }
|
|
39
|
+
* })
|
|
40
|
+
* })
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example Response with custom headers
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const paginatedResponse = new OasResponse({
|
|
48
|
+
* description: 'Paginated list of items',
|
|
49
|
+
* headers: {
|
|
50
|
+
* 'X-Total-Count': new OasHeader({
|
|
51
|
+
* description: 'Total number of items',
|
|
52
|
+
* schema: new OasInteger({ minimum: 0 })
|
|
53
|
+
* }),
|
|
54
|
+
* 'X-Page-Number': new OasHeader({
|
|
55
|
+
* description: 'Current page number',
|
|
56
|
+
* schema: new OasInteger({ minimum: 1 })
|
|
57
|
+
* }),
|
|
58
|
+
* 'Link': new OasHeader({
|
|
59
|
+
* description: 'Pagination links',
|
|
60
|
+
* schema: new OasString()
|
|
61
|
+
* })
|
|
62
|
+
* },
|
|
63
|
+
* content: {
|
|
64
|
+
* 'application/json': new OasMediaType({
|
|
65
|
+
* schema: new OasArray({
|
|
66
|
+
* items: new OasRef({ $ref: '#/components/schemas/Item' })
|
|
67
|
+
* })
|
|
68
|
+
* })
|
|
69
|
+
* }
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example Multiple content types
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const multiFormatResponse = new OasResponse({
|
|
76
|
+
* description: 'User data in multiple formats',
|
|
77
|
+
* content: {
|
|
78
|
+
* 'application/json': new OasMediaType({
|
|
79
|
+
* schema: new OasRef({ $ref: '#/components/schemas/User' })
|
|
80
|
+
* }),
|
|
81
|
+
* 'application/xml': new OasMediaType({
|
|
82
|
+
* schema: new OasObject({
|
|
83
|
+
* // XML-specific schema definition
|
|
84
|
+
* properties: {
|
|
85
|
+
* user: new OasRef({ $ref: '#/components/schemas/User' })
|
|
86
|
+
* }
|
|
87
|
+
* })
|
|
88
|
+
* }),
|
|
89
|
+
* 'text/csv': new OasMediaType({
|
|
90
|
+
* schema: new OasString({
|
|
91
|
+
* description: 'User data in CSV format'
|
|
92
|
+
* })
|
|
93
|
+
* })
|
|
94
|
+
* }
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Error responses
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const errorResponse = new OasResponse({
|
|
101
|
+
* description: 'Validation error occurred',
|
|
102
|
+
* content: {
|
|
103
|
+
* 'application/json': new OasMediaType({
|
|
104
|
+
* schema: new OasObject({
|
|
105
|
+
* properties: {
|
|
106
|
+
* error: new OasString({ description: 'Error message' }),
|
|
107
|
+
* code: new OasString({ description: 'Error code' }),
|
|
108
|
+
* details: new OasArray({
|
|
109
|
+
* items: new OasObject({
|
|
110
|
+
* properties: {
|
|
111
|
+
* field: new OasString(),
|
|
112
|
+
* message: new OasString()
|
|
113
|
+
* }
|
|
114
|
+
* })
|
|
115
|
+
* })
|
|
116
|
+
* },
|
|
117
|
+
* required: ['error', 'code']
|
|
118
|
+
* })
|
|
119
|
+
* })
|
|
120
|
+
* }
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example File download response
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const fileDownloadResponse = new OasResponse({
|
|
127
|
+
* description: 'File download',
|
|
128
|
+
* headers: {
|
|
129
|
+
* 'Content-Disposition': new OasHeader({
|
|
130
|
+
* description: 'Attachment filename',
|
|
131
|
+
* schema: new OasString({ example: 'attachment; filename="report.pdf"' })
|
|
132
|
+
* }),
|
|
133
|
+
* 'Content-Length': new OasHeader({
|
|
134
|
+
* description: 'File size in bytes',
|
|
135
|
+
* schema: new OasInteger({ minimum: 0 })
|
|
136
|
+
* })
|
|
137
|
+
* },
|
|
138
|
+
* content: {
|
|
139
|
+
* 'application/pdf': new OasMediaType({
|
|
140
|
+
* schema: new OasString({
|
|
141
|
+
* format: 'binary',
|
|
142
|
+
* description: 'PDF file content'
|
|
143
|
+
* })
|
|
144
|
+
* }),
|
|
145
|
+
* 'application/octet-stream': new OasMediaType({
|
|
146
|
+
* schema: new OasString({
|
|
147
|
+
* format: 'binary',
|
|
148
|
+
* description: 'Generic binary content'
|
|
149
|
+
* })
|
|
150
|
+
* })
|
|
151
|
+
* }
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @example No content response
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const noContentResponse = new OasResponse({
|
|
158
|
+
* description: 'Operation completed successfully, no content returned'
|
|
159
|
+
* // No content or headers - represents HTTP 204 No Content
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example Using in operation definitions
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const getUserOperation = new OasOperation({
|
|
166
|
+
* path: '/users/{id}',
|
|
167
|
+
* method: 'get',
|
|
168
|
+
* responses: {
|
|
169
|
+
* '200': successResponse,
|
|
170
|
+
* '404': new OasResponse({
|
|
171
|
+
* description: 'User not found',
|
|
172
|
+
* content: {
|
|
173
|
+
* 'application/json': new OasMediaType({
|
|
174
|
+
* schema: new OasObject({
|
|
175
|
+
* properties: {
|
|
176
|
+
* error: new OasString({ example: 'User not found' }),
|
|
177
|
+
* code: new OasString({ example: 'USER_NOT_FOUND' })
|
|
178
|
+
* }
|
|
179
|
+
* })
|
|
180
|
+
* })
|
|
181
|
+
* }
|
|
182
|
+
* }),
|
|
183
|
+
* '500': new OasRef({ $ref: '#/components/responses/InternalServerError' })
|
|
184
|
+
* }
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
5
188
|
class OasResponse {
|
|
6
189
|
constructor(fields) {
|
|
7
190
|
Object.defineProperty(this, "oasType", {
|