@skmtc/core 0.0.789 → 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/context/RenderContext.d.ts +190 -0
- package/esm/context/RenderContext.d.ts.map +1 -1
- package/esm/context/RenderContext.js +179 -0
- package/esm/oas/boolean/Boolean.d.ts +142 -1
- package/esm/oas/boolean/Boolean.d.ts.map +1 -1
- package/esm/oas/boolean/Boolean.js +130 -1
- 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/parameter/Parameter.d.ts +160 -0
- package/esm/oas/parameter/Parameter.d.ts.map +1 -1
- package/esm/oas/parameter/Parameter.js +144 -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/context/RenderContext.d.ts +190 -0
- package/script/context/RenderContext.d.ts.map +1 -1
- package/script/context/RenderContext.js +179 -0
- package/script/oas/boolean/Boolean.d.ts +142 -1
- package/script/oas/boolean/Boolean.d.ts.map +1 -1
- package/script/oas/boolean/Boolean.js +130 -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/parameter/Parameter.d.ts +160 -0
- package/script/oas/parameter/Parameter.d.ts.map +1 -1
- package/script/oas/parameter/Parameter.js +144 -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
|
@@ -1,6 +1,135 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Represents a boolean schema in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* The `OasBoolean` class handles boolean data types in OpenAPI schemas, supporting
|
|
6
|
+
* both simple true/false values and more complex boolean schemas with constraints,
|
|
7
|
+
* enumerations, and nullable types. This class provides type-safe boolean handling
|
|
8
|
+
* with optional null value support through generic typing.
|
|
9
|
+
*
|
|
10
|
+
* ## Key Features
|
|
11
|
+
*
|
|
12
|
+
* - **Type Safety**: Generic nullable type support with proper TypeScript inference
|
|
13
|
+
* - **Enum Support**: Constrain boolean values to specific true/false combinations
|
|
14
|
+
* - **Null Handling**: Optional null value support for nullable boolean types
|
|
15
|
+
* - **Validation**: Default values and example validation
|
|
16
|
+
* - **JSON Schema**: Converts to standard JSON Schema format for validation
|
|
17
|
+
* - **Documentation**: Rich metadata support for API documentation
|
|
18
|
+
*
|
|
19
|
+
* @template Nullable - Whether the boolean value itself can be null
|
|
20
|
+
*
|
|
21
|
+
* @example Basic boolean schema
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { OasBoolean } from '@skmtc/core';
|
|
24
|
+
*
|
|
25
|
+
* const isActiveSchema = new OasBoolean({
|
|
26
|
+
* title: 'Active Status',
|
|
27
|
+
* description: 'Whether the user account is active',
|
|
28
|
+
* default: true,
|
|
29
|
+
* example: true
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // This represents: boolean with default true
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Nullable boolean schema
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const nullableFlag = new OasBoolean<true>({
|
|
38
|
+
* title: 'Optional Flag',
|
|
39
|
+
* description: 'An optional boolean flag that can be null',
|
|
40
|
+
* nullable: true,
|
|
41
|
+
* default: null,
|
|
42
|
+
* example: true
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // This represents: boolean | null
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Boolean with enum constraints
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const strictBoolean = new OasBoolean({
|
|
51
|
+
* title: 'Confirmation',
|
|
52
|
+
* description: 'Must explicitly be true to confirm action',
|
|
53
|
+
* enums: [true], // Only true is allowed
|
|
54
|
+
* example: true
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // This only accepts true, effectively making it required
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example Boolean with null in enum
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const triStateBoolean = new OasBoolean<true>({
|
|
63
|
+
* title: 'Approval Status',
|
|
64
|
+
* description: 'Approval can be true (approved), false (denied), or null (pending)',
|
|
65
|
+
* nullable: true,
|
|
66
|
+
* enums: [true, false, null],
|
|
67
|
+
* default: null,
|
|
68
|
+
* example: null
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* // This represents: true | false | null (tri-state logic)
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example Feature flag schema
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const featureFlag = new OasBoolean({
|
|
77
|
+
* title: 'Feature Enabled',
|
|
78
|
+
* description: 'Whether the new feature is enabled for this user',
|
|
79
|
+
* default: false,
|
|
80
|
+
* example: false
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // Used in configuration objects
|
|
84
|
+
* const userConfig = new OasObject({
|
|
85
|
+
* properties: {
|
|
86
|
+
* darkMode: featureFlag,
|
|
87
|
+
* notifications: featureFlag,
|
|
88
|
+
* betaFeatures: featureFlag
|
|
89
|
+
* }
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example Consent and agreement booleans
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const consentSchema = new OasBoolean({
|
|
96
|
+
* title: 'Terms Accepted',
|
|
97
|
+
* description: 'User has accepted the terms and conditions',
|
|
98
|
+
* enums: [true], // Must be true to be valid
|
|
99
|
+
* example: true
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* const privacyConsent = new OasBoolean({
|
|
103
|
+
* title: 'Privacy Policy Accepted',
|
|
104
|
+
* description: 'User has accepted the privacy policy',
|
|
105
|
+
* default: false,
|
|
106
|
+
* example: true
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* // Used in registration forms where consent is required
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @example Optional settings with nullable booleans
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const userPreferences = new OasObject({
|
|
115
|
+
* properties: {
|
|
116
|
+
* emailNotifications: new OasBoolean<true>({
|
|
117
|
+
* title: 'Email Notifications',
|
|
118
|
+
* description: 'Enable email notifications (null means use default)',
|
|
119
|
+
* nullable: true,
|
|
120
|
+
* default: null
|
|
121
|
+
* }),
|
|
122
|
+
* smsNotifications: new OasBoolean<true>({
|
|
123
|
+
* title: 'SMS Notifications',
|
|
124
|
+
* description: 'Enable SMS notifications (null means not set)',
|
|
125
|
+
* nullable: true,
|
|
126
|
+
* default: null
|
|
127
|
+
* })
|
|
128
|
+
* }
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* // Allows: { emailNotifications: true, smsNotifications: null }
|
|
132
|
+
* ```
|
|
4
133
|
*/
|
|
5
134
|
export class OasBoolean {
|
|
6
135
|
constructor(fields = {}) {
|
|
@@ -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,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,sEAAsE;IACtE,OAAO,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAChF,mFAAmF;IACnF,KAAK,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;IACpF,2DAA2D;IAC3D,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAA;IAC3B,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkKG;AACH,qBAAa,SAAS,CAAC,QAAQ,SAAS,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS;IAC/E;;;OAGG;IACH,OAAO,EAAG,QAAQ,CAAS;IAC3B;;OAEG;IACH,IAAI,EAAG,QAAQ,CAAS;IACxB;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB;;OAEG;IACH,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/E;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B;;OAEG;IACH,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC9B,qCAAqC;IACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IACpD;;OAEG;IACH,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/E;;OAEG;IACH,KAAK,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;IACnF;;OAEG;IACH,MAAM,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;IACtC;;OAEG;IACH,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B;;OAEG;IACH,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAA;IACrC;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B;;OAEG;IACH,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAA;gBACzB,MAAM,GAAE,YAAY,CAAC,QAAQ,CAAM;IAgB/C,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC;IAI9B,WAAW,IAAI,SAAS,CAAC,QAAQ,CAAC;IAKlC,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC,oBAAoB;CAgB5E"}
|
package/esm/oas/number/Number.js
CHANGED
|
@@ -1,6 +1,166 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Represents a number schema in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* The `OasNumber` class handles floating-point numeric data types in OpenAPI schemas,
|
|
6
|
+
* supporting comprehensive validation constraints including ranges, precision formats,
|
|
7
|
+
* and mathematical constraints. This class provides type-safe number handling with
|
|
8
|
+
* optional null value support and extensive validation capabilities.
|
|
9
|
+
*
|
|
10
|
+
* ## Key Features
|
|
11
|
+
*
|
|
12
|
+
* - **Range Validation**: Minimum and maximum constraints with exclusive/inclusive options
|
|
13
|
+
* - **Precision Control**: Float and double format support for different precision needs
|
|
14
|
+
* - **Mathematical Constraints**: Multiple-of validation for specific numeric patterns
|
|
15
|
+
* - **Type Safety**: Generic nullable type support with proper TypeScript inference
|
|
16
|
+
* - **Enum Support**: Constrain numbers to specific allowed values
|
|
17
|
+
* - **Null Handling**: Optional null value support for nullable number types
|
|
18
|
+
*
|
|
19
|
+
* @template Nullable - Whether the number value itself can be null
|
|
20
|
+
*
|
|
21
|
+
* @example Basic number schema with range
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { OasNumber } from '@skmtc/core';
|
|
24
|
+
*
|
|
25
|
+
* const ageSchema = new OasNumber({
|
|
26
|
+
* title: 'Age',
|
|
27
|
+
* description: 'Person age in years',
|
|
28
|
+
* minimum: 0,
|
|
29
|
+
* maximum: 150,
|
|
30
|
+
* example: 25,
|
|
31
|
+
* default: 18
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // This represents: number (0 <= value <= 150)
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example Price with precision and constraints
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const priceSchema = new OasNumber({
|
|
40
|
+
* title: 'Product Price',
|
|
41
|
+
* description: 'Price in USD with cent precision',
|
|
42
|
+
* format: 'double',
|
|
43
|
+
* minimum: 0,
|
|
44
|
+
* exclusiveMinimum: true, // Must be > 0, not >= 0
|
|
45
|
+
* multipleOf: 0.01, // Must be in cents (e.g., 19.99, 10.50)
|
|
46
|
+
* example: 29.99
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // This represents: number > 0, in multiples of 0.01
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Percentage with strict bounds
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const percentageSchema = new OasNumber({
|
|
55
|
+
* title: 'Completion Percentage',
|
|
56
|
+
* description: 'Task completion as a percentage',
|
|
57
|
+
* minimum: 0,
|
|
58
|
+
* maximum: 100,
|
|
59
|
+
* multipleOf: 0.1, // One decimal place precision
|
|
60
|
+
* example: 75.5,
|
|
61
|
+
* default: 0
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // This represents: 0 <= value <= 100, in increments of 0.1
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example Nullable rating system
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const ratingSchema = new OasNumber<true>({
|
|
70
|
+
* title: 'User Rating',
|
|
71
|
+
* description: 'Product rating from 1-5 stars, null if not rated',
|
|
72
|
+
* nullable: true,
|
|
73
|
+
* minimum: 1,
|
|
74
|
+
* maximum: 5,
|
|
75
|
+
* multipleOf: 0.5, // Allow half-star ratings
|
|
76
|
+
* enums: [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, null],
|
|
77
|
+
* example: 4.5,
|
|
78
|
+
* default: null
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* // This represents: (1 | 1.5 | 2 | 2.5 | 3 | 3.5 | 4 | 4.5 | 5) | null
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @example Scientific measurement with high precision
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const temperatureSchema = new OasNumber({
|
|
87
|
+
* title: 'Temperature',
|
|
88
|
+
* description: 'Temperature in Celsius with high precision',
|
|
89
|
+
* format: 'double',
|
|
90
|
+
* minimum: -273.15, // Absolute zero
|
|
91
|
+
* maximum: 1000,
|
|
92
|
+
* multipleOf: 0.001, // Millikelvin precision
|
|
93
|
+
* example: 23.456
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* // For scientific applications requiring high precision
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example Currency with regional constraints
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const currencySchema = new OasNumber({
|
|
102
|
+
* title: 'Amount',
|
|
103
|
+
* description: 'Transaction amount in major currency units',
|
|
104
|
+
* format: 'double',
|
|
105
|
+
* minimum: 0,
|
|
106
|
+
* maximum: 999999.99,
|
|
107
|
+
* multipleOf: 0.01,
|
|
108
|
+
* example: 1234.56
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* // Used in financial applications
|
|
112
|
+
* const transaction = new OasObject({
|
|
113
|
+
* properties: {
|
|
114
|
+
* amount: currencySchema,
|
|
115
|
+
* currency: new OasString({ enum: ['USD', 'EUR', 'GBP'] })
|
|
116
|
+
* }
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @example Coordinate system
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const latitudeSchema = new OasNumber({
|
|
123
|
+
* title: 'Latitude',
|
|
124
|
+
* description: 'Geographic latitude coordinate',
|
|
125
|
+
* format: 'double',
|
|
126
|
+
* minimum: -90,
|
|
127
|
+
* maximum: 90,
|
|
128
|
+
* example: 40.7128
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* const longitudeSchema = new OasNumber({
|
|
132
|
+
* title: 'Longitude',
|
|
133
|
+
* description: 'Geographic longitude coordinate',
|
|
134
|
+
* format: 'double',
|
|
135
|
+
* minimum: -180,
|
|
136
|
+
* maximum: 180,
|
|
137
|
+
* example: -74.0060
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* // Used for location data
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @example Probability and statistics
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const probabilitySchema = new OasNumber({
|
|
146
|
+
* title: 'Probability',
|
|
147
|
+
* description: 'Statistical probability value',
|
|
148
|
+
* minimum: 0,
|
|
149
|
+
* maximum: 1,
|
|
150
|
+
* exclusiveMaximum: false, // Can be exactly 1
|
|
151
|
+
* example: 0.75,
|
|
152
|
+
* default: 0.5
|
|
153
|
+
* });
|
|
154
|
+
*
|
|
155
|
+
* const confidenceSchema = new OasNumber({
|
|
156
|
+
* title: 'Confidence Level',
|
|
157
|
+
* description: 'Statistical confidence level as percentage',
|
|
158
|
+
* minimum: 0,
|
|
159
|
+
* maximum: 100,
|
|
160
|
+
* enums: [90, 95, 99], // Common confidence levels
|
|
161
|
+
* example: 95
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
4
164
|
*/
|
|
5
165
|
export class OasNumber {
|
|
6
166
|
constructor(fields = {}) {
|
|
@@ -6,21 +6,181 @@ import type { OasExample } from '../example/Example.js';
|
|
|
6
6
|
import type { OasSchema } from '../schema/Schema.js';
|
|
7
7
|
import type { ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
8
8
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
9
|
+
/**
|
|
10
|
+
* Constructor fields for {@link OasParameter}.
|
|
11
|
+
*/
|
|
9
12
|
export type ParameterFields = {
|
|
13
|
+
/** The name of the parameter */
|
|
10
14
|
name: string;
|
|
15
|
+
/** The location of the parameter (path, query, header, cookie) */
|
|
11
16
|
location: OasParameterLocation;
|
|
17
|
+
/** A brief description of the parameter */
|
|
12
18
|
description?: string | undefined;
|
|
19
|
+
/** Determines whether this parameter is mandatory */
|
|
13
20
|
required?: boolean | undefined;
|
|
21
|
+
/** Specifies that the parameter is deprecated */
|
|
14
22
|
deprecated?: boolean | undefined;
|
|
23
|
+
/** Whether to allow empty values for the parameter */
|
|
15
24
|
allowEmptyValue?: boolean | undefined;
|
|
25
|
+
/** Whether reserved characters are allowed in the parameter value */
|
|
16
26
|
allowReserved?: boolean | undefined;
|
|
27
|
+
/** The schema defining the parameter's data type */
|
|
17
28
|
schema?: OasSchema | OasRef<'schema'> | undefined;
|
|
29
|
+
/** Example values for the parameter */
|
|
18
30
|
examples?: Record<string, OasExample | OasRef<'example'>> | undefined;
|
|
31
|
+
/** Media type definitions for the parameter content */
|
|
19
32
|
content?: Record<string, OasMediaType> | undefined;
|
|
33
|
+
/** The serialization style for the parameter */
|
|
20
34
|
style: OasParameterStyle;
|
|
35
|
+
/** Whether to explode parameter values */
|
|
21
36
|
explode: boolean;
|
|
37
|
+
/** Custom extension fields (x-* properties) */
|
|
22
38
|
extensionFields?: Record<string, unknown>;
|
|
23
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Represents a Parameter Object in the OpenAPI Specification.
|
|
42
|
+
*
|
|
43
|
+
* The `OasParameter` class encapsulates the definition of a single operation parameter,
|
|
44
|
+
* including its location, data type, validation rules, and serialization behavior.
|
|
45
|
+
* Parameters can be located in the path, query string, headers, or cookies.
|
|
46
|
+
*
|
|
47
|
+
* This class provides comprehensive support for parameter validation, serialization
|
|
48
|
+
* styles, and complex data types through schema definitions or content specifications.
|
|
49
|
+
*
|
|
50
|
+
* ## Key Features
|
|
51
|
+
*
|
|
52
|
+
* - **Location Support**: Path, query, header, and cookie parameters
|
|
53
|
+
* - **Schema Validation**: Comprehensive data type validation through schemas
|
|
54
|
+
* - **Serialization Styles**: Various parameter serialization formats
|
|
55
|
+
* - **Content Types**: Support for complex parameter content with media types
|
|
56
|
+
* - **Examples & Documentation**: Parameter examples and descriptive documentation
|
|
57
|
+
* - **Advanced Options**: Empty values, reserved characters, and explode behavior
|
|
58
|
+
*
|
|
59
|
+
* @example Basic path parameter
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { OasParameter, OasString } from '@skmtc/core';
|
|
62
|
+
*
|
|
63
|
+
* const userIdParam = new OasParameter({
|
|
64
|
+
* name: 'userId',
|
|
65
|
+
* location: 'path',
|
|
66
|
+
* description: 'Unique identifier for the user',
|
|
67
|
+
* required: true,
|
|
68
|
+
* schema: new OasString({
|
|
69
|
+
* pattern: '^[0-9a-f]{24}$',
|
|
70
|
+
* example: '507f1f77bcf86cd799439011'
|
|
71
|
+
* }),
|
|
72
|
+
* style: 'simple',
|
|
73
|
+
* explode: false
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* // Used in path: /users/{userId}
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example Query parameter with validation
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const pageSizeParam = new OasParameter({
|
|
82
|
+
* name: 'pageSize',
|
|
83
|
+
* location: 'query',
|
|
84
|
+
* description: 'Number of items to return per page',
|
|
85
|
+
* required: false,
|
|
86
|
+
* schema: new OasInteger({
|
|
87
|
+
* minimum: 1,
|
|
88
|
+
* maximum: 100,
|
|
89
|
+
* default: 20
|
|
90
|
+
* }),
|
|
91
|
+
* style: 'form',
|
|
92
|
+
* explode: true,
|
|
93
|
+
* examples: {
|
|
94
|
+
* small: new OasExample({ value: 10 }),
|
|
95
|
+
* medium: new OasExample({ value: 25 }),
|
|
96
|
+
* large: new OasExample({ value: 50 })
|
|
97
|
+
* }
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // Used in query: ?pageSize=20
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example Header parameter
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const authHeaderParam = new OasParameter({
|
|
106
|
+
* name: 'Authorization',
|
|
107
|
+
* location: 'header',
|
|
108
|
+
* description: 'Bearer token for authentication',
|
|
109
|
+
* required: true,
|
|
110
|
+
* schema: new OasString({
|
|
111
|
+
* pattern: '^Bearer [A-Za-z0-9+/=]+$',
|
|
112
|
+
* example: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
113
|
+
* }),
|
|
114
|
+
* style: 'simple',
|
|
115
|
+
* explode: false
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Complex parameter with content
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const filterParam = new OasParameter({
|
|
122
|
+
* name: 'filter',
|
|
123
|
+
* location: 'query',
|
|
124
|
+
* description: 'Complex filter object',
|
|
125
|
+
* required: false,
|
|
126
|
+
* content: {
|
|
127
|
+
* 'application/json': new OasMediaType({
|
|
128
|
+
* schema: new OasObject({
|
|
129
|
+
* properties: {
|
|
130
|
+
* category: new OasString(),
|
|
131
|
+
* priceRange: new OasObject({
|
|
132
|
+
* properties: {
|
|
133
|
+
* min: new OasNumber(),
|
|
134
|
+
* max: new OasNumber()
|
|
135
|
+
* }
|
|
136
|
+
* })
|
|
137
|
+
* }
|
|
138
|
+
* })
|
|
139
|
+
* })
|
|
140
|
+
* },
|
|
141
|
+
* style: 'deepObject',
|
|
142
|
+
* explode: true
|
|
143
|
+
* });
|
|
144
|
+
*
|
|
145
|
+
* // Used as: ?filter[category]=electronics&filter[priceRange][min]=100
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @example Array parameter with explode
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const tagsParam = new OasParameter({
|
|
151
|
+
* name: 'tags',
|
|
152
|
+
* location: 'query',
|
|
153
|
+
* description: 'Filter by multiple tags',
|
|
154
|
+
* required: false,
|
|
155
|
+
* schema: new OasArray({
|
|
156
|
+
* items: new OasString(),
|
|
157
|
+
* minItems: 1,
|
|
158
|
+
* maxItems: 10
|
|
159
|
+
* }),
|
|
160
|
+
* style: 'form',
|
|
161
|
+
* explode: true // Results in: ?tags=tech&tags=api&tags=rest
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* // Without explode: ?tags=tech,api,rest
|
|
165
|
+
* // With explode: ?tags=tech&tags=api&tags=rest
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example Cookie parameter
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const sessionParam = new OasParameter({
|
|
171
|
+
* name: 'sessionId',
|
|
172
|
+
* location: 'cookie',
|
|
173
|
+
* description: 'Session identifier cookie',
|
|
174
|
+
* required: false,
|
|
175
|
+
* schema: new OasString({
|
|
176
|
+
* minLength: 32,
|
|
177
|
+
* maxLength: 128
|
|
178
|
+
* }),
|
|
179
|
+
* style: 'form',
|
|
180
|
+
* explode: false
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
24
184
|
export declare class OasParameter {
|
|
25
185
|
oasType: 'parameter';
|
|
26
186
|
name: string;
|