@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
|
@@ -62,6 +62,101 @@ const File_js_1 = require("../dsl/File.js");
|
|
|
62
62
|
const JsonFile_js_1 = require("../dsl/JsonFile.js");
|
|
63
63
|
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
64
64
|
const ts_pattern_1 = require("ts-pattern");
|
|
65
|
+
/**
|
|
66
|
+
* The generation context for the second phase of the SKMTC transformation pipeline.
|
|
67
|
+
*
|
|
68
|
+
* `GenerateContext` manages the transformation of parsed OAS (OpenAPI Schema) objects
|
|
69
|
+
* into code artifacts using pluggable generators. It provides APIs for model and operation
|
|
70
|
+
* generation, file management, dependency tracking, and artifact registration.
|
|
71
|
+
*
|
|
72
|
+
* ## Key Responsibilities
|
|
73
|
+
*
|
|
74
|
+
* - **Generator Orchestration**: Executes pluggable model and operation generators
|
|
75
|
+
* - **Schema Processing**: Provides utilities for working with OAS schemas and references
|
|
76
|
+
* - **File Management**: Handles file creation, imports, exports, and dependencies
|
|
77
|
+
* - **Artifact Registration**: Collects generated definitions and files for rendering
|
|
78
|
+
* - **Type System Integration**: Bridges OAS types with generator-specific type systems
|
|
79
|
+
* - **Settings Management**: Handles skipping logic and client customizations
|
|
80
|
+
*
|
|
81
|
+
* ## Generator Integration
|
|
82
|
+
*
|
|
83
|
+
* The context works with two main types of generators:
|
|
84
|
+
* - **Model Generators**: Transform schema definitions into type definitions
|
|
85
|
+
* - **Operation Generators**: Transform API operations into client functions
|
|
86
|
+
*
|
|
87
|
+
* @example Basic usage in a model generator
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { ModelBase } from '@skmtc/core';
|
|
90
|
+
*
|
|
91
|
+
* class TypeScriptInterface extends ModelBase {
|
|
92
|
+
* generate(): Definition {
|
|
93
|
+
* const schema = this.context.getSchema(this.refName);
|
|
94
|
+
*
|
|
95
|
+
* return new Definition({
|
|
96
|
+
* context: this.context,
|
|
97
|
+
* identifier: Identifier.createType(this.refName),
|
|
98
|
+
* description: schema.description,
|
|
99
|
+
* value: {
|
|
100
|
+
* generatorKey: this.generatorKey,
|
|
101
|
+
* content: this.generateInterfaceBody(schema)
|
|
102
|
+
* }
|
|
103
|
+
* });
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example Operation generator usage
|
|
109
|
+
* ```typescript
|
|
110
|
+
* class ApiClientGenerator extends OperationBase {
|
|
111
|
+
* generate(): Definition {
|
|
112
|
+
* const operation = this.context.getOperation(this.path, this.method);
|
|
113
|
+
*
|
|
114
|
+
* const functionName = this.context.createOperationName(this.path, this.method);
|
|
115
|
+
*
|
|
116
|
+
* return new Definition({
|
|
117
|
+
* context: this.context,
|
|
118
|
+
* identifier: Identifier.createVariable(functionName),
|
|
119
|
+
* value: {
|
|
120
|
+
* generatorKey: this.generatorKey,
|
|
121
|
+
* content: this.generateClientFunction(operation)
|
|
122
|
+
* }
|
|
123
|
+
* });
|
|
124
|
+
* }
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @example Schema and type system integration
|
|
129
|
+
* ```typescript
|
|
130
|
+
* class MyGenerator extends ModelBase {
|
|
131
|
+
* generate(): Definition {
|
|
132
|
+
* const schema = this.context.getSchema(this.refName);
|
|
133
|
+
*
|
|
134
|
+
* // Transform schema using type system
|
|
135
|
+
* const typeOutput = this.context.transformSchema(schema, {
|
|
136
|
+
* stringType: 'string',
|
|
137
|
+
* numberType: 'number',
|
|
138
|
+
* arrayType: (items) => `Array<${items}>`
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* // Register dependencies
|
|
142
|
+
* if (schema.hasReferences()) {
|
|
143
|
+
* this.context.addImportsToFile('./models/types.ts', {
|
|
144
|
+
* './common': ['BaseModel']
|
|
145
|
+
* });
|
|
146
|
+
* }
|
|
147
|
+
*
|
|
148
|
+
* return new Definition({
|
|
149
|
+
* context: this.context,
|
|
150
|
+
* identifier: Identifier.createType(this.refName),
|
|
151
|
+
* value: {
|
|
152
|
+
* generatorKey: this.generatorKey,
|
|
153
|
+
* content: typeOutput.content
|
|
154
|
+
* }
|
|
155
|
+
* });
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
65
160
|
class GenerateContext {
|
|
66
161
|
constructor({ oasDocument, settings, logger, captureCurrentResult, stackTrail, toGeneratorConfigMap }) {
|
|
67
162
|
_GenerateContext_instances.add(this);
|
package/script/dsl/JsonFile.d.ts
CHANGED
|
@@ -1,12 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructor arguments for {@link JsonFile}.
|
|
3
|
+
*/
|
|
1
4
|
type JsonFileArgs = {
|
|
5
|
+
/** The file path for the generated JSON file */
|
|
2
6
|
path: string;
|
|
7
|
+
/** The JSON content to write to the file */
|
|
3
8
|
content: Record<string, unknown>;
|
|
4
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Represents a JSON file in the SKMTC DSL system.
|
|
12
|
+
*
|
|
13
|
+
* The `JsonFile` class is used to generate JSON files as part of the code generation
|
|
14
|
+
* process. It provides a simple interface for creating configuration files, manifests,
|
|
15
|
+
* package.json files, and other JSON-based artifacts with proper formatting.
|
|
16
|
+
*
|
|
17
|
+
* ## Key Features
|
|
18
|
+
*
|
|
19
|
+
* - **JSON Formatting**: Automatically formats JSON with 2-space indentation
|
|
20
|
+
* - **Type Safety**: Accepts any valid JSON-serializable content structure
|
|
21
|
+
* - **Path Management**: Associates content with specific file paths
|
|
22
|
+
* - **String Conversion**: Easy integration with file writing systems
|
|
23
|
+
*
|
|
24
|
+
* @example Basic JSON file creation
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { JsonFile } from '@skmtc/core';
|
|
27
|
+
*
|
|
28
|
+
* const packageJson = new JsonFile({
|
|
29
|
+
* path: './package.json',
|
|
30
|
+
* content: {
|
|
31
|
+
* name: 'my-api-client',
|
|
32
|
+
* version: '1.0.0',
|
|
33
|
+
* type: 'module',
|
|
34
|
+
* main: './index.js',
|
|
35
|
+
* dependencies: {
|
|
36
|
+
* 'axios': '^1.0.0'
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const jsonContent = packageJson.toString();
|
|
42
|
+
* console.log(jsonContent);
|
|
43
|
+
* // {
|
|
44
|
+
* // "name": "my-api-client",
|
|
45
|
+
* // "version": "1.0.0",
|
|
46
|
+
* // "type": "module",
|
|
47
|
+
* // "main": "./index.js",
|
|
48
|
+
* // "dependencies": {
|
|
49
|
+
* // "axios": "^1.0.0"
|
|
50
|
+
* // }
|
|
51
|
+
* // }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example Configuration file generation
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const configFile = new JsonFile({
|
|
57
|
+
* path: './src/config/api.json',
|
|
58
|
+
* content: {
|
|
59
|
+
* baseUrl: 'https://api.example.com',
|
|
60
|
+
* timeout: 5000,
|
|
61
|
+
* retryAttempts: 3,
|
|
62
|
+
* endpoints: {
|
|
63
|
+
* users: '/users',
|
|
64
|
+
* products: '/products',
|
|
65
|
+
* orders: '/orders'
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Write to file system
|
|
71
|
+
* await Deno.writeTextFile(configFile.path, configFile.toString());
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example OpenAPI specification output
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const openApiFile = new JsonFile({
|
|
77
|
+
* path: './dist/openapi.json',
|
|
78
|
+
* content: {
|
|
79
|
+
* openapi: '3.0.0',
|
|
80
|
+
* info: {
|
|
81
|
+
* title: 'My API',
|
|
82
|
+
* version: '1.0.0'
|
|
83
|
+
* },
|
|
84
|
+
* paths: {
|
|
85
|
+
* '/users': {
|
|
86
|
+
* get: {
|
|
87
|
+
* summary: 'List users',
|
|
88
|
+
* responses: {
|
|
89
|
+
* '200': {
|
|
90
|
+
* description: 'Success'
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example Using with generator registration
|
|
101
|
+
* ```typescript
|
|
102
|
+
* class MyGenerator extends ContentBase {
|
|
103
|
+
* generate() {
|
|
104
|
+
* const manifestFile = new JsonFile({
|
|
105
|
+
* path: './generated/manifest.json',
|
|
106
|
+
* content: {
|
|
107
|
+
* generatedAt: new Date().toISOString(),
|
|
108
|
+
* version: '1.0.0',
|
|
109
|
+
* files: [
|
|
110
|
+
* './models/User.ts',
|
|
111
|
+
* './models/Product.ts'
|
|
112
|
+
* ]
|
|
113
|
+
* }
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // Register with the generation context
|
|
117
|
+
* this.register({ jsonFile: manifestFile });
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
5
122
|
export declare class JsonFile {
|
|
123
|
+
/** The file type, always 'json' for JSON files */
|
|
6
124
|
fileType: 'json';
|
|
125
|
+
/** The file path for this generated JSON file */
|
|
7
126
|
path: string;
|
|
127
|
+
/** The JSON content to write to the file */
|
|
8
128
|
content: Record<string, unknown>;
|
|
129
|
+
/**
|
|
130
|
+
* Creates a new JsonFile instance.
|
|
131
|
+
*
|
|
132
|
+
* @param args - JSON file configuration
|
|
133
|
+
* @param args.path - The output path for this JSON file
|
|
134
|
+
* @param args.content - The JSON content to write
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const configFile = new JsonFile({
|
|
139
|
+
* path: './config/settings.json',
|
|
140
|
+
* content: {
|
|
141
|
+
* theme: 'dark',
|
|
142
|
+
* language: 'en',
|
|
143
|
+
* features: ['auth', 'notifications']
|
|
144
|
+
* }
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
9
148
|
constructor({ path, content }: JsonFileArgs);
|
|
149
|
+
/**
|
|
150
|
+
* Converts the JSON content to a formatted string.
|
|
151
|
+
*
|
|
152
|
+
* This method serializes the content object to JSON with 2-space indentation
|
|
153
|
+
* for readable output. The resulting string is suitable for writing directly
|
|
154
|
+
* to a file or including in the generation pipeline.
|
|
155
|
+
*
|
|
156
|
+
* @returns The formatted JSON content as a string
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const file = new JsonFile({
|
|
161
|
+
* path: './data.json',
|
|
162
|
+
* content: { name: 'test', value: 42 }
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* console.log(file.toString());
|
|
166
|
+
* // {
|
|
167
|
+
* // "name": "test",
|
|
168
|
+
* // "value": 42
|
|
169
|
+
* // }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
10
172
|
toString(): string;
|
|
11
173
|
}
|
|
12
174
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonFile.d.ts","sourceRoot":"","sources":["../../src/dsl/JsonFile.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED,qBAAa,QAAQ;IACnB,QAAQ,EAAE,MAAM,CAAS;
|
|
1
|
+
{"version":3,"file":"JsonFile.d.ts","sourceRoot":"","sources":["../../src/dsl/JsonFile.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,YAAY,GAAG;IAClB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AACH,qBAAa,QAAQ;IACnB,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAS;IAEzB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAA;IAEZ,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEhC;;;;;;;;;;;;;;;;;;OAkBG;gBACS,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,YAAY;IAK3C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|
package/script/dsl/JsonFile.js
CHANGED
|
@@ -1,20 +1,154 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JsonFile = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents a JSON file in the SKMTC DSL system.
|
|
6
|
+
*
|
|
7
|
+
* The `JsonFile` class is used to generate JSON files as part of the code generation
|
|
8
|
+
* process. It provides a simple interface for creating configuration files, manifests,
|
|
9
|
+
* package.json files, and other JSON-based artifacts with proper formatting.
|
|
10
|
+
*
|
|
11
|
+
* ## Key Features
|
|
12
|
+
*
|
|
13
|
+
* - **JSON Formatting**: Automatically formats JSON with 2-space indentation
|
|
14
|
+
* - **Type Safety**: Accepts any valid JSON-serializable content structure
|
|
15
|
+
* - **Path Management**: Associates content with specific file paths
|
|
16
|
+
* - **String Conversion**: Easy integration with file writing systems
|
|
17
|
+
*
|
|
18
|
+
* @example Basic JSON file creation
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { JsonFile } from '@skmtc/core';
|
|
21
|
+
*
|
|
22
|
+
* const packageJson = new JsonFile({
|
|
23
|
+
* path: './package.json',
|
|
24
|
+
* content: {
|
|
25
|
+
* name: 'my-api-client',
|
|
26
|
+
* version: '1.0.0',
|
|
27
|
+
* type: 'module',
|
|
28
|
+
* main: './index.js',
|
|
29
|
+
* dependencies: {
|
|
30
|
+
* 'axios': '^1.0.0'
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* const jsonContent = packageJson.toString();
|
|
36
|
+
* console.log(jsonContent);
|
|
37
|
+
* // {
|
|
38
|
+
* // "name": "my-api-client",
|
|
39
|
+
* // "version": "1.0.0",
|
|
40
|
+
* // "type": "module",
|
|
41
|
+
* // "main": "./index.js",
|
|
42
|
+
* // "dependencies": {
|
|
43
|
+
* // "axios": "^1.0.0"
|
|
44
|
+
* // }
|
|
45
|
+
* // }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Configuration file generation
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const configFile = new JsonFile({
|
|
51
|
+
* path: './src/config/api.json',
|
|
52
|
+
* content: {
|
|
53
|
+
* baseUrl: 'https://api.example.com',
|
|
54
|
+
* timeout: 5000,
|
|
55
|
+
* retryAttempts: 3,
|
|
56
|
+
* endpoints: {
|
|
57
|
+
* users: '/users',
|
|
58
|
+
* products: '/products',
|
|
59
|
+
* orders: '/orders'
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // Write to file system
|
|
65
|
+
* await Deno.writeTextFile(configFile.path, configFile.toString());
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example OpenAPI specification output
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const openApiFile = new JsonFile({
|
|
71
|
+
* path: './dist/openapi.json',
|
|
72
|
+
* content: {
|
|
73
|
+
* openapi: '3.0.0',
|
|
74
|
+
* info: {
|
|
75
|
+
* title: 'My API',
|
|
76
|
+
* version: '1.0.0'
|
|
77
|
+
* },
|
|
78
|
+
* paths: {
|
|
79
|
+
* '/users': {
|
|
80
|
+
* get: {
|
|
81
|
+
* summary: 'List users',
|
|
82
|
+
* responses: {
|
|
83
|
+
* '200': {
|
|
84
|
+
* description: 'Success'
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example Using with generator registration
|
|
95
|
+
* ```typescript
|
|
96
|
+
* class MyGenerator extends ContentBase {
|
|
97
|
+
* generate() {
|
|
98
|
+
* const manifestFile = new JsonFile({
|
|
99
|
+
* path: './generated/manifest.json',
|
|
100
|
+
* content: {
|
|
101
|
+
* generatedAt: new Date().toISOString(),
|
|
102
|
+
* version: '1.0.0',
|
|
103
|
+
* files: [
|
|
104
|
+
* './models/User.ts',
|
|
105
|
+
* './models/Product.ts'
|
|
106
|
+
* ]
|
|
107
|
+
* }
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* // Register with the generation context
|
|
111
|
+
* this.register({ jsonFile: manifestFile });
|
|
112
|
+
* }
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
4
116
|
class JsonFile {
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new JsonFile instance.
|
|
119
|
+
*
|
|
120
|
+
* @param args - JSON file configuration
|
|
121
|
+
* @param args.path - The output path for this JSON file
|
|
122
|
+
* @param args.content - The JSON content to write
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const configFile = new JsonFile({
|
|
127
|
+
* path: './config/settings.json',
|
|
128
|
+
* content: {
|
|
129
|
+
* theme: 'dark',
|
|
130
|
+
* language: 'en',
|
|
131
|
+
* features: ['auth', 'notifications']
|
|
132
|
+
* }
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
5
136
|
constructor({ path, content }) {
|
|
137
|
+
/** The file type, always 'json' for JSON files */
|
|
6
138
|
Object.defineProperty(this, "fileType", {
|
|
7
139
|
enumerable: true,
|
|
8
140
|
configurable: true,
|
|
9
141
|
writable: true,
|
|
10
142
|
value: 'json'
|
|
11
143
|
});
|
|
144
|
+
/** The file path for this generated JSON file */
|
|
12
145
|
Object.defineProperty(this, "path", {
|
|
13
146
|
enumerable: true,
|
|
14
147
|
configurable: true,
|
|
15
148
|
writable: true,
|
|
16
149
|
value: void 0
|
|
17
150
|
});
|
|
151
|
+
/** The JSON content to write to the file */
|
|
18
152
|
Object.defineProperty(this, "content", {
|
|
19
153
|
enumerable: true,
|
|
20
154
|
configurable: true,
|
|
@@ -24,6 +158,29 @@ class JsonFile {
|
|
|
24
158
|
this.path = path;
|
|
25
159
|
this.content = content;
|
|
26
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Converts the JSON content to a formatted string.
|
|
163
|
+
*
|
|
164
|
+
* This method serializes the content object to JSON with 2-space indentation
|
|
165
|
+
* for readable output. The resulting string is suitable for writing directly
|
|
166
|
+
* to a file or including in the generation pipeline.
|
|
167
|
+
*
|
|
168
|
+
* @returns The formatted JSON content as a string
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const file = new JsonFile({
|
|
173
|
+
* path: './data.json',
|
|
174
|
+
* content: { name: 'test', value: 42 }
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* console.log(file.toString());
|
|
178
|
+
* // {
|
|
179
|
+
* // "name": "test",
|
|
180
|
+
* // "value": 42
|
|
181
|
+
* // }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
27
184
|
toString() {
|
|
28
185
|
return JSON.stringify(this.content, null, 2);
|
|
29
186
|
}
|
|
@@ -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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Operation.d.ts","sourceRoot":"","sources":["../../../src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