@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.
@@ -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
- * Object representing a number in the OpenAPI Specification.
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;AAC9D,MAAM,MAAM,YAAY,CAAC,QAAQ,SAAS,OAAO,GAAG,SAAS,IAAI;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,OAAO,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAChF,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,OAAO,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAChF,KAAK,CAAC,EAAE,QAAQ,SAA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,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"}
@@ -1,6 +1,166 @@
1
1
  import "../../_dnt.polyfills.js";
2
2
  /**
3
- * Object representing a number in the OpenAPI Specification.
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 = {}) {
@@ -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,G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