@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
|
@@ -1,4 +1,187 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a Response Object in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* The `OasResponse` class encapsulates the definition of a single HTTP response,
|
|
6
|
+
* including its description, headers, and content for different media types.
|
|
7
|
+
* Responses describe the possible outcomes of API operations and can include
|
|
8
|
+
* both successful and error scenarios.
|
|
9
|
+
*
|
|
10
|
+
* This class provides comprehensive support for response definitions with typed
|
|
11
|
+
* content, custom headers, and multiple media type representations.
|
|
12
|
+
*
|
|
13
|
+
* ## Key Features
|
|
14
|
+
*
|
|
15
|
+
* - **Content Types**: Support for multiple media types (JSON, XML, HTML, etc.)
|
|
16
|
+
* - **Header Definitions**: Custom response headers with validation
|
|
17
|
+
* - **Schema Integration**: Typed response bodies through schema definitions
|
|
18
|
+
* - **Reference Support**: Can reference reusable response components
|
|
19
|
+
* - **Documentation**: Rich description support for API documentation
|
|
20
|
+
* - **JSON Schema**: Converts to standard JSON Schema format for validation
|
|
21
|
+
*
|
|
22
|
+
* @example Basic JSON response
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { OasResponse, OasMediaType, OasObject, OasString } from '@skmtc/core';
|
|
25
|
+
*
|
|
26
|
+
* const successResponse = new OasResponse({
|
|
27
|
+
* description: 'User retrieved successfully',
|
|
28
|
+
* content: {
|
|
29
|
+
* 'application/json': new OasMediaType({
|
|
30
|
+
* schema: new OasObject({
|
|
31
|
+
* properties: {
|
|
32
|
+
* id: new OasString(),
|
|
33
|
+
* name: new OasString(),
|
|
34
|
+
* email: new OasString({ format: 'email' })
|
|
35
|
+
* }
|
|
36
|
+
* })
|
|
37
|
+
* })
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example Response with custom headers
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const paginatedResponse = new OasResponse({
|
|
45
|
+
* description: 'Paginated list of items',
|
|
46
|
+
* headers: {
|
|
47
|
+
* 'X-Total-Count': new OasHeader({
|
|
48
|
+
* description: 'Total number of items',
|
|
49
|
+
* schema: new OasInteger({ minimum: 0 })
|
|
50
|
+
* }),
|
|
51
|
+
* 'X-Page-Number': new OasHeader({
|
|
52
|
+
* description: 'Current page number',
|
|
53
|
+
* schema: new OasInteger({ minimum: 1 })
|
|
54
|
+
* }),
|
|
55
|
+
* 'Link': new OasHeader({
|
|
56
|
+
* description: 'Pagination links',
|
|
57
|
+
* schema: new OasString()
|
|
58
|
+
* })
|
|
59
|
+
* },
|
|
60
|
+
* content: {
|
|
61
|
+
* 'application/json': new OasMediaType({
|
|
62
|
+
* schema: new OasArray({
|
|
63
|
+
* items: new OasRef({ $ref: '#/components/schemas/Item' })
|
|
64
|
+
* })
|
|
65
|
+
* })
|
|
66
|
+
* }
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example Multiple content types
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const multiFormatResponse = new OasResponse({
|
|
73
|
+
* description: 'User data in multiple formats',
|
|
74
|
+
* content: {
|
|
75
|
+
* 'application/json': new OasMediaType({
|
|
76
|
+
* schema: new OasRef({ $ref: '#/components/schemas/User' })
|
|
77
|
+
* }),
|
|
78
|
+
* 'application/xml': new OasMediaType({
|
|
79
|
+
* schema: new OasObject({
|
|
80
|
+
* // XML-specific schema definition
|
|
81
|
+
* properties: {
|
|
82
|
+
* user: new OasRef({ $ref: '#/components/schemas/User' })
|
|
83
|
+
* }
|
|
84
|
+
* })
|
|
85
|
+
* }),
|
|
86
|
+
* 'text/csv': new OasMediaType({
|
|
87
|
+
* schema: new OasString({
|
|
88
|
+
* description: 'User data in CSV format'
|
|
89
|
+
* })
|
|
90
|
+
* })
|
|
91
|
+
* }
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example Error responses
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const errorResponse = new OasResponse({
|
|
98
|
+
* description: 'Validation error occurred',
|
|
99
|
+
* content: {
|
|
100
|
+
* 'application/json': new OasMediaType({
|
|
101
|
+
* schema: new OasObject({
|
|
102
|
+
* properties: {
|
|
103
|
+
* error: new OasString({ description: 'Error message' }),
|
|
104
|
+
* code: new OasString({ description: 'Error code' }),
|
|
105
|
+
* details: new OasArray({
|
|
106
|
+
* items: new OasObject({
|
|
107
|
+
* properties: {
|
|
108
|
+
* field: new OasString(),
|
|
109
|
+
* message: new OasString()
|
|
110
|
+
* }
|
|
111
|
+
* })
|
|
112
|
+
* })
|
|
113
|
+
* },
|
|
114
|
+
* required: ['error', 'code']
|
|
115
|
+
* })
|
|
116
|
+
* })
|
|
117
|
+
* }
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @example File download response
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const fileDownloadResponse = new OasResponse({
|
|
124
|
+
* description: 'File download',
|
|
125
|
+
* headers: {
|
|
126
|
+
* 'Content-Disposition': new OasHeader({
|
|
127
|
+
* description: 'Attachment filename',
|
|
128
|
+
* schema: new OasString({ example: 'attachment; filename="report.pdf"' })
|
|
129
|
+
* }),
|
|
130
|
+
* 'Content-Length': new OasHeader({
|
|
131
|
+
* description: 'File size in bytes',
|
|
132
|
+
* schema: new OasInteger({ minimum: 0 })
|
|
133
|
+
* })
|
|
134
|
+
* },
|
|
135
|
+
* content: {
|
|
136
|
+
* 'application/pdf': new OasMediaType({
|
|
137
|
+
* schema: new OasString({
|
|
138
|
+
* format: 'binary',
|
|
139
|
+
* description: 'PDF file content'
|
|
140
|
+
* })
|
|
141
|
+
* }),
|
|
142
|
+
* 'application/octet-stream': new OasMediaType({
|
|
143
|
+
* schema: new OasString({
|
|
144
|
+
* format: 'binary',
|
|
145
|
+
* description: 'Generic binary content'
|
|
146
|
+
* })
|
|
147
|
+
* })
|
|
148
|
+
* }
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @example No content response
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const noContentResponse = new OasResponse({
|
|
155
|
+
* description: 'Operation completed successfully, no content returned'
|
|
156
|
+
* // No content or headers - represents HTTP 204 No Content
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @example Using in operation definitions
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const getUserOperation = new OasOperation({
|
|
163
|
+
* path: '/users/{id}',
|
|
164
|
+
* method: 'get',
|
|
165
|
+
* responses: {
|
|
166
|
+
* '200': successResponse,
|
|
167
|
+
* '404': new OasResponse({
|
|
168
|
+
* description: 'User not found',
|
|
169
|
+
* content: {
|
|
170
|
+
* 'application/json': new OasMediaType({
|
|
171
|
+
* schema: new OasObject({
|
|
172
|
+
* properties: {
|
|
173
|
+
* error: new OasString({ example: 'User not found' }),
|
|
174
|
+
* code: new OasString({ example: 'USER_NOT_FOUND' })
|
|
175
|
+
* }
|
|
176
|
+
* })
|
|
177
|
+
* })
|
|
178
|
+
* }
|
|
179
|
+
* }),
|
|
180
|
+
* '500': new OasRef({ $ref: '#/components/responses/InternalServerError' })
|
|
181
|
+
* }
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
2
185
|
export class OasResponse {
|
|
3
186
|
constructor(fields) {
|
|
4
187
|
Object.defineProperty(this, "oasType", {
|
package/esm/oas/void/Void.d.ts
CHANGED
|
@@ -1,13 +1,140 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
import type { OasRef } from '../ref/Ref.js';
|
|
3
|
+
/**
|
|
4
|
+
* Constructor fields for {@link OasVoid}.
|
|
5
|
+
*/
|
|
3
6
|
export type VoidFields = {
|
|
7
|
+
/** A short summary of the void schema */
|
|
4
8
|
title?: string;
|
|
9
|
+
/** A description of what the void represents */
|
|
5
10
|
description?: string;
|
|
6
11
|
};
|
|
7
12
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
13
|
+
* Represents a void (empty) schema in the OpenAPI Specification.
|
|
14
|
+
*
|
|
15
|
+
* The `OasVoid` class represents the absence of a value or content, commonly used
|
|
16
|
+
* in scenarios where operations don't return any content (like HTTP 204 No Content
|
|
17
|
+
* responses), optional properties that might not be present, or fallback cases
|
|
18
|
+
* in schema processing where no specific type is defined.
|
|
19
|
+
*
|
|
20
|
+
* This class serves as a type-safe representation of "nothing" in the OpenAPI
|
|
21
|
+
* type system, enabling proper handling of void responses and empty schemas
|
|
22
|
+
* throughout the SKMTC pipeline.
|
|
23
|
+
*
|
|
24
|
+
* ## Key Features
|
|
25
|
+
*
|
|
26
|
+
* - **Empty Content Representation**: Models operations that return no content
|
|
27
|
+
* - **Type Safety**: Provides a concrete type for void/empty scenarios
|
|
28
|
+
* - **Schema Processing**: Handles missing or undefined schema definitions
|
|
29
|
+
* - **Factory Pattern**: Convenient `empty()` static method for common usage
|
|
30
|
+
* - **Pipeline Integration**: Works seamlessly with the SKMTC processing pipeline
|
|
31
|
+
*
|
|
32
|
+
* @example Basic void schema for empty responses
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { OasVoid } from '@skmtc/core';
|
|
35
|
+
*
|
|
36
|
+
* const emptyResponse = new OasVoid({
|
|
37
|
+
* title: 'No Content',
|
|
38
|
+
* description: 'Operation completed successfully with no response body'
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Used for HTTP 204 No Content responses
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example Using the empty factory method
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const voidSchema = OasVoid.empty();
|
|
47
|
+
*
|
|
48
|
+
* // Equivalent to new OasVoid({})
|
|
49
|
+
* // Commonly used as a fallback or placeholder
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example In operation responses
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const deleteOperation = new OasOperation({
|
|
55
|
+
* path: '/users/{id}',
|
|
56
|
+
* method: 'delete',
|
|
57
|
+
* responses: {
|
|
58
|
+
* '204': new OasResponse({
|
|
59
|
+
* description: 'User deleted successfully',
|
|
60
|
+
* content: {
|
|
61
|
+
* // No content for successful deletion
|
|
62
|
+
* }
|
|
63
|
+
* }),
|
|
64
|
+
* '404': new OasResponse({
|
|
65
|
+
* description: 'User not found'
|
|
66
|
+
* })
|
|
67
|
+
* }
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // The void response indicates successful deletion with no return value
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example As a schema fallback
|
|
74
|
+
* ```typescript
|
|
75
|
+
* function processSchema(schema: OasSchema | undefined): OasSchema {
|
|
76
|
+
* if (!schema) {
|
|
77
|
+
* return OasVoid.empty(); // Fallback for missing schemas
|
|
78
|
+
* }
|
|
79
|
+
* return schema;
|
|
80
|
+
* }
|
|
81
|
+
*
|
|
82
|
+
* // Ensures type safety even when schemas are missing
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example In optional object properties
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const userProfile = new OasObject({
|
|
88
|
+
* properties: {
|
|
89
|
+
* name: new OasString({ description: 'User name' }),
|
|
90
|
+
* avatar: new OasString({
|
|
91
|
+
* description: 'Avatar URL',
|
|
92
|
+
* nullable: true
|
|
93
|
+
* }),
|
|
94
|
+
* // Some properties might be processed as void if not defined
|
|
95
|
+
* metadata: processOptionalSchema(rawSchema.metadata) // might return OasVoid
|
|
96
|
+
* }
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example HTTP operations with void responses
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Common HTTP operations that return void/empty content:
|
|
103
|
+
*
|
|
104
|
+
* // DELETE - Resource removal
|
|
105
|
+
* const deleteResponse = new OasVoid({
|
|
106
|
+
* title: 'Deletion Successful',
|
|
107
|
+
* description: 'Resource was successfully deleted'
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* // PUT - Update with no response body
|
|
111
|
+
* const updateResponse = new OasVoid({
|
|
112
|
+
* title: 'Update Successful',
|
|
113
|
+
* description: 'Resource was successfully updated'
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // POST - Action with no return value
|
|
117
|
+
* const actionResponse = new OasVoid({
|
|
118
|
+
* title: 'Action Completed',
|
|
119
|
+
* description: 'Action was successfully performed'
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @example In code generation
|
|
124
|
+
* ```typescript
|
|
125
|
+
* class TypeScriptGenerator extends ModelBase {
|
|
126
|
+
* generateType(schema: OasSchema): string {
|
|
127
|
+
* if (schema.type === 'void') {
|
|
128
|
+
* return 'void'; // TypeScript void type
|
|
129
|
+
* }
|
|
130
|
+
* // Handle other types...
|
|
131
|
+
* return 'unknown';
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* // Generates:
|
|
136
|
+
* // async function deleteUser(id: string): Promise<void>
|
|
137
|
+
* ```
|
|
11
138
|
*/
|
|
12
139
|
export declare class OasVoid {
|
|
13
140
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Void.d.ts","sourceRoot":"","sources":["../../../src/oas/void/Void.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"Void.d.ts","sourceRoot":"","sources":["../../../src/oas/void/Void.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8HG;AACH,qBAAa,OAAO;IAClB;;;OAGG;IACH,OAAO,EAAG,QAAQ,CAAS;IAC3B;;OAEG;IACH,IAAI,EAAG,MAAM,CAAS;IACtB;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;gBAEnB,MAAM,GAAE,UAAe;IAKnC,MAAM,CAAC,KAAK,IAAI,OAAO;IAIvB,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,OAAO;IAIlB,WAAW,IAAI,OAAO;CAGvB"}
|
package/esm/oas/void/Void.js
CHANGED
|
@@ -1,8 +1,130 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Represents a void (empty) schema in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* The `OasVoid` class represents the absence of a value or content, commonly used
|
|
6
|
+
* in scenarios where operations don't return any content (like HTTP 204 No Content
|
|
7
|
+
* responses), optional properties that might not be present, or fallback cases
|
|
8
|
+
* in schema processing where no specific type is defined.
|
|
9
|
+
*
|
|
10
|
+
* This class serves as a type-safe representation of "nothing" in the OpenAPI
|
|
11
|
+
* type system, enabling proper handling of void responses and empty schemas
|
|
12
|
+
* throughout the SKMTC pipeline.
|
|
13
|
+
*
|
|
14
|
+
* ## Key Features
|
|
15
|
+
*
|
|
16
|
+
* - **Empty Content Representation**: Models operations that return no content
|
|
17
|
+
* - **Type Safety**: Provides a concrete type for void/empty scenarios
|
|
18
|
+
* - **Schema Processing**: Handles missing or undefined schema definitions
|
|
19
|
+
* - **Factory Pattern**: Convenient `empty()` static method for common usage
|
|
20
|
+
* - **Pipeline Integration**: Works seamlessly with the SKMTC processing pipeline
|
|
21
|
+
*
|
|
22
|
+
* @example Basic void schema for empty responses
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { OasVoid } from '@skmtc/core';
|
|
25
|
+
*
|
|
26
|
+
* const emptyResponse = new OasVoid({
|
|
27
|
+
* title: 'No Content',
|
|
28
|
+
* description: 'Operation completed successfully with no response body'
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Used for HTTP 204 No Content responses
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example Using the empty factory method
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const voidSchema = OasVoid.empty();
|
|
37
|
+
*
|
|
38
|
+
* // Equivalent to new OasVoid({})
|
|
39
|
+
* // Commonly used as a fallback or placeholder
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example In operation responses
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const deleteOperation = new OasOperation({
|
|
45
|
+
* path: '/users/{id}',
|
|
46
|
+
* method: 'delete',
|
|
47
|
+
* responses: {
|
|
48
|
+
* '204': new OasResponse({
|
|
49
|
+
* description: 'User deleted successfully',
|
|
50
|
+
* content: {
|
|
51
|
+
* // No content for successful deletion
|
|
52
|
+
* }
|
|
53
|
+
* }),
|
|
54
|
+
* '404': new OasResponse({
|
|
55
|
+
* description: 'User not found'
|
|
56
|
+
* })
|
|
57
|
+
* }
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* // The void response indicates successful deletion with no return value
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example As a schema fallback
|
|
64
|
+
* ```typescript
|
|
65
|
+
* function processSchema(schema: OasSchema | undefined): OasSchema {
|
|
66
|
+
* if (!schema) {
|
|
67
|
+
* return OasVoid.empty(); // Fallback for missing schemas
|
|
68
|
+
* }
|
|
69
|
+
* return schema;
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* // Ensures type safety even when schemas are missing
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example In optional object properties
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const userProfile = new OasObject({
|
|
78
|
+
* properties: {
|
|
79
|
+
* name: new OasString({ description: 'User name' }),
|
|
80
|
+
* avatar: new OasString({
|
|
81
|
+
* description: 'Avatar URL',
|
|
82
|
+
* nullable: true
|
|
83
|
+
* }),
|
|
84
|
+
* // Some properties might be processed as void if not defined
|
|
85
|
+
* metadata: processOptionalSchema(rawSchema.metadata) // might return OasVoid
|
|
86
|
+
* }
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @example HTTP operations with void responses
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Common HTTP operations that return void/empty content:
|
|
93
|
+
*
|
|
94
|
+
* // DELETE - Resource removal
|
|
95
|
+
* const deleteResponse = new OasVoid({
|
|
96
|
+
* title: 'Deletion Successful',
|
|
97
|
+
* description: 'Resource was successfully deleted'
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // PUT - Update with no response body
|
|
101
|
+
* const updateResponse = new OasVoid({
|
|
102
|
+
* title: 'Update Successful',
|
|
103
|
+
* description: 'Resource was successfully updated'
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // POST - Action with no return value
|
|
107
|
+
* const actionResponse = new OasVoid({
|
|
108
|
+
* title: 'Action Completed',
|
|
109
|
+
* description: 'Action was successfully performed'
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @example In code generation
|
|
114
|
+
* ```typescript
|
|
115
|
+
* class TypeScriptGenerator extends ModelBase {
|
|
116
|
+
* generateType(schema: OasSchema): string {
|
|
117
|
+
* if (schema.type === 'void') {
|
|
118
|
+
* return 'void'; // TypeScript void type
|
|
119
|
+
* }
|
|
120
|
+
* // Handle other types...
|
|
121
|
+
* return 'unknown';
|
|
122
|
+
* }
|
|
123
|
+
* }
|
|
124
|
+
*
|
|
125
|
+
* // Generates:
|
|
126
|
+
* // async function deleteUser(id: string): Promise<void>
|
|
127
|
+
* ```
|
|
6
128
|
*/
|
|
7
129
|
export class OasVoid {
|
|
8
130
|
constructor(fields = {}) {
|
package/package.json
CHANGED
|
@@ -2,23 +2,201 @@ import "../../_dnt.polyfills.js";
|
|
|
2
2
|
import type { OasRef } from '../ref/Ref.js';
|
|
3
3
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
4
4
|
import type { ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
5
|
+
/**
|
|
6
|
+
* Constructor fields for {@link OasNumber}.
|
|
7
|
+
*
|
|
8
|
+
* @template Nullable - Whether the number can be null (affects type unions)
|
|
9
|
+
*/
|
|
5
10
|
export type NumberFields<Nullable extends boolean | undefined> = {
|
|
11
|
+
/** A short summary of the number schema */
|
|
6
12
|
title?: string;
|
|
13
|
+
/** A description of the number schema */
|
|
7
14
|
description?: string;
|
|
15
|
+
/** Whether the number value can be null */
|
|
8
16
|
nullable?: Nullable;
|
|
17
|
+
/** Default value for the number (null allowed if Nullable is true) */
|
|
9
18
|
default?: Nullable extends true ? number | null | undefined : number | undefined;
|
|
19
|
+
/** Custom extension fields (x-* properties) */
|
|
10
20
|
extensionFields?: Record<string, unknown>;
|
|
21
|
+
/** Example value for the number (null allowed if Nullable is true) */
|
|
11
22
|
example?: Nullable extends true ? number | null | undefined : number | undefined;
|
|
23
|
+
/** Array of valid enum values for the number (null allowed if Nullable is true) */
|
|
12
24
|
enums?: Nullable extends true ? (number | null)[] | undefined : number[] | undefined;
|
|
25
|
+
/** The format of the number (float or double precision) */
|
|
13
26
|
format?: 'float' | 'double';
|
|
27
|
+
/** Value must be a multiple of this number */
|
|
14
28
|
multipleOf?: number;
|
|
29
|
+
/** Maximum value allowed (inclusive by default) */
|
|
15
30
|
maximum?: number;
|
|
31
|
+
/** Whether the maximum value is exclusive */
|
|
16
32
|
exclusiveMaximum?: boolean;
|
|
33
|
+
/** Minimum value allowed (inclusive by default) */
|
|
17
34
|
minimum?: number;
|
|
35
|
+
/** Whether the minimum value is exclusive */
|
|
18
36
|
exclusiveMinimum?: boolean;
|
|
19
37
|
};
|
|
20
38
|
/**
|
|
21
|
-
*
|
|
39
|
+
* Represents a number schema in the OpenAPI Specification.
|
|
40
|
+
*
|
|
41
|
+
* The `OasNumber` class handles floating-point numeric data types in OpenAPI schemas,
|
|
42
|
+
* supporting comprehensive validation constraints including ranges, precision formats,
|
|
43
|
+
* and mathematical constraints. This class provides type-safe number handling with
|
|
44
|
+
* optional null value support and extensive validation capabilities.
|
|
45
|
+
*
|
|
46
|
+
* ## Key Features
|
|
47
|
+
*
|
|
48
|
+
* - **Range Validation**: Minimum and maximum constraints with exclusive/inclusive options
|
|
49
|
+
* - **Precision Control**: Float and double format support for different precision needs
|
|
50
|
+
* - **Mathematical Constraints**: Multiple-of validation for specific numeric patterns
|
|
51
|
+
* - **Type Safety**: Generic nullable type support with proper TypeScript inference
|
|
52
|
+
* - **Enum Support**: Constrain numbers to specific allowed values
|
|
53
|
+
* - **Null Handling**: Optional null value support for nullable number types
|
|
54
|
+
*
|
|
55
|
+
* @template Nullable - Whether the number value itself can be null
|
|
56
|
+
*
|
|
57
|
+
* @example Basic number schema with range
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { OasNumber } from '@skmtc/core';
|
|
60
|
+
*
|
|
61
|
+
* const ageSchema = new OasNumber({
|
|
62
|
+
* title: 'Age',
|
|
63
|
+
* description: 'Person age in years',
|
|
64
|
+
* minimum: 0,
|
|
65
|
+
* maximum: 150,
|
|
66
|
+
* example: 25,
|
|
67
|
+
* default: 18
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // This represents: number (0 <= value <= 150)
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example Price with precision and constraints
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const priceSchema = new OasNumber({
|
|
76
|
+
* title: 'Product Price',
|
|
77
|
+
* description: 'Price in USD with cent precision',
|
|
78
|
+
* format: 'double',
|
|
79
|
+
* minimum: 0,
|
|
80
|
+
* exclusiveMinimum: true, // Must be > 0, not >= 0
|
|
81
|
+
* multipleOf: 0.01, // Must be in cents (e.g., 19.99, 10.50)
|
|
82
|
+
* example: 29.99
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // This represents: number > 0, in multiples of 0.01
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Percentage with strict bounds
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const percentageSchema = new OasNumber({
|
|
91
|
+
* title: 'Completion Percentage',
|
|
92
|
+
* description: 'Task completion as a percentage',
|
|
93
|
+
* minimum: 0,
|
|
94
|
+
* maximum: 100,
|
|
95
|
+
* multipleOf: 0.1, // One decimal place precision
|
|
96
|
+
* example: 75.5,
|
|
97
|
+
* default: 0
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // This represents: 0 <= value <= 100, in increments of 0.1
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example Nullable rating system
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const ratingSchema = new OasNumber<true>({
|
|
106
|
+
* title: 'User Rating',
|
|
107
|
+
* description: 'Product rating from 1-5 stars, null if not rated',
|
|
108
|
+
* nullable: true,
|
|
109
|
+
* minimum: 1,
|
|
110
|
+
* maximum: 5,
|
|
111
|
+
* multipleOf: 0.5, // Allow half-star ratings
|
|
112
|
+
* enums: [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, null],
|
|
113
|
+
* example: 4.5,
|
|
114
|
+
* default: null
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* // This represents: (1 | 1.5 | 2 | 2.5 | 3 | 3.5 | 4 | 4.5 | 5) | null
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @example Scientific measurement with high precision
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const temperatureSchema = new OasNumber({
|
|
123
|
+
* title: 'Temperature',
|
|
124
|
+
* description: 'Temperature in Celsius with high precision',
|
|
125
|
+
* format: 'double',
|
|
126
|
+
* minimum: -273.15, // Absolute zero
|
|
127
|
+
* maximum: 1000,
|
|
128
|
+
* multipleOf: 0.001, // Millikelvin precision
|
|
129
|
+
* example: 23.456
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* // For scientific applications requiring high precision
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @example Currency with regional constraints
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const currencySchema = new OasNumber({
|
|
138
|
+
* title: 'Amount',
|
|
139
|
+
* description: 'Transaction amount in major currency units',
|
|
140
|
+
* format: 'double',
|
|
141
|
+
* minimum: 0,
|
|
142
|
+
* maximum: 999999.99,
|
|
143
|
+
* multipleOf: 0.01,
|
|
144
|
+
* example: 1234.56
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* // Used in financial applications
|
|
148
|
+
* const transaction = new OasObject({
|
|
149
|
+
* properties: {
|
|
150
|
+
* amount: currencySchema,
|
|
151
|
+
* currency: new OasString({ enum: ['USD', 'EUR', 'GBP'] })
|
|
152
|
+
* }
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @example Coordinate system
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const latitudeSchema = new OasNumber({
|
|
159
|
+
* title: 'Latitude',
|
|
160
|
+
* description: 'Geographic latitude coordinate',
|
|
161
|
+
* format: 'double',
|
|
162
|
+
* minimum: -90,
|
|
163
|
+
* maximum: 90,
|
|
164
|
+
* example: 40.7128
|
|
165
|
+
* });
|
|
166
|
+
*
|
|
167
|
+
* const longitudeSchema = new OasNumber({
|
|
168
|
+
* title: 'Longitude',
|
|
169
|
+
* description: 'Geographic longitude coordinate',
|
|
170
|
+
* format: 'double',
|
|
171
|
+
* minimum: -180,
|
|
172
|
+
* maximum: 180,
|
|
173
|
+
* example: -74.0060
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* // Used for location data
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @example Probability and statistics
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const probabilitySchema = new OasNumber({
|
|
182
|
+
* title: 'Probability',
|
|
183
|
+
* description: 'Statistical probability value',
|
|
184
|
+
* minimum: 0,
|
|
185
|
+
* maximum: 1,
|
|
186
|
+
* exclusiveMaximum: false, // Can be exactly 1
|
|
187
|
+
* example: 0.75,
|
|
188
|
+
* default: 0.5
|
|
189
|
+
* });
|
|
190
|
+
*
|
|
191
|
+
* const confidenceSchema = new OasNumber({
|
|
192
|
+
* title: 'Confidence Level',
|
|
193
|
+
* description: 'Statistical confidence level as percentage',
|
|
194
|
+
* minimum: 0,
|
|
195
|
+
* maximum: 100,
|
|
196
|
+
* enums: [90, 95, 99], // Common confidence levels
|
|
197
|
+
* example: 95
|
|
198
|
+
* });
|
|
199
|
+
* ```
|
|
22
200
|
*/
|
|
23
201
|
export declare class OasNumber<Nullable extends boolean | undefined = boolean | undefined> {
|
|
24
202
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Number.d.ts","sourceRoot":"","sources":["../../../src/oas/number/Number.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"Number.d.ts","sourceRoot":"","sources":["../../../src/oas/number/Number.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAE9D;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,QAAQ,SAAS,OAAO,GAAG,SAAS,IAAI;IAC/D,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,sEAAsE;IACtE,OAAO,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAChF,+CAA+C;IAC/C,e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