@skmtc/core 0.0.787 → 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/JsonFile.d.ts +162 -0
- package/esm/dsl/JsonFile.d.ts.map +1 -1
- package/esm/dsl/JsonFile.js +157 -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/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/JsonFile.d.ts +162 -0
- package/script/dsl/JsonFile.d.ts.map +1 -1
- package/script/dsl/JsonFile.js +157 -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
|
@@ -3,7 +3,113 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OasOperation = void 0;
|
|
4
4
|
require("../../_dnt.polyfills.js");
|
|
5
5
|
const Object_js_1 = require("../object/Object.js");
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Represents an OpenAPI Operation Object in the SKMTC OAS processing system.
|
|
8
|
+
*
|
|
9
|
+
* The `OasOperation` class encapsulates a single API operation (path + method combination)
|
|
10
|
+
* with all its associated metadata, parameters, request/response specifications, and
|
|
11
|
+
* security requirements. It provides utilities for extracting common operation data
|
|
12
|
+
* like success responses and request bodies.
|
|
13
|
+
*
|
|
14
|
+
* ## Key Features
|
|
15
|
+
*
|
|
16
|
+
* - **Path and Method**: Unique combination identifying the operation
|
|
17
|
+
* - **Metadata Access**: Operation ID, summary, description, tags, and deprecation status
|
|
18
|
+
* - **Parameter Handling**: Query, path, header, and cookie parameters
|
|
19
|
+
* - **Request/Response Specs**: Type-safe access to request body and response definitions
|
|
20
|
+
* - **Security Context**: Operation-specific security requirements
|
|
21
|
+
* - **Success Response Utils**: Helper methods to identify and extract successful responses
|
|
22
|
+
*
|
|
23
|
+
* @example Basic operation properties
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { OasOperation } from '@skmtc/core';
|
|
26
|
+
*
|
|
27
|
+
* // Typically created during document parsing
|
|
28
|
+
* const getUserOp = new OasOperation({
|
|
29
|
+
* path: '/users/{id}',
|
|
30
|
+
* method: 'get',
|
|
31
|
+
* operationId: 'getUserById',
|
|
32
|
+
* summary: 'Get user by ID',
|
|
33
|
+
* description: 'Retrieves a single user by their unique identifier',
|
|
34
|
+
* parameters: [
|
|
35
|
+
* // Path parameter for user ID
|
|
36
|
+
* { name: 'id', in: 'path', required: true, schema: { type: 'string' } }
|
|
37
|
+
* ],
|
|
38
|
+
* responses: {
|
|
39
|
+
* '200': { description: 'User found', content: { ... } },
|
|
40
|
+
* '404': { description: 'User not found' }
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* console.log(getUserOp.path); // '/users/{id}'
|
|
45
|
+
* console.log(getUserOp.method); // 'get'
|
|
46
|
+
* console.log(getUserOp.operationId); // 'getUserById'
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Working with success responses
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Find the primary success response
|
|
52
|
+
* const successResponse = operation.toSuccessResponse();
|
|
53
|
+
* if (successResponse) {
|
|
54
|
+
* const resolved = successResponse.resolve();
|
|
55
|
+
* console.log('Success response:', resolved.description);
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* // Get the HTTP status code for success
|
|
59
|
+
* const successCode = operation.toSuccessResponseCode();
|
|
60
|
+
* console.log('Success status:', successCode); // '200', '201', 'default', etc.
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example Extracting request body data
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Extract request body with custom transformation
|
|
66
|
+
* const requestData = operation.toRequestBody(({ schema, requestBody }) => {
|
|
67
|
+
* return {
|
|
68
|
+
* schema: schema,
|
|
69
|
+
* contentType: 'application/json',
|
|
70
|
+
* required: requestBody.required ?? false,
|
|
71
|
+
* description: requestBody.description
|
|
72
|
+
* };
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* if (requestData) {
|
|
76
|
+
* console.log('Request schema:', requestData.schema);
|
|
77
|
+
* console.log('Required:', requestData.required);
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Parameter processing
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Process operation parameters by location
|
|
84
|
+
* const pathParams = operation.parameters?.filter(param => {
|
|
85
|
+
* const resolved = param.resolve();
|
|
86
|
+
* return resolved.in === 'path';
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* const queryParams = operation.parameters?.filter(param => {
|
|
90
|
+
* const resolved = param.resolve();
|
|
91
|
+
* return resolved.in === 'query';
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* console.log('Path parameters:', pathParams?.length);
|
|
95
|
+
* console.log('Query parameters:', queryParams?.length);
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Security requirements
|
|
99
|
+
* ```typescript
|
|
100
|
+
* if (operation.security) {
|
|
101
|
+
* console.log('Operation has specific security requirements');
|
|
102
|
+
* for (const requirement of operation.security) {
|
|
103
|
+
* // Process security schemes for this operation
|
|
104
|
+
* Object.keys(requirement.schemes).forEach(scheme => {
|
|
105
|
+
* console.log(`Security scheme: ${scheme}`);
|
|
106
|
+
* });
|
|
107
|
+
* }
|
|
108
|
+
* } else {
|
|
109
|
+
* console.log('Operation uses default document security');
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
7
113
|
class OasOperation {
|
|
8
114
|
constructor(fields) {
|
|
9
115
|
Object.defineProperty(this, "oasType", {
|
package/script/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';
|
|
@@ -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;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAI7E,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,UAAU,CAAC,SAAS,CAAC,IAAI;IACvD,OAAO,EAAE,CAAC,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,qBAAa,MAAM,CAAC,CAAC,SAAS,UAAU,CAAC,SAAS,CAAC;;IACjD,OAAO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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/script/oas/ref/Ref.js
CHANGED
|
@@ -17,6 +17,92 @@ require("../../_dnt.polyfills.js");
|
|
|
17
17
|
const refFns_js_1 = require("../../helpers/refFns.js");
|
|
18
18
|
const ts_pattern_1 = require("ts-pattern");
|
|
19
19
|
const MAX_LOOKUPS = 10;
|
|
20
|
+
/**
|
|
21
|
+
* Represents an OpenAPI reference ($ref) in the SKMTC OAS processing system.
|
|
22
|
+
*
|
|
23
|
+
* The `OasRef` class handles OpenAPI JSON Reference Objects that point to reusable
|
|
24
|
+
* components within the same document. It provides type-safe reference resolution
|
|
25
|
+
* with support for chained references and circular reference detection.
|
|
26
|
+
*
|
|
27
|
+
* ## Key Features
|
|
28
|
+
*
|
|
29
|
+
* - **Type Safety**: Generic parameter ensures resolved types match the reference type
|
|
30
|
+
* - **Lazy Resolution**: References are resolved on-demand, not during construction
|
|
31
|
+
* - **Chain Resolution**: Handles references that point to other references
|
|
32
|
+
* - **Circular Detection**: Prevents infinite loops with maximum lookup limits
|
|
33
|
+
* - **Type Validation**: Ensures resolved objects match expected reference types
|
|
34
|
+
*
|
|
35
|
+
* @template T - The type of component this reference points to
|
|
36
|
+
*
|
|
37
|
+
* @example Basic reference resolution
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { OasRef } from '@skmtc/core';
|
|
40
|
+
*
|
|
41
|
+
* // Reference to a schema component
|
|
42
|
+
* const userRef = new OasRef<'schema'>({
|
|
43
|
+
* refType: 'schema',
|
|
44
|
+
* $ref: '#/components/schemas/User'
|
|
45
|
+
* }, document);
|
|
46
|
+
*
|
|
47
|
+
* // Resolve the reference
|
|
48
|
+
* const userSchema = userRef.resolve();
|
|
49
|
+
* console.log(userSchema.properties); // Access resolved schema properties
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Working with different reference types
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // Schema reference
|
|
55
|
+
* const schemaRef = new OasRef<'schema'>({
|
|
56
|
+
* refType: 'schema',
|
|
57
|
+
* $ref: '#/components/schemas/Product'
|
|
58
|
+
* }, document);
|
|
59
|
+
*
|
|
60
|
+
* // Response reference
|
|
61
|
+
* const responseRef = new OasRef<'response'>({
|
|
62
|
+
* refType: 'response',
|
|
63
|
+
* $ref: '#/components/responses/ErrorResponse'
|
|
64
|
+
* }, document);
|
|
65
|
+
*
|
|
66
|
+
* // Parameter reference
|
|
67
|
+
* const paramRef = new OasRef<'parameter'>({
|
|
68
|
+
* refType: 'parameter',
|
|
69
|
+
* $ref: '#/components/parameters/PageSize'
|
|
70
|
+
* }, document);
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example Reference checking and conditional resolution
|
|
74
|
+
* ```typescript
|
|
75
|
+
* function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
|
|
76
|
+
* if (schema.isRef()) {
|
|
77
|
+
* // Handle reference
|
|
78
|
+
* const refName = schema.toRefName();
|
|
79
|
+
* console.log(`Processing reference: ${refName}`);
|
|
80
|
+
*
|
|
81
|
+
* // Resolve only when needed
|
|
82
|
+
* const resolved = schema.resolve();
|
|
83
|
+
* return processed(resolved);
|
|
84
|
+
* } else {
|
|
85
|
+
* // Handle direct schema
|
|
86
|
+
* return process(schema);
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Chained reference handling
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // References can point to other references
|
|
94
|
+
* const chainedRef = new OasRef<'schema'>({
|
|
95
|
+
* refType: 'schema',
|
|
96
|
+
* $ref: '#/components/schemas/AliasToUser'
|
|
97
|
+
* }, document);
|
|
98
|
+
*
|
|
99
|
+
* // resolve() automatically follows the chain
|
|
100
|
+
* const finalSchema = chainedRef.resolve(); // Follows chain to final schema
|
|
101
|
+
*
|
|
102
|
+
* // resolveOnce() resolves only one step
|
|
103
|
+
* const oneStep = chainedRef.resolveOnce(); // May still be a reference
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
20
106
|
class OasRef {
|
|
21
107
|
constructor(fields, oasDocument) {
|
|
22
108
|
Object.defineProperty(this, "oasType", {
|