@openapi-qraft/plugin 2.0.0-next.9 → 2.0.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 +105 -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.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/package.json +4 -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
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
ReferenceObject,
|
|
6
6
|
} from 'openapi-typescript/src/types.js';
|
|
7
7
|
import { createServicePathMatch } from './createServicePathMatch.js';
|
|
8
|
+
import { replaceRefParametersWithComponent } from './open-api/replaceRefParametersWithComponent.js';
|
|
8
9
|
import {
|
|
9
10
|
OperationGlobMethods,
|
|
10
11
|
parseOperationGlobs,
|
|
@@ -43,12 +44,12 @@ export function predefineSchemaParameters(
|
|
|
43
44
|
const predefinedOperation = predefinedPathItem?.[method];
|
|
44
45
|
if (predefinedOperation) assertIsOperationObject(predefinedOperation);
|
|
45
46
|
|
|
46
|
-
const operationParameters =
|
|
47
|
-
predefinedOperation?.parameters ?? operation.parameters
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
const operationParameters = replaceRefParametersWithComponent(
|
|
48
|
+
predefinedOperation?.parameters ?? operation.parameters,
|
|
49
|
+
schema.components?.parameters
|
|
50
|
+
);
|
|
50
51
|
|
|
51
|
-
const predefinedParameters = operationParameters
|
|
52
|
+
const predefinedParameters = operationParameters?.map(
|
|
52
53
|
(operationParameter) => {
|
|
53
54
|
if (
|
|
54
55
|
findPredefinedOperationParameter(
|
|
@@ -204,8 +205,11 @@ export function createPredefinedParametersGlobs(
|
|
|
204
205
|
|
|
205
206
|
assertIsOperationObject(operation);
|
|
206
207
|
|
|
207
|
-
const operationParameters =
|
|
208
|
-
|
|
208
|
+
const operationParameters = replaceRefParametersWithComponent(
|
|
209
|
+
// @ts-expect-error the issue with custom OpenAPISchemaType
|
|
210
|
+
operation.parameters,
|
|
211
|
+
schema.components?.parameters
|
|
212
|
+
);
|
|
209
213
|
|
|
210
214
|
const predefinedParametersGlobKey = createOperationGlobsKey(
|
|
211
215
|
pathGlobs,
|
|
@@ -231,6 +235,7 @@ export function createPredefinedParametersGlobs(
|
|
|
231
235
|
for (const parameterSchemaToPredefine of parametersToPredefine) {
|
|
232
236
|
const parameterToPredefine = findPredefinedOperationParameter(
|
|
233
237
|
parameterSchemaToPredefine,
|
|
238
|
+
// @ts-expect-error the issue with custom OpenAPISchemaType
|
|
234
239
|
operationParameters
|
|
235
240
|
);
|
|
236
241
|
|
|
@@ -341,18 +346,6 @@ export function assertIsOperationObject(
|
|
|
341
346
|
}
|
|
342
347
|
}
|
|
343
348
|
|
|
344
|
-
export function assertIsParameterObjects(
|
|
345
|
-
parameterObjects: Array<ParameterObject | ReferenceObject>
|
|
346
|
-
): asserts parameterObjects is Array<ParameterObject> {
|
|
347
|
-
parameterObjects.forEach((parameterObject) => {
|
|
348
|
-
if ('$ref' in parameterObject) {
|
|
349
|
-
throw new Error(
|
|
350
|
-
`Expected a ParameterObject, but got a ReferenceObject: ${parameterObject}`
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
|
|
356
349
|
type ParsedPredefinedParametersOption = {
|
|
357
350
|
methods: OperationGlobMethods[] | undefined;
|
|
358
351
|
pathGlobs: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createServicePathMatch } from './createServicePathMatch.js';
|
|
2
2
|
import { getOperationIdName } from './open-api/getOperationName.js';
|
|
3
|
-
import {
|
|
3
|
+
import { OpenAPIService } from './open-api/OpenAPIService.js';
|
|
4
4
|
import {
|
|
5
5
|
OperationGlobMethods,
|
|
6
6
|
parseOperationGlobs,
|
|
@@ -9,7 +9,7 @@ import { splitCommaSeparatedGlobs } from './splitCommaSeparatedGlobs.js';
|
|
|
9
9
|
|
|
10
10
|
export const processOperationNameModifierOption = (
|
|
11
11
|
modifiers: OperationNameModifier[],
|
|
12
|
-
services:
|
|
12
|
+
services: OpenAPIService[]
|
|
13
13
|
) => {
|
|
14
14
|
if (!modifiers.length)
|
|
15
15
|
return {
|
|
@@ -17,7 +17,7 @@ export const processOperationNameModifierOption = (
|
|
|
17
17
|
services,
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const
|
|
20
|
+
const availableOperationNameModifiers = modifiers.map((modifier) => ({
|
|
21
21
|
...modifier,
|
|
22
22
|
isPathMatch: createServicePathMatch(
|
|
23
23
|
splitCommaSeparatedGlobs(modifier.pathGlobs)
|
|
@@ -36,6 +36,8 @@ export const processOperationNameModifierOption = (
|
|
|
36
36
|
>
|
|
37
37
|
>();
|
|
38
38
|
|
|
39
|
+
const processedOperationNameModifiers = new Set<(typeof modifiers)[number]>();
|
|
40
|
+
|
|
39
41
|
for (const service of services) {
|
|
40
42
|
serviceOperationReplacements.set(service.name, new Map());
|
|
41
43
|
|
|
@@ -47,7 +49,7 @@ export const processOperationNameModifierOption = (
|
|
|
47
49
|
if (!operationReplacements)
|
|
48
50
|
throw new Error('operationReplacements not found');
|
|
49
51
|
|
|
50
|
-
const
|
|
52
|
+
const operationNameModifiers = availableOperationNameModifiers.filter(
|
|
51
53
|
(modifier) =>
|
|
52
54
|
modifier.isPathMatch(operation.path) &&
|
|
53
55
|
(modifier.methods === undefined ||
|
|
@@ -58,16 +60,16 @@ export const processOperationNameModifierOption = (
|
|
|
58
60
|
);
|
|
59
61
|
|
|
60
62
|
const replacedOperationName = getOperationIdName(
|
|
61
|
-
|
|
62
|
-
(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
modifier.operationNameModifierReplace
|
|
63
|
+
operationNameModifiers.reduce((operationNameAcc, modifier) => {
|
|
64
|
+
processedOperationNameModifiers.add(modifier);
|
|
65
|
+
|
|
66
|
+
return operationNameAcc.replace(
|
|
67
|
+
normalizeOperationNameModifierRegex(
|
|
68
|
+
modifier.operationNameModifierRegex
|
|
68
69
|
),
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
modifier.operationNameModifierReplace
|
|
71
|
+
);
|
|
72
|
+
}, operation.name)
|
|
71
73
|
);
|
|
72
74
|
|
|
73
75
|
if (replacedOperationName !== operation.name) {
|
|
@@ -75,7 +77,7 @@ export const processOperationNameModifierOption = (
|
|
|
75
77
|
operationReplacements.set(replacedOperationName, new Map());
|
|
76
78
|
operationReplacements.get(replacedOperationName)?.set(
|
|
77
79
|
operation.name,
|
|
78
|
-
|
|
80
|
+
operationNameModifiers.map(
|
|
79
81
|
({ isPathMatch: _, ...operationModifiersRest }) =>
|
|
80
82
|
operationModifiersRest
|
|
81
83
|
)
|
|
@@ -102,13 +104,26 @@ export const processOperationNameModifierOption = (
|
|
|
102
104
|
}),
|
|
103
105
|
}));
|
|
104
106
|
|
|
105
|
-
const errors
|
|
107
|
+
const errors: Array<
|
|
108
|
+
| {
|
|
109
|
+
type: 'conflictingOperationNameModifier';
|
|
110
|
+
serviceName: string;
|
|
111
|
+
replacedOperationName: string;
|
|
112
|
+
originalOperationName: string | undefined;
|
|
113
|
+
modifiers: OperationNameModifier[];
|
|
114
|
+
}
|
|
115
|
+
| {
|
|
116
|
+
type: 'unusedOperationNameModifier';
|
|
117
|
+
modifier: OperationNameModifier;
|
|
118
|
+
}
|
|
119
|
+
> = Array.from(serviceOperationReplacements).flatMap(
|
|
106
120
|
([serviceName, modifiedOperations]) =>
|
|
107
121
|
Array.from(modifiedOperations).flatMap(
|
|
108
122
|
([replacedOperationName, operationModifierMap]) => {
|
|
109
123
|
if (operationModifierMap.size > 1) {
|
|
110
124
|
return Array.from(operationModifierMap).map(
|
|
111
125
|
([originalOperationName, modifiers]) => ({
|
|
126
|
+
type: 'conflictingOperationNameModifier',
|
|
112
127
|
serviceName,
|
|
113
128
|
replacedOperationName,
|
|
114
129
|
originalOperationName,
|
|
@@ -123,6 +138,7 @@ export const processOperationNameModifierOption = (
|
|
|
123
138
|
if (modifiers && modifiers.length > 1) {
|
|
124
139
|
return [
|
|
125
140
|
{
|
|
141
|
+
type: 'conflictingOperationNameModifier',
|
|
126
142
|
serviceName,
|
|
127
143
|
replacedOperationName,
|
|
128
144
|
originalOperationName,
|
|
@@ -136,6 +152,20 @@ export const processOperationNameModifierOption = (
|
|
|
136
152
|
)
|
|
137
153
|
);
|
|
138
154
|
|
|
155
|
+
availableOperationNameModifiers.forEach((modifier) => {
|
|
156
|
+
if (!processedOperationNameModifiers.has(modifier)) {
|
|
157
|
+
errors.push({
|
|
158
|
+
type: 'unusedOperationNameModifier',
|
|
159
|
+
modifier: {
|
|
160
|
+
methods: modifier.methods,
|
|
161
|
+
pathGlobs: modifier.pathGlobs,
|
|
162
|
+
operationNameModifierRegex: modifier.operationNameModifierRegex,
|
|
163
|
+
operationNameModifierReplace: modifier.operationNameModifierReplace,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
139
169
|
return {
|
|
140
170
|
errors,
|
|
141
171
|
services: replacedOperationNamesServices,
|
package/src/packageVersion.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file was generated automatically
|
|
2
|
-
export const packageVersion = '2.0.0
|
|
2
|
+
export const packageVersion = '2.0.0';
|