@alagoni97/cli 0.72.2 → 0.72.4
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/dist/codegen/generators/typescript/channels/openapi.js +11 -15
- package/dist/codegen/inputs/openapi/generators/headers.js +6 -2
- package/dist/codegen/inputs/openapi/generators/parameters.js +6 -2
- package/dist/codegen/inputs/openapi/generators/payloads.js +17 -9
- package/dist/codegen/inputs/openapi/generators/types.js +6 -2
- package/dist/codegen/inputs/openapi/utils.d.ts +15 -0
- package/dist/codegen/inputs/openapi/utils.js +28 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ const utils_3 = require("../utils");
|
|
|
8
8
|
const errors_1 = require("../../../errors");
|
|
9
9
|
const utils_4 = require("../../../utils");
|
|
10
10
|
const security_1 = require("../../../inputs/openapi/security");
|
|
11
|
+
const utils_5 = require("../../../inputs/openapi/utils");
|
|
11
12
|
const HTTP_METHODS = [
|
|
12
13
|
'get',
|
|
13
14
|
'post',
|
|
@@ -83,7 +84,11 @@ function processOperation(pathItem, method, path, payloads, parameters) {
|
|
|
83
84
|
if (!operation) {
|
|
84
85
|
return undefined;
|
|
85
86
|
}
|
|
86
|
-
const operationId =
|
|
87
|
+
const operationId = (0, utils_5.deriveOperationId)({
|
|
88
|
+
operationId: operation.operationId,
|
|
89
|
+
method,
|
|
90
|
+
path
|
|
91
|
+
});
|
|
87
92
|
const hasBody = METHODS_WITH_BODY.includes(method);
|
|
88
93
|
// Look up payloads
|
|
89
94
|
const requestPayload = hasBody
|
|
@@ -120,9 +125,12 @@ function processOperation(pathItem, method, path, payloads, parameters) {
|
|
|
120
125
|
// Extract operation metadata for JSDoc
|
|
121
126
|
const description = operation.description ?? operation.summary;
|
|
122
127
|
const deprecated = operation.deprecated === true;
|
|
123
|
-
// Generate the HTTP client function
|
|
128
|
+
// Generate the HTTP client function.
|
|
129
|
+
// Use the operationId directly as the function name; the HTTP method is
|
|
130
|
+
// already encoded in synthesized ids (and meaningful in spec-provided ones),
|
|
131
|
+
// so prepending the method here would double the verb (e.g. getGetUser).
|
|
124
132
|
return (0, http_1.renderHttpFetchClient)({
|
|
125
|
-
|
|
133
|
+
functionName: (0, utils_3.camelCase)(operationId),
|
|
126
134
|
requestMessageModule: hasBody ? requestMessageModule : undefined,
|
|
127
135
|
requestMessageType: hasBody ? requestMessageType : undefined,
|
|
128
136
|
replyMessageModule,
|
|
@@ -154,15 +162,3 @@ function validateOpenAPIContext(context) {
|
|
|
154
162
|
}
|
|
155
163
|
return { openapiDocument };
|
|
156
164
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Gets the operation ID from an OpenAPI operation.
|
|
159
|
-
* Falls back to generating one from method+path if not present.
|
|
160
|
-
*/
|
|
161
|
-
function getOperationId(operation, method, path) {
|
|
162
|
-
if (operation.operationId) {
|
|
163
|
-
return operation.operationId;
|
|
164
|
-
}
|
|
165
|
-
// Generate from method + path
|
|
166
|
-
const sanitizedPath = path.replace(/[^a-zA-Z0-9]/g, '');
|
|
167
|
-
return `${method}${sanitizedPath}`;
|
|
168
|
-
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processOpenAPIHeaders = void 0;
|
|
4
4
|
const utils_1 = require("../../../generators/typescript/utils");
|
|
5
|
+
const utils_2 = require("../utils");
|
|
5
6
|
// Helper function to convert OpenAPI header schema to JSON Schema
|
|
6
7
|
function convertHeaderSchemaToJsonSchema(header) {
|
|
7
8
|
let schema;
|
|
@@ -44,8 +45,11 @@ function extractHeadersFromOperations(paths) {
|
|
|
44
45
|
return param.in === 'header';
|
|
45
46
|
});
|
|
46
47
|
if (allParameters.length > 0) {
|
|
47
|
-
const operationId =
|
|
48
|
-
|
|
48
|
+
const operationId = (0, utils_2.deriveOperationId)({
|
|
49
|
+
operationId: operationObj.operationId,
|
|
50
|
+
method,
|
|
51
|
+
path: pathKey
|
|
52
|
+
});
|
|
49
53
|
operationHeaders[operationId] = headerParams;
|
|
50
54
|
}
|
|
51
55
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createOpenAPIGenerator = exports.createParameterSchema = exports.convertParameterSchemaToJsonSchema = exports.processOpenAPIParameters = void 0;
|
|
4
4
|
const utils_1 = require("../../../generators/typescript/utils");
|
|
5
|
+
const utils_2 = require("../utils");
|
|
5
6
|
const modelina_1 = require("@asyncapi/modelina");
|
|
6
7
|
// Constants for OpenAPI parameter metadata keys
|
|
7
8
|
const X_PARAMETER_LOCATION = 'x-parameter-location';
|
|
@@ -30,8 +31,11 @@ function processOpenAPIParameters(openapiDocument) {
|
|
|
30
31
|
return ['path', 'query'].includes(param.in);
|
|
31
32
|
});
|
|
32
33
|
if (filteredParams.length > 0) {
|
|
33
|
-
const operationId =
|
|
34
|
-
|
|
34
|
+
const operationId = (0, utils_2.deriveOperationId)({
|
|
35
|
+
operationId: operationObj.operationId,
|
|
36
|
+
method,
|
|
37
|
+
path: pathKey
|
|
38
|
+
});
|
|
35
39
|
// Create schema for the parameters
|
|
36
40
|
const parameterSchema = createParameterSchema(operationId, filteredParams, 'Parameters', pathKey);
|
|
37
41
|
channelParameters[operationId] = {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.processOpenAPIPayloads = void 0;
|
|
4
4
|
const utils_1 = require("../../../generators/typescript/utils");
|
|
5
5
|
const utils_2 = require("../../../utils");
|
|
6
|
+
const utils_3 = require("../utils");
|
|
6
7
|
// Constants
|
|
7
8
|
const JSON_SCHEMA_DRAFT_07 = 'http://json-schema.org/draft-07/schema';
|
|
8
9
|
// Helper function to extract schema from OpenAPI 2.0 response
|
|
@@ -98,19 +99,26 @@ function extractPayloadsFromOperations(paths) {
|
|
|
98
99
|
continue;
|
|
99
100
|
}
|
|
100
101
|
const operationObj = operation;
|
|
101
|
-
const operationId =
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
const operationId = (0, utils_3.deriveOperationId)({
|
|
103
|
+
operationId: operationObj.operationId,
|
|
104
|
+
method,
|
|
105
|
+
path: pathKey
|
|
106
|
+
});
|
|
107
|
+
// Extract request payload schema.
|
|
108
|
+
// Prefer the 3.x `requestBody`: 3.x operations also carry a `parameters`
|
|
109
|
+
// array (path/query/header), so presence of `parameters` cannot be used
|
|
110
|
+
// to detect 2.0 - doing so would drop the body on any 3.x operation that
|
|
111
|
+
// declares parameters. The 2.0 body lives in a `parameters` entry with
|
|
112
|
+
// `in: 'body'`, so fall back to that only when there is no `requestBody`.
|
|
104
113
|
let requestSchema = null;
|
|
105
|
-
|
|
106
|
-
if ('parameters' in operationObj && operationObj.parameters) {
|
|
107
|
-
// OpenAPI 2.0 style
|
|
108
|
-
requestSchema = extractOpenAPI2RequestSchema(operationObj.parameters);
|
|
109
|
-
}
|
|
110
|
-
else if ('requestBody' in operationObj && operationObj.requestBody) {
|
|
114
|
+
if ('requestBody' in operationObj && operationObj.requestBody) {
|
|
111
115
|
// OpenAPI 3.x style
|
|
112
116
|
requestSchema = extractOpenAPI3RequestSchema(operationObj.requestBody);
|
|
113
117
|
}
|
|
118
|
+
else if ('parameters' in operationObj && operationObj.parameters) {
|
|
119
|
+
// OpenAPI 2.0 style (body carried as a `in: 'body'` parameter)
|
|
120
|
+
requestSchema = extractOpenAPI2RequestSchema(operationObj.parameters);
|
|
121
|
+
}
|
|
114
122
|
if (requestSchema) {
|
|
115
123
|
const requestSchemaId = (0, utils_1.pascalCase)(`${operationId}_Request`);
|
|
116
124
|
requestPayloads[operationId] = {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateOpenAPITypes = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
4
5
|
async function generateOpenAPITypes(openapiDocument, generator) {
|
|
5
6
|
const paths = openapiDocument.paths ?? {};
|
|
6
7
|
const allPaths = Object.keys(paths);
|
|
@@ -22,8 +23,11 @@ async function generateOpenAPITypes(openapiDocument, generator) {
|
|
|
22
23
|
if (operationObj &&
|
|
23
24
|
typeof operationObj === 'object' &&
|
|
24
25
|
method !== 'parameters') {
|
|
25
|
-
const operationId =
|
|
26
|
-
|
|
26
|
+
const operationId = (0, utils_1.deriveOperationId)({
|
|
27
|
+
operationId: operationObj.operationId,
|
|
28
|
+
method,
|
|
29
|
+
path: pathStr
|
|
30
|
+
});
|
|
27
31
|
operationIds.push(operationId);
|
|
28
32
|
operationIdToPathMap[operationId] = pathStr;
|
|
29
33
|
pathOperationIds.push(operationId);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the operation identifier used to correlate payloads, parameters,
|
|
3
|
+
* headers and channel functions for a single OpenAPI operation.
|
|
4
|
+
*
|
|
5
|
+
* When the spec provides an `operationId` it is used verbatim so generated
|
|
6
|
+
* names stay predictable. Otherwise a name is synthesized from the HTTP method
|
|
7
|
+
* and path segments, preserving word boundaries so it can be cased cleanly
|
|
8
|
+
* (e.g. `GET /v2/connect/{referenceId}` -> `getV2ConnectReferenceId`) instead
|
|
9
|
+
* of collapsing into an uncasable blob (`getv2connectreferenceId`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function deriveOperationId({ operationId, method, path }: {
|
|
12
|
+
operationId?: string;
|
|
13
|
+
method: string;
|
|
14
|
+
path: string;
|
|
15
|
+
}): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveOperationId = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Shared helpers for deriving stable identifiers from OpenAPI operations.
|
|
6
|
+
*/
|
|
7
|
+
const modelina_1 = require("@asyncapi/modelina");
|
|
8
|
+
/**
|
|
9
|
+
* Derive the operation identifier used to correlate payloads, parameters,
|
|
10
|
+
* headers and channel functions for a single OpenAPI operation.
|
|
11
|
+
*
|
|
12
|
+
* When the spec provides an `operationId` it is used verbatim so generated
|
|
13
|
+
* names stay predictable. Otherwise a name is synthesized from the HTTP method
|
|
14
|
+
* and path segments, preserving word boundaries so it can be cased cleanly
|
|
15
|
+
* (e.g. `GET /v2/connect/{referenceId}` -> `getV2ConnectReferenceId`) instead
|
|
16
|
+
* of collapsing into an uncasable blob (`getv2connectreferenceId`).
|
|
17
|
+
*/
|
|
18
|
+
function deriveOperationId({ operationId, method, path }) {
|
|
19
|
+
if (operationId) {
|
|
20
|
+
return operationId;
|
|
21
|
+
}
|
|
22
|
+
const segments = path
|
|
23
|
+
.split('/')
|
|
24
|
+
.map((segment) => segment.replace(/[{}]/g, ''))
|
|
25
|
+
.filter((segment) => segment.length > 0);
|
|
26
|
+
return modelina_1.FormatHelpers.toCamelCase([method, ...segments].join(' '));
|
|
27
|
+
}
|
|
28
|
+
exports.deriveOperationId = deriveOperationId;
|
package/oclif.manifest.json
CHANGED