@skmtc/core 0.0.786 → 0.0.788
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/GenerateContext.d.ts +95 -0
- package/esm/context/GenerateContext.d.ts.map +1 -1
- package/esm/context/GenerateContext.js +95 -0
- package/esm/dsl/ContentSettings.d.ts +164 -0
- package/esm/dsl/ContentSettings.d.ts.map +1 -1
- package/esm/dsl/ContentSettings.js +151 -0
- package/esm/dsl/Definition.d.ts +199 -0
- package/esm/dsl/Definition.d.ts.map +1 -1
- package/esm/dsl/Definition.js +189 -0
- package/esm/dsl/EntityType.d.ts +83 -0
- package/esm/dsl/EntityType.d.ts.map +1 -1
- package/esm/dsl/EntityType.js +83 -0
- package/esm/dsl/JsonFile.d.ts +162 -0
- package/esm/dsl/JsonFile.d.ts.map +1 -1
- package/esm/dsl/JsonFile.js +157 -0
- package/esm/oas/array/Array.d.ts +109 -1
- package/esm/oas/array/Array.d.ts.map +1 -1
- package/esm/oas/array/Array.js +93 -1
- package/esm/oas/integer/Integer.d.ts +98 -0
- package/esm/oas/integer/Integer.d.ts.map +1 -1
- package/esm/oas/integer/Integer.js +80 -0
- package/esm/oas/operation/Operation.d.ts +107 -1
- package/esm/oas/operation/Operation.d.ts.map +1 -1
- package/esm/oas/operation/Operation.js +107 -1
- package/esm/oas/ref/Ref.d.ts +86 -0
- package/esm/oas/ref/Ref.d.ts.map +1 -1
- package/esm/oas/ref/Ref.js +86 -0
- package/esm/oas/string/String.d.ts +103 -1
- package/esm/oas/string/String.d.ts.map +1 -1
- package/esm/oas/string/String.js +87 -1
- package/esm/types/Brand.d.ts +74 -0
- package/esm/types/Brand.d.ts.map +1 -1
- package/esm/types/Brand.js +9 -0
- package/esm/types/RefName.d.ts +61 -0
- package/esm/types/RefName.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/context/GenerateContext.d.ts +95 -0
- package/script/context/GenerateContext.d.ts.map +1 -1
- package/script/context/GenerateContext.js +95 -0
- package/script/dsl/ContentSettings.d.ts +164 -0
- package/script/dsl/ContentSettings.d.ts.map +1 -1
- package/script/dsl/ContentSettings.js +151 -0
- package/script/dsl/Definition.d.ts +199 -0
- package/script/dsl/Definition.d.ts.map +1 -1
- package/script/dsl/Definition.js +189 -0
- package/script/dsl/EntityType.d.ts +83 -0
- package/script/dsl/EntityType.d.ts.map +1 -1
- package/script/dsl/EntityType.js +83 -0
- package/script/dsl/JsonFile.d.ts +162 -0
- package/script/dsl/JsonFile.d.ts.map +1 -1
- package/script/dsl/JsonFile.js +157 -0
- package/script/oas/array/Array.d.ts +109 -1
- package/script/oas/array/Array.d.ts.map +1 -1
- package/script/oas/array/Array.js +93 -1
- package/script/oas/integer/Integer.d.ts +98 -0
- package/script/oas/integer/Integer.d.ts.map +1 -1
- package/script/oas/integer/Integer.js +80 -0
- package/script/oas/operation/Operation.d.ts +107 -1
- package/script/oas/operation/Operation.d.ts.map +1 -1
- package/script/oas/operation/Operation.js +107 -1
- package/script/oas/ref/Ref.d.ts +86 -0
- package/script/oas/ref/Ref.d.ts.map +1 -1
- package/script/oas/ref/Ref.js +86 -0
- package/script/oas/string/String.d.ts +103 -1
- package/script/oas/string/String.d.ts.map +1 -1
- package/script/oas/string/String.js +87 -1
- package/script/types/Brand.d.ts +74 -0
- package/script/types/Brand.d.ts.map +1 -1
- package/script/types/Brand.js +9 -0
- package/script/types/RefName.d.ts +61 -0
- package/script/types/RefName.d.ts.map +1 -1
|
@@ -2,21 +2,119 @@ 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 OasInteger}.
|
|
7
|
+
*
|
|
8
|
+
* @template Nullable - Whether the integer value can be null
|
|
9
|
+
*/
|
|
5
10
|
export type IntegerFields<Nullable extends boolean | undefined> = {
|
|
11
|
+
/** A short summary of the integer schema */
|
|
6
12
|
title?: string;
|
|
13
|
+
/** A description of the integer schema */
|
|
7
14
|
description?: string;
|
|
15
|
+
/** Whether the integer value can be null */
|
|
8
16
|
nullable?: Nullable;
|
|
17
|
+
/** Integer format specification (int32 or int64) */
|
|
9
18
|
format?: 'int32' | 'int64';
|
|
19
|
+
/** Default value for the integer */
|
|
10
20
|
default?: Nullable extends true ? number | null | undefined : number | undefined;
|
|
21
|
+
/** Array of allowed enum values */
|
|
11
22
|
enums?: Nullable extends true ? (number | null)[] | undefined : number[] | undefined;
|
|
23
|
+
/** Custom extension fields (x-* properties) */
|
|
12
24
|
extensionFields?: Record<string, unknown>;
|
|
25
|
+
/** Example value for the integer */
|
|
13
26
|
example?: Nullable extends true ? number | null | undefined : number | undefined;
|
|
27
|
+
/** Number must be a multiple of this value */
|
|
14
28
|
multipleOf?: number;
|
|
29
|
+
/** Maximum value (inclusive) */
|
|
15
30
|
maximum?: number;
|
|
31
|
+
/** Whether maximum is exclusive */
|
|
16
32
|
exclusiveMaximum?: boolean;
|
|
33
|
+
/** Minimum value (inclusive) */
|
|
17
34
|
minimum?: number;
|
|
35
|
+
/** Whether minimum is exclusive */
|
|
18
36
|
exclusiveMinimum?: boolean;
|
|
19
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Represents an integer schema in the OpenAPI Specification.
|
|
40
|
+
*
|
|
41
|
+
* `OasInteger` handles integer type definitions with comprehensive validation
|
|
42
|
+
* constraints including range limits, multiple-of validation, format specifications,
|
|
43
|
+
* and enum restrictions. It supports both 32-bit and 64-bit integer formats
|
|
44
|
+
* and provides nullable type support.
|
|
45
|
+
*
|
|
46
|
+
* This class is used throughout the OAS processing pipeline to represent
|
|
47
|
+
* integer fields in API schemas, including IDs, counts, timestamps, and
|
|
48
|
+
* other numeric values that must be whole numbers.
|
|
49
|
+
*
|
|
50
|
+
* ## Key Features
|
|
51
|
+
*
|
|
52
|
+
* - **Format Support**: int32 and int64 format specifications
|
|
53
|
+
* - **Range Validation**: Minimum and maximum value constraints
|
|
54
|
+
* - **Multiple Validation**: Ensure values are multiples of specified numbers
|
|
55
|
+
* - **Enum Values**: Restricted sets of allowed integer values
|
|
56
|
+
* - **Nullable Support**: Type-safe nullable integer handling
|
|
57
|
+
* - **JSON Schema**: Conversion to standard JSON Schema format
|
|
58
|
+
*
|
|
59
|
+
* @template Nullable - Whether the integer value can be null
|
|
60
|
+
*
|
|
61
|
+
* @example Basic integer schema
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { OasInteger } from '@skmtc/core';
|
|
64
|
+
*
|
|
65
|
+
* const ageInteger = new OasInteger({
|
|
66
|
+
* title: 'Age',
|
|
67
|
+
* description: 'Person age in years',
|
|
68
|
+
* minimum: 0,
|
|
69
|
+
* maximum: 150,
|
|
70
|
+
* example: 25
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example ID with int64 format
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const userIdInteger = new OasInteger({
|
|
77
|
+
* title: 'User ID',
|
|
78
|
+
* description: 'Unique user identifier',
|
|
79
|
+
* format: 'int64',
|
|
80
|
+
* minimum: 1,
|
|
81
|
+
* example: 1234567890123
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example Count with multiple-of validation
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const batchSizeInteger = new OasInteger({
|
|
88
|
+
* title: 'Batch Size',
|
|
89
|
+
* description: 'Number of items to process',
|
|
90
|
+
* minimum: 10,
|
|
91
|
+
* maximum: 1000,
|
|
92
|
+
* multipleOf: 10, // Must be multiple of 10
|
|
93
|
+
* default: 50
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example Status code enum
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const statusCodeInteger = new OasInteger({
|
|
100
|
+
* title: 'HTTP Status Code',
|
|
101
|
+
* description: 'Valid HTTP response status codes',
|
|
102
|
+
* enums: [200, 201, 400, 401, 404, 500],
|
|
103
|
+
* example: 200
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @example Nullable integer
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const optionalCountInteger = new OasInteger<true>({
|
|
110
|
+
* title: 'Optional Count',
|
|
111
|
+
* description: 'Count value that can be null',
|
|
112
|
+
* nullable: true,
|
|
113
|
+
* minimum: 0,
|
|
114
|
+
* default: null
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
20
118
|
export declare class OasInteger<Nullable extends boolean | undefined = boolean | undefined> {
|
|
21
119
|
/**
|
|
22
120
|
* Object is part the 'schema' set which is used
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Integer.d.ts","sourceRoot":"","sources":["../../../src/oas/integer/Integer.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,aAAa,CAAC,QAAQ,SAAS,OAAO,GAAG,SAAS,IAAI;IAChE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;IAC1B,OAAO,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAChF,KAAK,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,GAA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AAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;IACnF,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,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;IACrC;;OAEG;IACH,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;gBACnE,MAAM,GAAE,aAAa,CAAC,QAAQ,CAAM;IAgBhD,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC;IAI/B,WAAW,IAAI,UAAU,CAAC,QAAQ,CAAC;IAKnC,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC,oBAAoB;CAiB5E"}
|
|
@@ -1,4 +1,84 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an integer schema in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* `OasInteger` handles integer type definitions with comprehensive validation
|
|
6
|
+
* constraints including range limits, multiple-of validation, format specifications,
|
|
7
|
+
* and enum restrictions. It supports both 32-bit and 64-bit integer formats
|
|
8
|
+
* and provides nullable type support.
|
|
9
|
+
*
|
|
10
|
+
* This class is used throughout the OAS processing pipeline to represent
|
|
11
|
+
* integer fields in API schemas, including IDs, counts, timestamps, and
|
|
12
|
+
* other numeric values that must be whole numbers.
|
|
13
|
+
*
|
|
14
|
+
* ## Key Features
|
|
15
|
+
*
|
|
16
|
+
* - **Format Support**: int32 and int64 format specifications
|
|
17
|
+
* - **Range Validation**: Minimum and maximum value constraints
|
|
18
|
+
* - **Multiple Validation**: Ensure values are multiples of specified numbers
|
|
19
|
+
* - **Enum Values**: Restricted sets of allowed integer values
|
|
20
|
+
* - **Nullable Support**: Type-safe nullable integer handling
|
|
21
|
+
* - **JSON Schema**: Conversion to standard JSON Schema format
|
|
22
|
+
*
|
|
23
|
+
* @template Nullable - Whether the integer value can be null
|
|
24
|
+
*
|
|
25
|
+
* @example Basic integer schema
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { OasInteger } from '@skmtc/core';
|
|
28
|
+
*
|
|
29
|
+
* const ageInteger = new OasInteger({
|
|
30
|
+
* title: 'Age',
|
|
31
|
+
* description: 'Person age in years',
|
|
32
|
+
* minimum: 0,
|
|
33
|
+
* maximum: 150,
|
|
34
|
+
* example: 25
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example ID with int64 format
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const userIdInteger = new OasInteger({
|
|
41
|
+
* title: 'User ID',
|
|
42
|
+
* description: 'Unique user identifier',
|
|
43
|
+
* format: 'int64',
|
|
44
|
+
* minimum: 1,
|
|
45
|
+
* example: 1234567890123
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Count with multiple-of validation
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const batchSizeInteger = new OasInteger({
|
|
52
|
+
* title: 'Batch Size',
|
|
53
|
+
* description: 'Number of items to process',
|
|
54
|
+
* minimum: 10,
|
|
55
|
+
* maximum: 1000,
|
|
56
|
+
* multipleOf: 10, // Must be multiple of 10
|
|
57
|
+
* default: 50
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Status code enum
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const statusCodeInteger = new OasInteger({
|
|
64
|
+
* title: 'HTTP Status Code',
|
|
65
|
+
* description: 'Valid HTTP response status codes',
|
|
66
|
+
* enums: [200, 201, 400, 401, 404, 500],
|
|
67
|
+
* example: 200
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example Nullable integer
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const optionalCountInteger = new OasInteger<true>({
|
|
74
|
+
* title: 'Optional Count',
|
|
75
|
+
* description: 'Count value that can be null',
|
|
76
|
+
* nullable: true,
|
|
77
|
+
* minimum: 0,
|
|
78
|
+
* default: null
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
2
82
|
export class OasInteger {
|
|
3
83
|
constructor(fields = {}) {
|
|
4
84
|
/**
|
|
@@ -30,7 +30,113 @@ type ToRequestBodyMapArgs = {
|
|
|
30
30
|
schema: OasSchema | OasRef<'schema'>;
|
|
31
31
|
requestBody: OasRequestBody;
|
|
32
32
|
};
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Represents an OpenAPI Operation Object in the SKMTC OAS processing system.
|
|
35
|
+
*
|
|
36
|
+
* The `OasOperation` class encapsulates a single API operation (path + method combination)
|
|
37
|
+
* with all its associated metadata, parameters, request/response specifications, and
|
|
38
|
+
* security requirements. It provides utilities for extracting common operation data
|
|
39
|
+
* like success responses and request bodies.
|
|
40
|
+
*
|
|
41
|
+
* ## Key Features
|
|
42
|
+
*
|
|
43
|
+
* - **Path and Method**: Unique combination identifying the operation
|
|
44
|
+
* - **Metadata Access**: Operation ID, summary, description, tags, and deprecation status
|
|
45
|
+
* - **Parameter Handling**: Query, path, header, and cookie parameters
|
|
46
|
+
* - **Request/Response Specs**: Type-safe access to request body and response definitions
|
|
47
|
+
* - **Security Context**: Operation-specific security requirements
|
|
48
|
+
* - **Success Response Utils**: Helper methods to identify and extract successful responses
|
|
49
|
+
*
|
|
50
|
+
* @example Basic operation properties
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { OasOperation } from '@skmtc/core';
|
|
53
|
+
*
|
|
54
|
+
* // Typically created during document parsing
|
|
55
|
+
* const getUserOp = new OasOperation({
|
|
56
|
+
* path: '/users/{id}',
|
|
57
|
+
* method: 'get',
|
|
58
|
+
* operationId: 'getUserById',
|
|
59
|
+
* summary: 'Get user by ID',
|
|
60
|
+
* description: 'Retrieves a single user by their unique identifier',
|
|
61
|
+
* parameters: [
|
|
62
|
+
* // Path parameter for user ID
|
|
63
|
+
* { name: 'id', in: 'path', required: true, schema: { type: 'string' } }
|
|
64
|
+
* ],
|
|
65
|
+
* responses: {
|
|
66
|
+
* '200': { description: 'User found', content: { ... } },
|
|
67
|
+
* '404': { description: 'User not found' }
|
|
68
|
+
* }
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* console.log(getUserOp.path); // '/users/{id}'
|
|
72
|
+
* console.log(getUserOp.method); // 'get'
|
|
73
|
+
* console.log(getUserOp.operationId); // 'getUserById'
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example Working with success responses
|
|
77
|
+
* ```typescript
|
|
78
|
+
* // Find the primary success response
|
|
79
|
+
* const successResponse = operation.toSuccessResponse();
|
|
80
|
+
* if (successResponse) {
|
|
81
|
+
* const resolved = successResponse.resolve();
|
|
82
|
+
* console.log('Success response:', resolved.description);
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* // Get the HTTP status code for success
|
|
86
|
+
* const successCode = operation.toSuccessResponseCode();
|
|
87
|
+
* console.log('Success status:', successCode); // '200', '201', 'default', etc.
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @example Extracting request body data
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Extract request body with custom transformation
|
|
93
|
+
* const requestData = operation.toRequestBody(({ schema, requestBody }) => {
|
|
94
|
+
* return {
|
|
95
|
+
* schema: schema,
|
|
96
|
+
* contentType: 'application/json',
|
|
97
|
+
* required: requestBody.required ?? false,
|
|
98
|
+
* description: requestBody.description
|
|
99
|
+
* };
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* if (requestData) {
|
|
103
|
+
* console.log('Request schema:', requestData.schema);
|
|
104
|
+
* console.log('Required:', requestData.required);
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example Parameter processing
|
|
109
|
+
* ```typescript
|
|
110
|
+
* // Process operation parameters by location
|
|
111
|
+
* const pathParams = operation.parameters?.filter(param => {
|
|
112
|
+
* const resolved = param.resolve();
|
|
113
|
+
* return resolved.in === 'path';
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* const queryParams = operation.parameters?.filter(param => {
|
|
117
|
+
* const resolved = param.resolve();
|
|
118
|
+
* return resolved.in === 'query';
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* console.log('Path parameters:', pathParams?.length);
|
|
122
|
+
* console.log('Query parameters:', queryParams?.length);
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @example Security requirements
|
|
126
|
+
* ```typescript
|
|
127
|
+
* if (operation.security) {
|
|
128
|
+
* console.log('Operation has specific security requirements');
|
|
129
|
+
* for (const requirement of operation.security) {
|
|
130
|
+
* // Process security schemes for this operation
|
|
131
|
+
* Object.keys(requirement.schemes).forEach(scheme => {
|
|
132
|
+
* console.log(`Security scheme: ${scheme}`);
|
|
133
|
+
* });
|
|
134
|
+
* }
|
|
135
|
+
* } else {
|
|
136
|
+
* console.log('Operation uses default document security');
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
34
140
|
export declare class OasOperation {
|
|
35
141
|
oasType: 'operation';
|
|
36
142
|
path: string;
|
|
@@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../../_dnt.polyfills.js";
|
|
2
2
|
import { OasObject } from '../object/Object.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Represents an OpenAPI Operation Object in the SKMTC OAS processing system.
|
|
5
|
+
*
|
|
6
|
+
* The `OasOperation` class encapsulates a single API operation (path + method combination)
|
|
7
|
+
* with all its associated metadata, parameters, request/response specifications, and
|
|
8
|
+
* security requirements. It provides utilities for extracting common operation data
|
|
9
|
+
* like success responses and request bodies.
|
|
10
|
+
*
|
|
11
|
+
* ## Key Features
|
|
12
|
+
*
|
|
13
|
+
* - **Path and Method**: Unique combination identifying the operation
|
|
14
|
+
* - **Metadata Access**: Operation ID, summary, description, tags, and deprecation status
|
|
15
|
+
* - **Parameter Handling**: Query, path, header, and cookie parameters
|
|
16
|
+
* - **Request/Response Specs**: Type-safe access to request body and response definitions
|
|
17
|
+
* - **Security Context**: Operation-specific security requirements
|
|
18
|
+
* - **Success Response Utils**: Helper methods to identify and extract successful responses
|
|
19
|
+
*
|
|
20
|
+
* @example Basic operation properties
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { OasOperation } from '@skmtc/core';
|
|
23
|
+
*
|
|
24
|
+
* // Typically created during document parsing
|
|
25
|
+
* const getUserOp = new OasOperation({
|
|
26
|
+
* path: '/users/{id}',
|
|
27
|
+
* method: 'get',
|
|
28
|
+
* operationId: 'getUserById',
|
|
29
|
+
* summary: 'Get user by ID',
|
|
30
|
+
* description: 'Retrieves a single user by their unique identifier',
|
|
31
|
+
* parameters: [
|
|
32
|
+
* // Path parameter for user ID
|
|
33
|
+
* { name: 'id', in: 'path', required: true, schema: { type: 'string' } }
|
|
34
|
+
* ],
|
|
35
|
+
* responses: {
|
|
36
|
+
* '200': { description: 'User found', content: { ... } },
|
|
37
|
+
* '404': { description: 'User not found' }
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* console.log(getUserOp.path); // '/users/{id}'
|
|
42
|
+
* console.log(getUserOp.method); // 'get'
|
|
43
|
+
* console.log(getUserOp.operationId); // 'getUserById'
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example Working with success responses
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Find the primary success response
|
|
49
|
+
* const successResponse = operation.toSuccessResponse();
|
|
50
|
+
* if (successResponse) {
|
|
51
|
+
* const resolved = successResponse.resolve();
|
|
52
|
+
* console.log('Success response:', resolved.description);
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* // Get the HTTP status code for success
|
|
56
|
+
* const successCode = operation.toSuccessResponseCode();
|
|
57
|
+
* console.log('Success status:', successCode); // '200', '201', 'default', etc.
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example Extracting request body data
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Extract request body with custom transformation
|
|
63
|
+
* const requestData = operation.toRequestBody(({ schema, requestBody }) => {
|
|
64
|
+
* return {
|
|
65
|
+
* schema: schema,
|
|
66
|
+
* contentType: 'application/json',
|
|
67
|
+
* required: requestBody.required ?? false,
|
|
68
|
+
* description: requestBody.description
|
|
69
|
+
* };
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* if (requestData) {
|
|
73
|
+
* console.log('Request schema:', requestData.schema);
|
|
74
|
+
* console.log('Required:', requestData.required);
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example Parameter processing
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Process operation parameters by location
|
|
81
|
+
* const pathParams = operation.parameters?.filter(param => {
|
|
82
|
+
* const resolved = param.resolve();
|
|
83
|
+
* return resolved.in === 'path';
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* const queryParams = operation.parameters?.filter(param => {
|
|
87
|
+
* const resolved = param.resolve();
|
|
88
|
+
* return resolved.in === 'query';
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* console.log('Path parameters:', pathParams?.length);
|
|
92
|
+
* console.log('Query parameters:', queryParams?.length);
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example Security requirements
|
|
96
|
+
* ```typescript
|
|
97
|
+
* if (operation.security) {
|
|
98
|
+
* console.log('Operation has specific security requirements');
|
|
99
|
+
* for (const requirement of operation.security) {
|
|
100
|
+
* // Process security schemes for this operation
|
|
101
|
+
* Object.keys(requirement.schemes).forEach(scheme => {
|
|
102
|
+
* console.log(`Security scheme: ${scheme}`);
|
|
103
|
+
* });
|
|
104
|
+
* }
|
|
105
|
+
* } else {
|
|
106
|
+
* console.log('Operation uses default document security');
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
4
110
|
export class OasOperation {
|
|
5
111
|
constructor(fields) {
|
|
6
112
|
Object.defineProperty(this, "oasType", {
|
package/esm/oas/ref/Ref.d.ts
CHANGED
|
@@ -14,6 +14,92 @@ export type RefFields<T extends OasRefData['refType']> = {
|
|
|
14
14
|
refType: T;
|
|
15
15
|
$ref: string;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Represents an OpenAPI reference ($ref) in the SKMTC OAS processing system.
|
|
19
|
+
*
|
|
20
|
+
* The `OasRef` class handles OpenAPI JSON Reference Objects that point to reusable
|
|
21
|
+
* components within the same document. It provides type-safe reference resolution
|
|
22
|
+
* with support for chained references and circular reference detection.
|
|
23
|
+
*
|
|
24
|
+
* ## Key Features
|
|
25
|
+
*
|
|
26
|
+
* - **Type Safety**: Generic parameter ensures resolved types match the reference type
|
|
27
|
+
* - **Lazy Resolution**: References are resolved on-demand, not during construction
|
|
28
|
+
* - **Chain Resolution**: Handles references that point to other references
|
|
29
|
+
* - **Circular Detection**: Prevents infinite loops with maximum lookup limits
|
|
30
|
+
* - **Type Validation**: Ensures resolved objects match expected reference types
|
|
31
|
+
*
|
|
32
|
+
* @template T - The type of component this reference points to
|
|
33
|
+
*
|
|
34
|
+
* @example Basic reference resolution
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { OasRef } from '@skmtc/core';
|
|
37
|
+
*
|
|
38
|
+
* // Reference to a schema component
|
|
39
|
+
* const userRef = new OasRef<'schema'>({
|
|
40
|
+
* refType: 'schema',
|
|
41
|
+
* $ref: '#/components/schemas/User'
|
|
42
|
+
* }, document);
|
|
43
|
+
*
|
|
44
|
+
* // Resolve the reference
|
|
45
|
+
* const userSchema = userRef.resolve();
|
|
46
|
+
* console.log(userSchema.properties); // Access resolved schema properties
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Working with different reference types
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Schema reference
|
|
52
|
+
* const schemaRef = new OasRef<'schema'>({
|
|
53
|
+
* refType: 'schema',
|
|
54
|
+
* $ref: '#/components/schemas/Product'
|
|
55
|
+
* }, document);
|
|
56
|
+
*
|
|
57
|
+
* // Response reference
|
|
58
|
+
* const responseRef = new OasRef<'response'>({
|
|
59
|
+
* refType: 'response',
|
|
60
|
+
* $ref: '#/components/responses/ErrorResponse'
|
|
61
|
+
* }, document);
|
|
62
|
+
*
|
|
63
|
+
* // Parameter reference
|
|
64
|
+
* const paramRef = new OasRef<'parameter'>({
|
|
65
|
+
* refType: 'parameter',
|
|
66
|
+
* $ref: '#/components/parameters/PageSize'
|
|
67
|
+
* }, document);
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example Reference checking and conditional resolution
|
|
71
|
+
* ```typescript
|
|
72
|
+
* function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
|
|
73
|
+
* if (schema.isRef()) {
|
|
74
|
+
* // Handle reference
|
|
75
|
+
* const refName = schema.toRefName();
|
|
76
|
+
* console.log(`Processing reference: ${refName}`);
|
|
77
|
+
*
|
|
78
|
+
* // Resolve only when needed
|
|
79
|
+
* const resolved = schema.resolve();
|
|
80
|
+
* return processed(resolved);
|
|
81
|
+
* } else {
|
|
82
|
+
* // Handle direct schema
|
|
83
|
+
* return process(schema);
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Chained reference handling
|
|
89
|
+
* ```typescript
|
|
90
|
+
* // References can point to other references
|
|
91
|
+
* const chainedRef = new OasRef<'schema'>({
|
|
92
|
+
* refType: 'schema',
|
|
93
|
+
* $ref: '#/components/schemas/AliasToUser'
|
|
94
|
+
* }, document);
|
|
95
|
+
*
|
|
96
|
+
* // resolve() automatically follows the chain
|
|
97
|
+
* const finalSchema = chainedRef.resolve(); // Follows chain to final schema
|
|
98
|
+
*
|
|
99
|
+
* // resolveOnce() resolves only one step
|
|
100
|
+
* const oneStep = chainedRef.resolveOnce(); // May still be a reference
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
17
103
|
export declare class OasRef<T extends OasRefData['refType']> {
|
|
18
104
|
#private;
|
|
19
105
|
oasType: 'ref';
|
package/esm/oas/ref/Ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../../src/oas/ref/Ref.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGhD,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACr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;gBAIP,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,WAAW;IAK1D,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC;IAI1B,OAAO,CAAC,gBAAgB,GAAE,MAAU,GAAG,WAAW,CAAC,CAAC,CAAC;IAUrD,WAAW,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;IAsCzC,SAAS,IAAI,OAAO;IAIpB,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,OAAO,IAAI,UAAU,CAAC,SAAS,CAAC,CAEnC;IAED,IAAI,WAAW,IAAI,WAAW,CAE7B;IAED,YAAY,CAAC,EACX,OAAO,EACR,EAAE,mBAAmB,GAAG,SAAS,CAAC,eAAe,GAAG,mBAAmB,CAAC,CAAC,CAAC;IAsB3E,MAAM,IAAI,MAAM;CAajB;AAED,KAAK,mBAAmB,CAAC,CAAC,SAAS,UAAU,CAAC,SAAS,CAAC,IAAI,UAAU,CACpE,WAAW,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAC/B,CAAA;AAED,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,WAAW,GACX,YAAY,GACZ,UAAU,GACV,cAAc,GACd,SAAS,GACT,iBAAiB,CAAA;AAErB,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,UAAU,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,gBAAgB,EAAE;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,CAAA"}
|
package/esm/oas/ref/Ref.js
CHANGED
|
@@ -14,6 +14,92 @@ import "../../_dnt.polyfills.js";
|
|
|
14
14
|
import { toRefName } from '../../helpers/refFns.js';
|
|
15
15
|
import { match } from 'ts-pattern';
|
|
16
16
|
const MAX_LOOKUPS = 10;
|
|
17
|
+
/**
|
|
18
|
+
* Represents an OpenAPI reference ($ref) in the SKMTC OAS processing system.
|
|
19
|
+
*
|
|
20
|
+
* The `OasRef` class handles OpenAPI JSON Reference Objects that point to reusable
|
|
21
|
+
* components within the same document. It provides type-safe reference resolution
|
|
22
|
+
* with support for chained references and circular reference detection.
|
|
23
|
+
*
|
|
24
|
+
* ## Key Features
|
|
25
|
+
*
|
|
26
|
+
* - **Type Safety**: Generic parameter ensures resolved types match the reference type
|
|
27
|
+
* - **Lazy Resolution**: References are resolved on-demand, not during construction
|
|
28
|
+
* - **Chain Resolution**: Handles references that point to other references
|
|
29
|
+
* - **Circular Detection**: Prevents infinite loops with maximum lookup limits
|
|
30
|
+
* - **Type Validation**: Ensures resolved objects match expected reference types
|
|
31
|
+
*
|
|
32
|
+
* @template T - The type of component this reference points to
|
|
33
|
+
*
|
|
34
|
+
* @example Basic reference resolution
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { OasRef } from '@skmtc/core';
|
|
37
|
+
*
|
|
38
|
+
* // Reference to a schema component
|
|
39
|
+
* const userRef = new OasRef<'schema'>({
|
|
40
|
+
* refType: 'schema',
|
|
41
|
+
* $ref: '#/components/schemas/User'
|
|
42
|
+
* }, document);
|
|
43
|
+
*
|
|
44
|
+
* // Resolve the reference
|
|
45
|
+
* const userSchema = userRef.resolve();
|
|
46
|
+
* console.log(userSchema.properties); // Access resolved schema properties
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Working with different reference types
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Schema reference
|
|
52
|
+
* const schemaRef = new OasRef<'schema'>({
|
|
53
|
+
* refType: 'schema',
|
|
54
|
+
* $ref: '#/components/schemas/Product'
|
|
55
|
+
* }, document);
|
|
56
|
+
*
|
|
57
|
+
* // Response reference
|
|
58
|
+
* const responseRef = new OasRef<'response'>({
|
|
59
|
+
* refType: 'response',
|
|
60
|
+
* $ref: '#/components/responses/ErrorResponse'
|
|
61
|
+
* }, document);
|
|
62
|
+
*
|
|
63
|
+
* // Parameter reference
|
|
64
|
+
* const paramRef = new OasRef<'parameter'>({
|
|
65
|
+
* refType: 'parameter',
|
|
66
|
+
* $ref: '#/components/parameters/PageSize'
|
|
67
|
+
* }, document);
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example Reference checking and conditional resolution
|
|
71
|
+
* ```typescript
|
|
72
|
+
* function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
|
|
73
|
+
* if (schema.isRef()) {
|
|
74
|
+
* // Handle reference
|
|
75
|
+
* const refName = schema.toRefName();
|
|
76
|
+
* console.log(`Processing reference: ${refName}`);
|
|
77
|
+
*
|
|
78
|
+
* // Resolve only when needed
|
|
79
|
+
* const resolved = schema.resolve();
|
|
80
|
+
* return processed(resolved);
|
|
81
|
+
* } else {
|
|
82
|
+
* // Handle direct schema
|
|
83
|
+
* return process(schema);
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Chained reference handling
|
|
89
|
+
* ```typescript
|
|
90
|
+
* // References can point to other references
|
|
91
|
+
* const chainedRef = new OasRef<'schema'>({
|
|
92
|
+
* refType: 'schema',
|
|
93
|
+
* $ref: '#/components/schemas/AliasToUser'
|
|
94
|
+
* }, document);
|
|
95
|
+
*
|
|
96
|
+
* // resolve() automatically follows the chain
|
|
97
|
+
* const finalSchema = chainedRef.resolve(); // Follows chain to final schema
|
|
98
|
+
*
|
|
99
|
+
* // resolveOnce() resolves only one step
|
|
100
|
+
* const oneStep = chainedRef.resolveOnce(); // May still be a reference
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
17
103
|
export class OasRef {
|
|
18
104
|
constructor(fields, oasDocument) {
|
|
19
105
|
Object.defineProperty(this, "oasType", {
|