@openapi-qraft/plugin 2.0.0-next.9 → 2.0.1-beta.0
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/CHANGELOG.md +111 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/QraftCommand.d.ts +2 -2
- package/dist/lib/QraftCommand.d.ts.map +1 -1
- package/dist/lib/QraftCommand.js +13 -6
- package/dist/lib/QraftCommand.js.map +1 -1
- package/dist/lib/open-api/OpenAPISchemaType.d.ts +3 -0
- package/dist/lib/open-api/OpenAPISchemaType.d.ts.map +1 -1
- package/dist/lib/open-api/OpenAPIService.d.ts +29 -0
- package/dist/lib/open-api/OpenAPIService.d.ts.map +1 -0
- package/dist/lib/open-api/OpenAPIService.js +2 -0
- package/dist/lib/open-api/OpenAPIService.js.map +1 -0
- package/dist/lib/open-api/getOperationName.d.ts +4 -1
- package/dist/lib/open-api/getOperationName.d.ts.map +1 -1
- package/dist/lib/open-api/getOperationName.js +19 -7
- package/dist/lib/open-api/getOperationName.js.map +1 -1
- package/dist/lib/open-api/getServices.d.ts +9 -30
- package/dist/lib/open-api/getServices.d.ts.map +1 -1
- package/dist/lib/open-api/getServices.js +7 -8
- package/dist/lib/open-api/getServices.js.map +1 -1
- package/dist/lib/open-api/replaceRefParametersWithComponent.d.ts +5 -0
- package/dist/lib/open-api/replaceRefParametersWithComponent.d.ts.map +1 -0
- package/dist/lib/open-api/replaceRefParametersWithComponent.js +26 -0
- package/dist/lib/open-api/replaceRefParametersWithComponent.js.map +1 -0
- package/dist/lib/parseOperationGlobs.d.ts +2 -2
- package/dist/lib/parseOperationGlobs.d.ts.map +1 -1
- package/dist/lib/predefineSchemaParameters.d.ts +0 -1
- package/dist/lib/predefineSchemaParameters.d.ts.map +1 -1
- package/dist/lib/predefineSchemaParameters.js +9 -13
- package/dist/lib/predefineSchemaParameters.js.map +1 -1
- package/dist/lib/processOperationNameModifierOption.d.ts +9 -5
- package/dist/lib/processOperationNameModifierOption.d.ts.map +1 -1
- package/dist/lib/processOperationNameModifierOption.js +23 -4
- package/dist/lib/processOperationNameModifierOption.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/package.json +12 -3
- package/src/index.ts +1 -0
- package/src/lib/QraftCommand.ts +32 -21
- package/src/lib/open-api/OpenAPISchemaType.ts +3 -0
- package/src/lib/open-api/OpenAPIService.ts +40 -0
- package/src/lib/open-api/getOperationName.ts +34 -7
- package/src/lib/open-api/getServices.ts +26 -49
- package/src/lib/open-api/replaceRefParametersWithComponent.ts +40 -0
- package/src/lib/parseOperationGlobs.ts +1 -1
- package/src/lib/predefineSchemaParameters.ts +12 -19
- package/src/lib/processOperationNameModifierOption.ts +45 -15
- package/src/packageVersion.ts +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createServicePathMatch } from './createServicePathMatch.js';
|
|
2
|
+
import { replaceRefParametersWithComponent } from './open-api/replaceRefParametersWithComponent.js';
|
|
2
3
|
import { parseOperationGlobs, } from './parseOperationGlobs.js';
|
|
3
4
|
import { splitCommaSeparatedGlobs } from './splitCommaSeparatedGlobs.js';
|
|
4
5
|
export function predefineSchemaParameters(schema, predefinedParametersGlobs) {
|
|
@@ -25,9 +26,8 @@ export function predefineSchemaParameters(schema, predefinedParametersGlobs) {
|
|
|
25
26
|
const predefinedOperation = predefinedPathItem?.[method];
|
|
26
27
|
if (predefinedOperation)
|
|
27
28
|
assertIsOperationObject(predefinedOperation);
|
|
28
|
-
const operationParameters = predefinedOperation?.parameters ?? operation.parameters
|
|
29
|
-
|
|
30
|
-
const predefinedParameters = operationParameters.map((operationParameter) => {
|
|
29
|
+
const operationParameters = replaceRefParametersWithComponent(predefinedOperation?.parameters ?? operation.parameters, schema.components?.parameters);
|
|
30
|
+
const predefinedParameters = operationParameters?.map((operationParameter) => {
|
|
31
31
|
if (findPredefinedOperationParameter(operationParameter, predefinedParametersGlob.parameters)) {
|
|
32
32
|
return {
|
|
33
33
|
...operationParameter,
|
|
@@ -127,8 +127,9 @@ export function createPredefinedParametersGlobs(schema, predefinedParameters) {
|
|
|
127
127
|
if (!operation)
|
|
128
128
|
continue;
|
|
129
129
|
assertIsOperationObject(operation);
|
|
130
|
-
const operationParameters =
|
|
131
|
-
|
|
130
|
+
const operationParameters = replaceRefParametersWithComponent(
|
|
131
|
+
// @ts-expect-error the issue with custom OpenAPISchemaType
|
|
132
|
+
operation.parameters, schema.components?.parameters);
|
|
132
133
|
const predefinedParametersGlobKey = createOperationGlobsKey(pathGlobs, methods);
|
|
133
134
|
if (!predefinedParametersGlobMap.has(predefinedParametersGlobKey))
|
|
134
135
|
predefinedParametersGlobMap.set(predefinedParametersGlobKey, {
|
|
@@ -142,7 +143,9 @@ export function createPredefinedParametersGlobs(schema, predefinedParameters) {
|
|
|
142
143
|
if (!predefinedPathGlob)
|
|
143
144
|
throw new Error('predefinedPathGlob not found');
|
|
144
145
|
for (const parameterSchemaToPredefine of parametersToPredefine) {
|
|
145
|
-
const parameterToPredefine = findPredefinedOperationParameter(parameterSchemaToPredefine,
|
|
146
|
+
const parameterToPredefine = findPredefinedOperationParameter(parameterSchemaToPredefine,
|
|
147
|
+
// @ts-expect-error the issue with custom OpenAPISchemaType
|
|
148
|
+
operationParameters);
|
|
146
149
|
if (!predefinedPathGlob.methods?.includes(method)) {
|
|
147
150
|
predefinedPathGlob.methods.push(method);
|
|
148
151
|
}
|
|
@@ -204,11 +207,4 @@ export function assertIsOperationObject(operationItem) {
|
|
|
204
207
|
throw new Error(`Expected a OperationObject, but got a ReferenceObject: ${operationItem}`);
|
|
205
208
|
}
|
|
206
209
|
}
|
|
207
|
-
export function assertIsParameterObjects(parameterObjects) {
|
|
208
|
-
parameterObjects.forEach((parameterObject) => {
|
|
209
|
-
if ('$ref' in parameterObject) {
|
|
210
|
-
throw new Error(`Expected a ParameterObject, but got a ReferenceObject: ${parameterObject}`);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
210
|
//# sourceMappingURL=predefineSchemaParameters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predefineSchemaParameters.js","sourceRoot":"","sources":["../../src/lib/predefineSchemaParameters.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,UAAU,yBAAyB,CACvC,MAAgB,EAChB,yBAAqD;IAErD,MAAM,qBAAqB,GAAwB,EAAE,CAAC;IAEtD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC;YAAE,SAAS;QAExE,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEnC,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAEhC,qBAAqB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QAE7C,KAAK,MAAM,OAAO,IAAI,OAAO,EAAE,CAAC;YAC9B,MAAM,MAAM,GAAG,OAA+B,CAAC;YAC/C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;gBAAE,SAAS;YAErE,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;YAClC,uBAAuB,CAAC,SAAS,CAAC,CAAC;YAEnC,KAAK,MAAM,wBAAwB,IAAI,yBAAyB,EAAE,CAAC;gBACjE,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI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S,gCAAgC,CACvC,0BAAwD,EACxD,mBAA2C;IAE3C,OAAO,mBAAmB,CAAC,IAAI,CAC7B,CAAC,kBAAkB,EAAE,EAAE,CACrB,kBAAkB,CAAC,EAAE,KAAK,0BAA0B,CAAC,EAAE;QACvD,kBAAkB,CAAC,IAAI,KAAK,0BAA0B,CAAC,IAAI,CAC9D,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B,CAAC,CAAkB,EAAE,CAAkB;IACxE,IAAI,QAAQ,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC;QAChC,OAAO,QAAQ,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC;AAC/E,CAAC;AAED,SAAS,sBAAsB,CAC7B,QAA0C;IAE1C,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,yDAAyD,QAAQ,EAAE,CACpE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,aAAgD;IAEhD,IAAI,MAAM,IAAI,aAAa,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,0DAA0D,aAAa,EAAE,CAC1E,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OpenAPIService } from './open-api/OpenAPIService.js';
|
|
2
2
|
import { OperationGlobMethods } from './parseOperationGlobs.js';
|
|
3
|
-
export declare const processOperationNameModifierOption: (modifiers: OperationNameModifier[], services:
|
|
4
|
-
errors: {
|
|
3
|
+
export declare const processOperationNameModifierOption: (modifiers: OperationNameModifier[], services: OpenAPIService[]) => {
|
|
4
|
+
errors: ({
|
|
5
|
+
type: "conflictingOperationNameModifier";
|
|
5
6
|
serviceName: string;
|
|
6
7
|
replacedOperationName: string;
|
|
7
8
|
originalOperationName: string | undefined;
|
|
8
9
|
modifiers: OperationNameModifier[];
|
|
9
|
-
}
|
|
10
|
+
} | {
|
|
11
|
+
type: "unusedOperationNameModifier";
|
|
12
|
+
modifier: OperationNameModifier;
|
|
13
|
+
})[];
|
|
10
14
|
services: {
|
|
11
|
-
operations: import("./open-api/
|
|
15
|
+
operations: import("./open-api/OpenAPIService.js").ServiceOperation[];
|
|
12
16
|
name: string;
|
|
13
17
|
variableName: string;
|
|
14
18
|
typeName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processOperationNameModifierOption.d.ts","sourceRoot":"","sources":["../../src/lib/processOperationNameModifierOption.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"processOperationNameModifierOption.d.ts","sourceRoot":"","sources":["../../src/lib/processOperationNameModifierOption.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EACL,oBAAoB,EAErB,MAAM,0BAA0B,CAAC;AAGlC,eAAO,MAAM,kCAAkC,cAClC,qBAAqB,EAAE,YACxB,cAAc,EAAE;;cAiGd,kCAAkC;qBAC3B,MAAM;+BACI,MAAM;+BACN,MAAM,GAAG,SAAS;mBAC9B,qBAAqB,EAAE;;cAG5B,6BAA6B;kBACzB,qBAAqB;;;;;;;;;CAwDtC,CAAC;AAMF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,oBAAoB,EAAE,GAAG,SAAS,CAAC;IAC5C;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,0BAA0B,EAAE,MAAM,CAAC;IACnC;;OAEG;IACH,4BAA4B,EAAE,MAAM,CAAC;CACtC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,GAAG,WAAW,EAAE,MAAM,EAAE,GACvB,qBAAqB,EAAE,CAwCzB"}
|
|
@@ -8,26 +8,30 @@ export const processOperationNameModifierOption = (modifiers, services) => {
|
|
|
8
8
|
errors: [],
|
|
9
9
|
services,
|
|
10
10
|
};
|
|
11
|
-
const
|
|
11
|
+
const availableOperationNameModifiers = modifiers.map((modifier) => ({
|
|
12
12
|
...modifier,
|
|
13
13
|
isPathMatch: createServicePathMatch(splitCommaSeparatedGlobs(modifier.pathGlobs)),
|
|
14
14
|
}));
|
|
15
15
|
const serviceOperationReplacements = new Map();
|
|
16
|
+
const processedOperationNameModifiers = new Set();
|
|
16
17
|
for (const service of services) {
|
|
17
18
|
serviceOperationReplacements.set(service.name, new Map());
|
|
18
19
|
for (const operation of service.operations) {
|
|
19
20
|
const operationReplacements = serviceOperationReplacements.get(service.name);
|
|
20
21
|
if (!operationReplacements)
|
|
21
22
|
throw new Error('operationReplacements not found');
|
|
22
|
-
const
|
|
23
|
+
const operationNameModifiers = availableOperationNameModifiers.filter((modifier) => modifier.isPathMatch(operation.path) &&
|
|
23
24
|
(modifier.methods === undefined ||
|
|
24
25
|
modifier.methods.includes(operation.method)) &&
|
|
25
26
|
normalizeOperationNameModifierRegex(modifier.operationNameModifierRegex).test(operation.name));
|
|
26
|
-
const replacedOperationName = getOperationIdName(
|
|
27
|
+
const replacedOperationName = getOperationIdName(operationNameModifiers.reduce((operationNameAcc, modifier) => {
|
|
28
|
+
processedOperationNameModifiers.add(modifier);
|
|
29
|
+
return operationNameAcc.replace(normalizeOperationNameModifierRegex(modifier.operationNameModifierRegex), modifier.operationNameModifierReplace);
|
|
30
|
+
}, operation.name));
|
|
27
31
|
if (replacedOperationName !== operation.name) {
|
|
28
32
|
if (!operationReplacements.has(replacedOperationName))
|
|
29
33
|
operationReplacements.set(replacedOperationName, new Map());
|
|
30
|
-
operationReplacements.get(replacedOperationName)?.set(operation.name,
|
|
34
|
+
operationReplacements.get(replacedOperationName)?.set(operation.name, operationNameModifiers.map(({ isPathMatch: _, ...operationModifiersRest }) => operationModifiersRest));
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
}
|
|
@@ -48,6 +52,7 @@ export const processOperationNameModifierOption = (modifiers, services) => {
|
|
|
48
52
|
const errors = Array.from(serviceOperationReplacements).flatMap(([serviceName, modifiedOperations]) => Array.from(modifiedOperations).flatMap(([replacedOperationName, operationModifierMap]) => {
|
|
49
53
|
if (operationModifierMap.size > 1) {
|
|
50
54
|
return Array.from(operationModifierMap).map(([originalOperationName, modifiers]) => ({
|
|
55
|
+
type: 'conflictingOperationNameModifier',
|
|
51
56
|
serviceName,
|
|
52
57
|
replacedOperationName,
|
|
53
58
|
originalOperationName,
|
|
@@ -58,6 +63,7 @@ export const processOperationNameModifierOption = (modifiers, services) => {
|
|
|
58
63
|
if (modifiers && modifiers.length > 1) {
|
|
59
64
|
return [
|
|
60
65
|
{
|
|
66
|
+
type: 'conflictingOperationNameModifier',
|
|
61
67
|
serviceName,
|
|
62
68
|
replacedOperationName,
|
|
63
69
|
originalOperationName,
|
|
@@ -67,6 +73,19 @@ export const processOperationNameModifierOption = (modifiers, services) => {
|
|
|
67
73
|
}
|
|
68
74
|
return [];
|
|
69
75
|
}));
|
|
76
|
+
availableOperationNameModifiers.forEach((modifier) => {
|
|
77
|
+
if (!processedOperationNameModifiers.has(modifier)) {
|
|
78
|
+
errors.push({
|
|
79
|
+
type: 'unusedOperationNameModifier',
|
|
80
|
+
modifier: {
|
|
81
|
+
methods: modifier.methods,
|
|
82
|
+
pathGlobs: modifier.pathGlobs,
|
|
83
|
+
operationNameModifierRegex: modifier.operationNameModifierRegex,
|
|
84
|
+
operationNameModifierReplace: modifier.operationNameModifierReplace,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
70
89
|
return {
|
|
71
90
|
errors,
|
|
72
91
|
services: replacedOperationNamesServices,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processOperationNameModifierOption.js","sourceRoot":"","sources":["../../src/lib/processOperationNameModifierOption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,SAAkC,EAClC,
|
|
1
|
+
{"version":3,"file":"processOperationNameModifierOption.js","sourceRoot":"","sources":["../../src/lib/processOperationNameModifierOption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,SAAkC,EAClC,QAA0B,EAC1B,EAAE;IACF,IAAI,CAAC,SAAS,CAAC,MAAM;QACnB,OAAO;YACL,MAAM,EAAE,EAAE;YACV,QAAQ;SACT,CAAC;IAEJ,MAAM,+BAA+B,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnE,GAAG,QAAQ;QACX,WAAW,EAAE,sBAAsB,CACjC,wBAAwB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAC7C;KACF,CAAC,CAAC,CAAC;IAMJ,MAAM,4BAA4B,GAAG,IAAI,GAAG,EAMzC,CAAC;IAEJ,MAAM,+BAA+B,GAAG,IAAI,GAAG,EAA8B,CAAC;IAE9E,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,4BAA4B,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QAE1D,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YAC3C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,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CACrC,CAAC;QAEF,IAAI,CAAC,iBAAiB,CAAC,MAAM;YAC3B,MAAM,IAAI,KAAK,CACb,oCAAoC,UAAU,oGAAoG,CACnJ,CAAC;QAEJ,MAAM,eAAe,GAAG,UAAU,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAEvE,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CACxC,CAAC,EACD,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAC/B,CAAC;QACF,MAAM,cAAc,GAAG,eAAe,CAAC,KAAK,CAC1C,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAClD,CAAC;QAEF,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;QAEtE,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC,MAAM;YAC7C,MAAM,IAAI,KAAK,CACb,sBAAsB,SAAS,4CAA4C,CAC5E,CAAC;QAEJ,4BAA4B,CAAC,IAAI,CAAC;YAChC,OAAO;YACP,SAAS;YACT,0BAA0B,EAAE,YAAY,CAAC,IAAI,EAAE;YAC/C,4BAA4B,EAAE,cAAc,CAAC,IAAI,EAAE;SACpD,CAAC,CAAC;IACL,CAAC;IAED,OAAO,4BAA4B,CAAC;AACtC,CAAC"}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const packageVersion = "2.0.
|
|
1
|
+
export declare const packageVersion = "2.0.1-beta.0";
|
|
2
2
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1-beta.0",
|
|
4
4
|
"packageManager": "yarn@4.0.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -37,11 +37,20 @@
|
|
|
37
37
|
"@openapi-qraft/test-fixtures": "1.0.0",
|
|
38
38
|
"@types/micromatch": "^4.0.9",
|
|
39
39
|
"@types/node": "^20.16.5",
|
|
40
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
40
41
|
"commander": "^11.1.0",
|
|
41
|
-
"eslint": "^9.
|
|
42
|
+
"eslint": "^9.16.0",
|
|
42
43
|
"rimraf": "^5.0.10",
|
|
43
44
|
"typescript": "^5.6.2",
|
|
44
|
-
"vitest": "^1.
|
|
45
|
+
"vitest": "^2.1.8"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"commander": "^11.1.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"commander": {
|
|
52
|
+
"optional": false
|
|
53
|
+
}
|
|
45
54
|
},
|
|
46
55
|
"files": [
|
|
47
56
|
"dist",
|
package/src/index.ts
CHANGED
package/src/lib/QraftCommand.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Option } from 'commander';
|
|
2
|
-
import type { Service } from './open-api/getServices.js';
|
|
3
2
|
import { sep } from 'node:path';
|
|
4
3
|
import process from 'node:process';
|
|
5
4
|
import { pathToFileURL, URL } from 'node:url';
|
|
@@ -12,6 +11,7 @@ import { GeneratorFile } from './GeneratorFile.js';
|
|
|
12
11
|
import { handleSchemaInput } from './handleSchemaInput.js';
|
|
13
12
|
import { getServices } from './open-api/getServices.js';
|
|
14
13
|
import { OpenAPISchemaType } from './open-api/OpenAPISchemaType.js';
|
|
14
|
+
import { OpenAPIService } from './open-api/OpenAPIService.js';
|
|
15
15
|
import { readSchema } from './open-api/readSchema.js';
|
|
16
16
|
import { OutputOptions } from './OutputOptions.js';
|
|
17
17
|
import {
|
|
@@ -151,26 +151,37 @@ export class QraftCommand extends Command {
|
|
|
151
151
|
|
|
152
152
|
if (operationNameModifierErrors.length) {
|
|
153
153
|
operationNameModifierErrors.forEach((error) => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
.
|
|
162
|
-
(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
154
|
+
if (error.type === 'conflictingOperationNameModifier') {
|
|
155
|
+
spinner.fail(
|
|
156
|
+
[
|
|
157
|
+
c.red.bold(
|
|
158
|
+
`Error occurred during operation name modifier setup: '${error.serviceName}.${error.originalOperationName}' to '${error.replacedOperationName}'`
|
|
159
|
+
),
|
|
160
|
+
c.yellow(
|
|
161
|
+
error.modifiers
|
|
162
|
+
.map(
|
|
163
|
+
({
|
|
164
|
+
pathGlobs,
|
|
165
|
+
operationNameModifierRegex,
|
|
166
|
+
operationNameModifierReplace,
|
|
167
|
+
}) =>
|
|
168
|
+
`Conflicting operation name modifier: '${pathGlobs}': '${operationNameModifierRegex}' => '${operationNameModifierReplace}'`
|
|
169
|
+
)
|
|
170
|
+
.join('\n')
|
|
171
|
+
),
|
|
172
|
+
].join('\n')
|
|
173
|
+
);
|
|
174
|
+
} else if (error.type === 'unusedOperationNameModifier') {
|
|
175
|
+
spinner.fail(
|
|
176
|
+
[
|
|
177
|
+
c.yellow.bold(
|
|
178
|
+
`Unused operation name modifier: '${error.modifier.pathGlobs}': '${error.modifier.operationNameModifierRegex}' => '${error.modifier.operationNameModifierReplace}'`
|
|
179
|
+
),
|
|
180
|
+
].join('\n')
|
|
181
|
+
);
|
|
182
|
+
}
|
|
173
183
|
});
|
|
184
|
+
|
|
174
185
|
process.exit(1);
|
|
175
186
|
}
|
|
176
187
|
|
|
@@ -366,7 +377,7 @@ export type QraftCommandActionCallback = (
|
|
|
366
377
|
/**
|
|
367
378
|
* OpenAPI services
|
|
368
379
|
*/
|
|
369
|
-
services:
|
|
380
|
+
services: OpenAPIService[];
|
|
370
381
|
/**
|
|
371
382
|
* OpenAPI schema
|
|
372
383
|
*/
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { OpenAPISchemaType } from './OpenAPISchemaType.js';
|
|
2
|
+
|
|
3
|
+
export type OpenAPIService = {
|
|
4
|
+
name: string;
|
|
5
|
+
variableName: string;
|
|
6
|
+
typeName: string;
|
|
7
|
+
fileBaseName: string;
|
|
8
|
+
operations: ServiceOperation[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ServiceOperation = {
|
|
12
|
+
method:
|
|
13
|
+
| 'get'
|
|
14
|
+
| 'put'
|
|
15
|
+
| 'post'
|
|
16
|
+
| 'patch'
|
|
17
|
+
| 'delete'
|
|
18
|
+
| 'options'
|
|
19
|
+
| 'head'
|
|
20
|
+
| 'trace';
|
|
21
|
+
path: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description: string | undefined;
|
|
24
|
+
summary: string | undefined;
|
|
25
|
+
deprecated: boolean | undefined;
|
|
26
|
+
errors: Record<string, string | undefined>;
|
|
27
|
+
requestBody: OpenAPISchemaType['paths'][string]['post']['requestBody'];
|
|
28
|
+
success: Record<string, string | undefined>;
|
|
29
|
+
parameters:
|
|
30
|
+
| {
|
|
31
|
+
name: string;
|
|
32
|
+
in: 'header' | 'query' | 'cookie';
|
|
33
|
+
description: string;
|
|
34
|
+
required: boolean;
|
|
35
|
+
schema: any;
|
|
36
|
+
example: string | undefined;
|
|
37
|
+
}[]
|
|
38
|
+
| undefined;
|
|
39
|
+
security: Array<Record<string, string[] | undefined>> | undefined;
|
|
40
|
+
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ServiceBaseNameByEndpointOption } from './getServiceNamesByOperationEndpoint.js';
|
|
2
|
+
import type { ServiceBaseName } from './getServices.js';
|
|
3
|
+
import camelcase from 'camelcase';
|
|
4
|
+
import { getEndpointPartIndex } from './getServiceNamesByOperationEndpoint.js';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* Convert the input value to a correct operation (method) classname.
|
|
@@ -8,23 +11,47 @@ import camelCase from 'camelcase';
|
|
|
8
11
|
export const getOperationName = (
|
|
9
12
|
url: string,
|
|
10
13
|
method: string,
|
|
11
|
-
operationId: string | undefined
|
|
14
|
+
operationId: string | undefined,
|
|
15
|
+
serviceNameBase: ServiceBaseName
|
|
12
16
|
): string => {
|
|
13
17
|
if (operationId) return getOperationIdName(operationId);
|
|
14
18
|
|
|
15
|
-
const urlWithoutPlaceholders =
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
const urlWithoutPlaceholders = (
|
|
20
|
+
serviceNameBase === 'tags'
|
|
21
|
+
? url
|
|
22
|
+
: reduceUrlByEndpointPartIndex(url, serviceNameBase)
|
|
23
|
+
)
|
|
24
|
+
.replace(/{(.*?)}/g, '$1')
|
|
18
25
|
.replace(/\//g, '-');
|
|
19
26
|
|
|
20
|
-
return
|
|
27
|
+
return camelcase(`${method}-${urlWithoutPlaceholders}`);
|
|
21
28
|
};
|
|
22
29
|
|
|
23
30
|
export const getOperationIdName = (operationId: string): string => {
|
|
24
|
-
return
|
|
31
|
+
return camelcase(
|
|
25
32
|
operationId
|
|
26
33
|
.replace(/^[^a-zA-Z]+/g, '')
|
|
27
34
|
.replace(/[^\w-]+/g, '-')
|
|
28
35
|
.trim()
|
|
29
36
|
);
|
|
30
37
|
};
|
|
38
|
+
|
|
39
|
+
export const reduceUrlByEndpointPartIndex = (
|
|
40
|
+
url: string,
|
|
41
|
+
serviceNameBase: ServiceBaseNameByEndpointOption
|
|
42
|
+
) => {
|
|
43
|
+
const pathSegments = (url.startsWith('/') ? url.slice(1) : url).split('/');
|
|
44
|
+
|
|
45
|
+
// skip the first segment
|
|
46
|
+
const pathOperationNameStartIndex = getEndpointPartIndex(serviceNameBase) + 1;
|
|
47
|
+
|
|
48
|
+
if (pathSegments.length + 1 <= pathOperationNameStartIndex) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Invalid service name base '${serviceNameBase}'. The path '${url}' does not contain enough segments to generate a service name.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const reducedPath = pathSegments.slice(pathOperationNameStartIndex).join('/');
|
|
55
|
+
|
|
56
|
+
return url.startsWith('/') ? `/${reducedPath}` : reducedPath;
|
|
57
|
+
};
|
|
@@ -7,50 +7,23 @@ import {
|
|
|
7
7
|
ServiceBaseNameByEndpointOption,
|
|
8
8
|
} from './getServiceNamesByOperationEndpoint.js';
|
|
9
9
|
import { getServiceNamesByOperationTags } from './getServiceNamesByOperationTags.js';
|
|
10
|
+
import {
|
|
11
|
+
OpenAPIService,
|
|
12
|
+
ServiceOperation as ServiceOperationStable,
|
|
13
|
+
} from './OpenAPIService.js';
|
|
14
|
+
import { replaceRefParametersWithComponent } from './replaceRefParametersWithComponent.js';
|
|
10
15
|
|
|
11
16
|
export type ServiceBaseName = ServiceBaseNameByEndpointOption | 'tags';
|
|
12
17
|
|
|
13
18
|
/**
|
|
14
|
-
* @deprecated
|
|
19
|
+
* @deprecated use `OpenAPIService` instead from './OpenAPIService.js'
|
|
15
20
|
*/
|
|
16
|
-
export type Service =
|
|
17
|
-
name: string;
|
|
18
|
-
variableName: string;
|
|
19
|
-
typeName: string;
|
|
20
|
-
fileBaseName: string;
|
|
21
|
-
operations: ServiceOperation[];
|
|
22
|
-
};
|
|
21
|
+
export type Service = OpenAPIService;
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
| 'post'
|
|
29
|
-
| 'patch'
|
|
30
|
-
| 'delete'
|
|
31
|
-
| 'options'
|
|
32
|
-
| 'head'
|
|
33
|
-
| 'trace';
|
|
34
|
-
path: string;
|
|
35
|
-
name: string;
|
|
36
|
-
description: string | undefined;
|
|
37
|
-
summary: string | undefined;
|
|
38
|
-
deprecated: boolean | undefined;
|
|
39
|
-
mediaType: string | undefined;
|
|
40
|
-
errors: Record<string, string | undefined>;
|
|
41
|
-
success: Record<string, string | undefined>;
|
|
42
|
-
parameters:
|
|
43
|
-
| {
|
|
44
|
-
name: string;
|
|
45
|
-
in: 'header' | 'query' | 'cookie';
|
|
46
|
-
description: string;
|
|
47
|
-
required: boolean;
|
|
48
|
-
schema: any;
|
|
49
|
-
example: string | undefined;
|
|
50
|
-
}[]
|
|
51
|
-
| undefined;
|
|
52
|
-
security: Array<Record<string, string[] | undefined>> | undefined;
|
|
53
|
-
};
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated use `ServiceOperation` instead from './OpenAPIService.js'
|
|
25
|
+
*/
|
|
26
|
+
export type ServiceOperation = ServiceOperationStable;
|
|
54
27
|
|
|
55
28
|
export interface ServiceOutputOptions {
|
|
56
29
|
postfixServices?: string; // todo::rename to `postfixService`
|
|
@@ -65,8 +38,9 @@ export const getServices = (
|
|
|
65
38
|
}: ServiceOutputOptions = {}
|
|
66
39
|
) => {
|
|
67
40
|
const paths = openApiJson.paths;
|
|
41
|
+
const parametersComponents = openApiJson.components.parameters ?? {};
|
|
68
42
|
|
|
69
|
-
const services = new Map<string,
|
|
43
|
+
const services = new Map<string, OpenAPIService>();
|
|
70
44
|
|
|
71
45
|
for (const path in paths) {
|
|
72
46
|
if (!Object.prototype.hasOwnProperty.call(paths, path)) continue;
|
|
@@ -141,18 +115,21 @@ export const getServices = (
|
|
|
141
115
|
method,
|
|
142
116
|
path,
|
|
143
117
|
errors,
|
|
144
|
-
name: getOperationName(
|
|
118
|
+
name: getOperationName(
|
|
119
|
+
path,
|
|
120
|
+
method,
|
|
121
|
+
methodOperation.operationId,
|
|
122
|
+
serviceNameBase
|
|
123
|
+
),
|
|
145
124
|
description: methodOperation.description,
|
|
146
125
|
summary: methodOperation.summary,
|
|
147
126
|
deprecated: methodOperation.deprecated,
|
|
148
|
-
parameters:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
? getContentMediaType(methodOperation.requestBody.content)
|
|
155
|
-
: undefined,
|
|
127
|
+
parameters: replaceRefParametersWithComponent(
|
|
128
|
+
// @ts-expect-error the issue with custom OpenAPISchemaType
|
|
129
|
+
methodOperation.parameters,
|
|
130
|
+
parametersComponents
|
|
131
|
+
),
|
|
132
|
+
requestBody: methodOperation.requestBody,
|
|
156
133
|
success: success,
|
|
157
134
|
security: methodOperation.security,
|
|
158
135
|
});
|
|
@@ -179,4 +156,4 @@ const supportedHTTPMethods = Object.values({
|
|
|
179
156
|
options: 'options',
|
|
180
157
|
head: 'head',
|
|
181
158
|
trace: 'trace',
|
|
182
|
-
} satisfies { [key in
|
|
159
|
+
} satisfies { [key in ServiceOperationStable['method']]: key });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { OpenAPISchemaType } from './OpenAPISchemaType.js';
|
|
2
|
+
import { ParameterObject } from 'openapi-typescript';
|
|
3
|
+
import { ReferenceObject } from 'openapi-typescript/src/types.js';
|
|
4
|
+
|
|
5
|
+
export function replaceRefParametersWithComponent(
|
|
6
|
+
parameters: ParameterObject | ReferenceObject | undefined,
|
|
7
|
+
parametersComponents: OpenAPISchemaType['components']['parameters']
|
|
8
|
+
) {
|
|
9
|
+
if (!Array.isArray(parameters)) return undefined;
|
|
10
|
+
|
|
11
|
+
const definedParameters = parameters
|
|
12
|
+
.map((parameter) => {
|
|
13
|
+
if (parameter.$ref)
|
|
14
|
+
return getParametersComponentByRef(
|
|
15
|
+
parameter.$ref,
|
|
16
|
+
parametersComponents
|
|
17
|
+
);
|
|
18
|
+
return parameter;
|
|
19
|
+
})
|
|
20
|
+
.filter(Boolean);
|
|
21
|
+
|
|
22
|
+
if (!definedParameters.length) return undefined;
|
|
23
|
+
|
|
24
|
+
return definedParameters;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get the operation from the $ref
|
|
29
|
+
* @param $ref Example: `#/components/parameters/Export`
|
|
30
|
+
* @param parameters
|
|
31
|
+
*/
|
|
32
|
+
function getParametersComponentByRef(
|
|
33
|
+
$ref: string,
|
|
34
|
+
parameters: OpenAPISchemaType['components']['parameters']
|
|
35
|
+
) {
|
|
36
|
+
const refPath = $ref.split('/').slice(1);
|
|
37
|
+
if (refPath[1] === 'parameters') {
|
|
38
|
+
return parameters?.[refPath[2]];
|
|
39
|
+
}
|
|
40
|
+
}
|