@skmtc/core 0.0.790 → 0.0.792
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/helpers/naming.d.ts +65 -1
- package/esm/helpers/naming.d.ts.map +1 -1
- package/esm/helpers/naming.js +65 -1
- package/esm/oas/example/Example.d.ts +81 -1
- package/esm/oas/example/Example.d.ts.map +1 -1
- package/esm/oas/example/Example.js +74 -1
- package/esm/oas/header/Header.d.ts +217 -1
- package/esm/oas/header/Header.d.ts.map +1 -1
- package/esm/oas/header/Header.js +207 -1
- package/esm/oas/info/Info.d.ts +72 -0
- package/esm/oas/info/Info.d.ts.map +1 -1
- package/esm/oas/info/Info.js +62 -0
- package/esm/oas/mediaType/MediaType.d.ts +85 -0
- package/esm/oas/mediaType/MediaType.d.ts.map +1 -1
- package/esm/oas/mediaType/MediaType.js +77 -0
- 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/pathItem/PathItem.d.ts +92 -0
- package/esm/oas/pathItem/PathItem.d.ts.map +1 -1
- package/esm/oas/pathItem/PathItem.js +85 -0
- package/esm/oas/requestBody/RequestBody.d.ts +264 -0
- package/esm/oas/requestBody/RequestBody.d.ts.map +1 -1
- package/esm/oas/requestBody/RequestBody.js +257 -0
- 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/helpers/naming.d.ts +65 -1
- package/script/helpers/naming.d.ts.map +1 -1
- package/script/helpers/naming.js +65 -1
- package/script/oas/example/Example.d.ts +81 -1
- package/script/oas/example/Example.d.ts.map +1 -1
- package/script/oas/example/Example.js +74 -1
- package/script/oas/header/Header.d.ts +217 -1
- package/script/oas/header/Header.d.ts.map +1 -1
- package/script/oas/header/Header.js +207 -1
- package/script/oas/info/Info.d.ts +72 -0
- package/script/oas/info/Info.d.ts.map +1 -1
- package/script/oas/info/Info.js +62 -0
- package/script/oas/mediaType/MediaType.d.ts +85 -0
- package/script/oas/mediaType/MediaType.d.ts.map +1 -1
- package/script/oas/mediaType/MediaType.js +77 -0
- 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/pathItem/PathItem.d.ts +92 -0
- package/script/oas/pathItem/PathItem.d.ts.map +1 -1
- package/script/oas/pathItem/PathItem.js +85 -0
- package/script/oas/requestBody/RequestBody.d.ts +264 -0
- package/script/oas/requestBody/RequestBody.d.ts.map +1 -1
- package/script/oas/requestBody/RequestBody.js +257 -0
- 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
|
@@ -4,12 +4,276 @@ import type { OasRef } from '../ref/Ref.js';
|
|
|
4
4
|
import type { OasSchema } from '../schema/Schema.js';
|
|
5
5
|
import type { ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
6
6
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
7
|
+
/**
|
|
8
|
+
* Constructor fields for {@link OasRequestBody}.
|
|
9
|
+
*/
|
|
7
10
|
export type RequestBodyFields = {
|
|
11
|
+
/** A description of the request body */
|
|
8
12
|
description?: string | undefined;
|
|
13
|
+
/** Request content for different media types */
|
|
9
14
|
content: Record<string, OasMediaType>;
|
|
15
|
+
/** Whether the request body is required */
|
|
10
16
|
required?: boolean | undefined;
|
|
17
|
+
/** Custom extension fields (x-* properties) */
|
|
11
18
|
extensionFields?: Record<string, unknown>;
|
|
12
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Represents a Request Body Object in the OpenAPI Specification.
|
|
22
|
+
*
|
|
23
|
+
* The `OasRequestBody` class encapsulates the definition of a request body that
|
|
24
|
+
* can be sent with HTTP operations. It supports multiple content types, schema
|
|
25
|
+
* validation, and can be marked as required or optional. Request bodies are
|
|
26
|
+
* commonly used with POST, PUT, PATCH, and sometimes DELETE operations.
|
|
27
|
+
*
|
|
28
|
+
* This class provides comprehensive support for request body definitions with
|
|
29
|
+
* typed content, multiple media type representations, and proper validation.
|
|
30
|
+
*
|
|
31
|
+
* ## Key Features
|
|
32
|
+
*
|
|
33
|
+
* - **Multiple Content Types**: Support for JSON, XML, form data, binary, and more
|
|
34
|
+
* - **Schema Validation**: Typed request bodies through schema definitions
|
|
35
|
+
* - **Required/Optional**: Control whether the request body is mandatory
|
|
36
|
+
* - **Reference Support**: Can reference reusable request body components
|
|
37
|
+
* - **Documentation**: Rich description support for API documentation
|
|
38
|
+
* - **Media Type Flexibility**: Different schemas for different content types
|
|
39
|
+
*
|
|
40
|
+
* @example Basic JSON request body
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { OasRequestBody, OasMediaType, OasObject, OasString } from '@skmtc/core';
|
|
43
|
+
*
|
|
44
|
+
* const createUserRequest = new OasRequestBody({
|
|
45
|
+
* description: 'User data for creating a new user account',
|
|
46
|
+
* required: true,
|
|
47
|
+
* content: {
|
|
48
|
+
* 'application/json': new OasMediaType({
|
|
49
|
+
* schema: new OasObject({
|
|
50
|
+
* properties: {
|
|
51
|
+
* name: new OasString({
|
|
52
|
+
* description: 'Full name',
|
|
53
|
+
* minLength: 1,
|
|
54
|
+
* maxLength: 100
|
|
55
|
+
* }),
|
|
56
|
+
* email: new OasString({
|
|
57
|
+
* format: 'email',
|
|
58
|
+
* description: 'Email address'
|
|
59
|
+
* }),
|
|
60
|
+
* password: new OasString({
|
|
61
|
+
* minLength: 8,
|
|
62
|
+
* description: 'Account password'
|
|
63
|
+
* })
|
|
64
|
+
* },
|
|
65
|
+
* required: ['name', 'email', 'password']
|
|
66
|
+
* })
|
|
67
|
+
* })
|
|
68
|
+
* }
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Multiple content types
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const multiFormatRequest = new OasRequestBody({
|
|
75
|
+
* description: 'Product data in multiple formats',
|
|
76
|
+
* required: true,
|
|
77
|
+
* content: {
|
|
78
|
+
* 'application/json': new OasMediaType({
|
|
79
|
+
* schema: new OasRef({ $ref: '#/components/schemas/Product' })
|
|
80
|
+
* }),
|
|
81
|
+
* 'application/xml': new OasMediaType({
|
|
82
|
+
* schema: new OasObject({
|
|
83
|
+
* properties: {
|
|
84
|
+
* product: new OasRef({ $ref: '#/components/schemas/Product' })
|
|
85
|
+
* }
|
|
86
|
+
* })
|
|
87
|
+
* }),
|
|
88
|
+
* 'application/x-www-form-urlencoded': new OasMediaType({
|
|
89
|
+
* schema: new OasObject({
|
|
90
|
+
* properties: {
|
|
91
|
+
* name: new OasString(),
|
|
92
|
+
* price: new OasNumber({ format: 'double' }),
|
|
93
|
+
* category_id: new OasInteger()
|
|
94
|
+
* }
|
|
95
|
+
* })
|
|
96
|
+
* })
|
|
97
|
+
* }
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @example File upload request body
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const fileUploadRequest = new OasRequestBody({
|
|
104
|
+
* description: 'File upload with metadata',
|
|
105
|
+
* required: true,
|
|
106
|
+
* content: {
|
|
107
|
+
* 'multipart/form-data': new OasMediaType({
|
|
108
|
+
* schema: new OasObject({
|
|
109
|
+
* properties: {
|
|
110
|
+
* file: new OasString({
|
|
111
|
+
* format: 'binary',
|
|
112
|
+
* description: 'The file to upload'
|
|
113
|
+
* }),
|
|
114
|
+
* filename: new OasString({
|
|
115
|
+
* description: 'Original filename'
|
|
116
|
+
* }),
|
|
117
|
+
* description: new OasString({
|
|
118
|
+
* description: 'File description',
|
|
119
|
+
* required: false
|
|
120
|
+
* }),
|
|
121
|
+
* tags: new OasArray({
|
|
122
|
+
* items: new OasString(),
|
|
123
|
+
* description: 'File tags'
|
|
124
|
+
* })
|
|
125
|
+
* },
|
|
126
|
+
* required: ['file', 'filename']
|
|
127
|
+
* })
|
|
128
|
+
* }),
|
|
129
|
+
* 'application/octet-stream': new OasMediaType({
|
|
130
|
+
* schema: new OasString({
|
|
131
|
+
* format: 'binary',
|
|
132
|
+
* description: 'Raw binary file content'
|
|
133
|
+
* })
|
|
134
|
+
* })
|
|
135
|
+
* }
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @example Optional request body for updates
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const updateUserRequest = new OasRequestBody({
|
|
142
|
+
* description: 'Partial user data for updates (all fields optional)',
|
|
143
|
+
* required: false, // Request body itself is optional
|
|
144
|
+
* content: {
|
|
145
|
+
* 'application/json': new OasMediaType({
|
|
146
|
+
* schema: new OasObject({
|
|
147
|
+
* properties: {
|
|
148
|
+
* name: new OasString({ description: 'Updated name' }),
|
|
149
|
+
* email: new OasString({
|
|
150
|
+
* format: 'email',
|
|
151
|
+
* description: 'Updated email'
|
|
152
|
+
* }),
|
|
153
|
+
* bio: new OasString({ description: 'User biography' }),
|
|
154
|
+
* preferences: new OasObject({
|
|
155
|
+
* properties: {
|
|
156
|
+
* notifications: new OasBoolean(),
|
|
157
|
+
* theme: new OasString({ enum: ['light', 'dark'] })
|
|
158
|
+
* }
|
|
159
|
+
* })
|
|
160
|
+
* }
|
|
161
|
+
* // No required fields - all updates are optional
|
|
162
|
+
* })
|
|
163
|
+
* })
|
|
164
|
+
* }
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example Complex nested data structures
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const orderRequest = new OasRequestBody({
|
|
171
|
+
* description: 'Complete order with items and shipping',
|
|
172
|
+
* required: true,
|
|
173
|
+
* content: {
|
|
174
|
+
* 'application/json': new OasMediaType({
|
|
175
|
+
* schema: new OasObject({
|
|
176
|
+
* properties: {
|
|
177
|
+
* customer: new OasObject({
|
|
178
|
+
* properties: {
|
|
179
|
+
* id: new OasString(),
|
|
180
|
+
* email: new OasString({ format: 'email' })
|
|
181
|
+
* },
|
|
182
|
+
* required: ['id']
|
|
183
|
+
* }),
|
|
184
|
+
* items: new OasArray({
|
|
185
|
+
* items: new OasObject({
|
|
186
|
+
* properties: {
|
|
187
|
+
* productId: new OasString(),
|
|
188
|
+
* quantity: new OasInteger({ minimum: 1 }),
|
|
189
|
+
* customizations: new OasArray({
|
|
190
|
+
* items: new OasString()
|
|
191
|
+
* })
|
|
192
|
+
* },
|
|
193
|
+
* required: ['productId', 'quantity']
|
|
194
|
+
* }),
|
|
195
|
+
* minItems: 1
|
|
196
|
+
* }),
|
|
197
|
+
* shipping: new OasObject({
|
|
198
|
+
* properties: {
|
|
199
|
+
* address: new OasRef({ $ref: '#/components/schemas/Address' }),
|
|
200
|
+
* method: new OasString({ enum: ['standard', 'express', 'overnight'] }),
|
|
201
|
+
* instructions: new OasString()
|
|
202
|
+
* },
|
|
203
|
+
* required: ['address', 'method']
|
|
204
|
+
* }),
|
|
205
|
+
* couponCode: new OasString({ description: 'Optional discount code' })
|
|
206
|
+
* },
|
|
207
|
+
* required: ['customer', 'items', 'shipping']
|
|
208
|
+
* })
|
|
209
|
+
* })
|
|
210
|
+
* }
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @example Form data with validation
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const registrationForm = new OasRequestBody({
|
|
217
|
+
* description: 'User registration form data',
|
|
218
|
+
* required: true,
|
|
219
|
+
* content: {
|
|
220
|
+
* 'application/x-www-form-urlencoded': new OasMediaType({
|
|
221
|
+
* schema: new OasObject({
|
|
222
|
+
* properties: {
|
|
223
|
+
* username: new OasString({
|
|
224
|
+
* pattern: '^[a-zA-Z0-9_]{3,20}$',
|
|
225
|
+
* description: 'Alphanumeric username, 3-20 characters'
|
|
226
|
+
* }),
|
|
227
|
+
* email: new OasString({
|
|
228
|
+
* format: 'email',
|
|
229
|
+
* description: 'Valid email address'
|
|
230
|
+
* }),
|
|
231
|
+
* password: new OasString({
|
|
232
|
+
* minLength: 8,
|
|
233
|
+
* description: 'Password, minimum 8 characters'
|
|
234
|
+
* }),
|
|
235
|
+
* confirmPassword: new OasString({
|
|
236
|
+
* description: 'Password confirmation'
|
|
237
|
+
* }),
|
|
238
|
+
* agreeToTerms: new OasBoolean({
|
|
239
|
+
* enum: [true],
|
|
240
|
+
* description: 'Must accept terms of service'
|
|
241
|
+
* })
|
|
242
|
+
* },
|
|
243
|
+
* required: ['username', 'email', 'password', 'confirmPassword', 'agreeToTerms']
|
|
244
|
+
* })
|
|
245
|
+
* })
|
|
246
|
+
* }
|
|
247
|
+
* });
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @example Using in operation definitions
|
|
251
|
+
* ```typescript
|
|
252
|
+
* const createProductOperation = new OasOperation({
|
|
253
|
+
* path: '/products',
|
|
254
|
+
* method: 'post',
|
|
255
|
+
* requestBody: createUserRequest,
|
|
256
|
+
* responses: {
|
|
257
|
+
* '201': new OasResponse({
|
|
258
|
+
* description: 'Product created successfully',
|
|
259
|
+
* content: {
|
|
260
|
+
* 'application/json': new OasMediaType({
|
|
261
|
+
* schema: new OasRef({ $ref: '#/components/schemas/Product' })
|
|
262
|
+
* })
|
|
263
|
+
* }
|
|
264
|
+
* }),
|
|
265
|
+
* '400': new OasResponse({
|
|
266
|
+
* description: 'Invalid request data',
|
|
267
|
+
* content: {
|
|
268
|
+
* 'application/json': new OasMediaType({
|
|
269
|
+
* schema: new OasRef({ $ref: '#/components/schemas/ValidationError' })
|
|
270
|
+
* })
|
|
271
|
+
* }
|
|
272
|
+
* })
|
|
273
|
+
* }
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
13
277
|
export declare class OasRequestBody {
|
|
14
278
|
oasType: 'requestBody';
|
|
15
279
|
description: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestBody.d.ts","sourceRoot":"","sources":["../../../src/oas/requestBody/RequestBody.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,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,iBAAiB,GAAG;IAC9B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACrC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC1C,CAAA;AAED,qBAAa,cAAc;IACzB,OAAO,EAAE,aAAa,CAAgB;IACtC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACrC,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;gBACxC,MAAM,EAAE,iBAAiB;IAOrC,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,aAAa,CAAC;IAItC,OAAO,IAAI,cAAc;IAIzB,WAAW,IAAI,cAAc;IAI7B,QAAQ,CAAC,SAAS,GAAE,MAA2B,GAAG,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS;IAI1F,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,iBAAiB;CAYxE"}
|
|
1
|
+
{"version":3,"file":"RequestBody.d.ts","sourceRoot":"","sources":["../../../src/oas/requestBody/RequestBody.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,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,iBAAiB,GAAG;IAC9B,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACrC,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC9B,+CAA+C;IAC/C,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC1C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgQG;AACH,qBAAa,cAAc;IACzB,OAAO,EAAE,aAAa,CAAgB;IACtC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACrC,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;gBACxC,MAAM,EAAE,iBAAiB;IAOrC,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,aAAa,CAAC;IAItC,OAAO,IAAI,cAAc;IAIzB,WAAW,IAAI,cAAc;IAI7B,QAAQ,CAAC,SAAS,GAAE,MAA2B,GAAG,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS;IAI1F,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,iBAAiB;CAYxE"}
|
|
@@ -1,4 +1,261 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a Request Body Object in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* The `OasRequestBody` class encapsulates the definition of a request body that
|
|
6
|
+
* can be sent with HTTP operations. It supports multiple content types, schema
|
|
7
|
+
* validation, and can be marked as required or optional. Request bodies are
|
|
8
|
+
* commonly used with POST, PUT, PATCH, and sometimes DELETE operations.
|
|
9
|
+
*
|
|
10
|
+
* This class provides comprehensive support for request body definitions with
|
|
11
|
+
* typed content, multiple media type representations, and proper validation.
|
|
12
|
+
*
|
|
13
|
+
* ## Key Features
|
|
14
|
+
*
|
|
15
|
+
* - **Multiple Content Types**: Support for JSON, XML, form data, binary, and more
|
|
16
|
+
* - **Schema Validation**: Typed request bodies through schema definitions
|
|
17
|
+
* - **Required/Optional**: Control whether the request body is mandatory
|
|
18
|
+
* - **Reference Support**: Can reference reusable request body components
|
|
19
|
+
* - **Documentation**: Rich description support for API documentation
|
|
20
|
+
* - **Media Type Flexibility**: Different schemas for different content types
|
|
21
|
+
*
|
|
22
|
+
* @example Basic JSON request body
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { OasRequestBody, OasMediaType, OasObject, OasString } from '@skmtc/core';
|
|
25
|
+
*
|
|
26
|
+
* const createUserRequest = new OasRequestBody({
|
|
27
|
+
* description: 'User data for creating a new user account',
|
|
28
|
+
* required: true,
|
|
29
|
+
* content: {
|
|
30
|
+
* 'application/json': new OasMediaType({
|
|
31
|
+
* schema: new OasObject({
|
|
32
|
+
* properties: {
|
|
33
|
+
* name: new OasString({
|
|
34
|
+
* description: 'Full name',
|
|
35
|
+
* minLength: 1,
|
|
36
|
+
* maxLength: 100
|
|
37
|
+
* }),
|
|
38
|
+
* email: new OasString({
|
|
39
|
+
* format: 'email',
|
|
40
|
+
* description: 'Email address'
|
|
41
|
+
* }),
|
|
42
|
+
* password: new OasString({
|
|
43
|
+
* minLength: 8,
|
|
44
|
+
* description: 'Account password'
|
|
45
|
+
* })
|
|
46
|
+
* },
|
|
47
|
+
* required: ['name', 'email', 'password']
|
|
48
|
+
* })
|
|
49
|
+
* })
|
|
50
|
+
* }
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example Multiple content types
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const multiFormatRequest = new OasRequestBody({
|
|
57
|
+
* description: 'Product data in multiple formats',
|
|
58
|
+
* required: true,
|
|
59
|
+
* content: {
|
|
60
|
+
* 'application/json': new OasMediaType({
|
|
61
|
+
* schema: new OasRef({ $ref: '#/components/schemas/Product' })
|
|
62
|
+
* }),
|
|
63
|
+
* 'application/xml': new OasMediaType({
|
|
64
|
+
* schema: new OasObject({
|
|
65
|
+
* properties: {
|
|
66
|
+
* product: new OasRef({ $ref: '#/components/schemas/Product' })
|
|
67
|
+
* }
|
|
68
|
+
* })
|
|
69
|
+
* }),
|
|
70
|
+
* 'application/x-www-form-urlencoded': new OasMediaType({
|
|
71
|
+
* schema: new OasObject({
|
|
72
|
+
* properties: {
|
|
73
|
+
* name: new OasString(),
|
|
74
|
+
* price: new OasNumber({ format: 'double' }),
|
|
75
|
+
* category_id: new OasInteger()
|
|
76
|
+
* }
|
|
77
|
+
* })
|
|
78
|
+
* })
|
|
79
|
+
* }
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example File upload request body
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const fileUploadRequest = new OasRequestBody({
|
|
86
|
+
* description: 'File upload with metadata',
|
|
87
|
+
* required: true,
|
|
88
|
+
* content: {
|
|
89
|
+
* 'multipart/form-data': new OasMediaType({
|
|
90
|
+
* schema: new OasObject({
|
|
91
|
+
* properties: {
|
|
92
|
+
* file: new OasString({
|
|
93
|
+
* format: 'binary',
|
|
94
|
+
* description: 'The file to upload'
|
|
95
|
+
* }),
|
|
96
|
+
* filename: new OasString({
|
|
97
|
+
* description: 'Original filename'
|
|
98
|
+
* }),
|
|
99
|
+
* description: new OasString({
|
|
100
|
+
* description: 'File description',
|
|
101
|
+
* required: false
|
|
102
|
+
* }),
|
|
103
|
+
* tags: new OasArray({
|
|
104
|
+
* items: new OasString(),
|
|
105
|
+
* description: 'File tags'
|
|
106
|
+
* })
|
|
107
|
+
* },
|
|
108
|
+
* required: ['file', 'filename']
|
|
109
|
+
* })
|
|
110
|
+
* }),
|
|
111
|
+
* 'application/octet-stream': new OasMediaType({
|
|
112
|
+
* schema: new OasString({
|
|
113
|
+
* format: 'binary',
|
|
114
|
+
* description: 'Raw binary file content'
|
|
115
|
+
* })
|
|
116
|
+
* })
|
|
117
|
+
* }
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @example Optional request body for updates
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const updateUserRequest = new OasRequestBody({
|
|
124
|
+
* description: 'Partial user data for updates (all fields optional)',
|
|
125
|
+
* required: false, // Request body itself is optional
|
|
126
|
+
* content: {
|
|
127
|
+
* 'application/json': new OasMediaType({
|
|
128
|
+
* schema: new OasObject({
|
|
129
|
+
* properties: {
|
|
130
|
+
* name: new OasString({ description: 'Updated name' }),
|
|
131
|
+
* email: new OasString({
|
|
132
|
+
* format: 'email',
|
|
133
|
+
* description: 'Updated email'
|
|
134
|
+
* }),
|
|
135
|
+
* bio: new OasString({ description: 'User biography' }),
|
|
136
|
+
* preferences: new OasObject({
|
|
137
|
+
* properties: {
|
|
138
|
+
* notifications: new OasBoolean(),
|
|
139
|
+
* theme: new OasString({ enum: ['light', 'dark'] })
|
|
140
|
+
* }
|
|
141
|
+
* })
|
|
142
|
+
* }
|
|
143
|
+
* // No required fields - all updates are optional
|
|
144
|
+
* })
|
|
145
|
+
* })
|
|
146
|
+
* }
|
|
147
|
+
* });
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @example Complex nested data structures
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const orderRequest = new OasRequestBody({
|
|
153
|
+
* description: 'Complete order with items and shipping',
|
|
154
|
+
* required: true,
|
|
155
|
+
* content: {
|
|
156
|
+
* 'application/json': new OasMediaType({
|
|
157
|
+
* schema: new OasObject({
|
|
158
|
+
* properties: {
|
|
159
|
+
* customer: new OasObject({
|
|
160
|
+
* properties: {
|
|
161
|
+
* id: new OasString(),
|
|
162
|
+
* email: new OasString({ format: 'email' })
|
|
163
|
+
* },
|
|
164
|
+
* required: ['id']
|
|
165
|
+
* }),
|
|
166
|
+
* items: new OasArray({
|
|
167
|
+
* items: new OasObject({
|
|
168
|
+
* properties: {
|
|
169
|
+
* productId: new OasString(),
|
|
170
|
+
* quantity: new OasInteger({ minimum: 1 }),
|
|
171
|
+
* customizations: new OasArray({
|
|
172
|
+
* items: new OasString()
|
|
173
|
+
* })
|
|
174
|
+
* },
|
|
175
|
+
* required: ['productId', 'quantity']
|
|
176
|
+
* }),
|
|
177
|
+
* minItems: 1
|
|
178
|
+
* }),
|
|
179
|
+
* shipping: new OasObject({
|
|
180
|
+
* properties: {
|
|
181
|
+
* address: new OasRef({ $ref: '#/components/schemas/Address' }),
|
|
182
|
+
* method: new OasString({ enum: ['standard', 'express', 'overnight'] }),
|
|
183
|
+
* instructions: new OasString()
|
|
184
|
+
* },
|
|
185
|
+
* required: ['address', 'method']
|
|
186
|
+
* }),
|
|
187
|
+
* couponCode: new OasString({ description: 'Optional discount code' })
|
|
188
|
+
* },
|
|
189
|
+
* required: ['customer', 'items', 'shipping']
|
|
190
|
+
* })
|
|
191
|
+
* })
|
|
192
|
+
* }
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @example Form data with validation
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const registrationForm = new OasRequestBody({
|
|
199
|
+
* description: 'User registration form data',
|
|
200
|
+
* required: true,
|
|
201
|
+
* content: {
|
|
202
|
+
* 'application/x-www-form-urlencoded': new OasMediaType({
|
|
203
|
+
* schema: new OasObject({
|
|
204
|
+
* properties: {
|
|
205
|
+
* username: new OasString({
|
|
206
|
+
* pattern: '^[a-zA-Z0-9_]{3,20}$',
|
|
207
|
+
* description: 'Alphanumeric username, 3-20 characters'
|
|
208
|
+
* }),
|
|
209
|
+
* email: new OasString({
|
|
210
|
+
* format: 'email',
|
|
211
|
+
* description: 'Valid email address'
|
|
212
|
+
* }),
|
|
213
|
+
* password: new OasString({
|
|
214
|
+
* minLength: 8,
|
|
215
|
+
* description: 'Password, minimum 8 characters'
|
|
216
|
+
* }),
|
|
217
|
+
* confirmPassword: new OasString({
|
|
218
|
+
* description: 'Password confirmation'
|
|
219
|
+
* }),
|
|
220
|
+
* agreeToTerms: new OasBoolean({
|
|
221
|
+
* enum: [true],
|
|
222
|
+
* description: 'Must accept terms of service'
|
|
223
|
+
* })
|
|
224
|
+
* },
|
|
225
|
+
* required: ['username', 'email', 'password', 'confirmPassword', 'agreeToTerms']
|
|
226
|
+
* })
|
|
227
|
+
* })
|
|
228
|
+
* }
|
|
229
|
+
* });
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @example Using in operation definitions
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const createProductOperation = new OasOperation({
|
|
235
|
+
* path: '/products',
|
|
236
|
+
* method: 'post',
|
|
237
|
+
* requestBody: createUserRequest,
|
|
238
|
+
* responses: {
|
|
239
|
+
* '201': new OasResponse({
|
|
240
|
+
* description: 'Product created successfully',
|
|
241
|
+
* content: {
|
|
242
|
+
* 'application/json': new OasMediaType({
|
|
243
|
+
* schema: new OasRef({ $ref: '#/components/schemas/Product' })
|
|
244
|
+
* })
|
|
245
|
+
* }
|
|
246
|
+
* }),
|
|
247
|
+
* '400': new OasResponse({
|
|
248
|
+
* description: 'Invalid request data',
|
|
249
|
+
* content: {
|
|
250
|
+
* 'application/json': new OasMediaType({
|
|
251
|
+
* schema: new OasRef({ $ref: '#/components/schemas/ValidationError' })
|
|
252
|
+
* })
|
|
253
|
+
* }
|
|
254
|
+
* })
|
|
255
|
+
* }
|
|
256
|
+
* });
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
2
259
|
export class OasRequestBody {
|
|
3
260
|
constructor(fields) {
|
|
4
261
|
Object.defineProperty(this, "oasType", {
|