@openapi-qraft/plugin 2.0.0-next.1 → 2.0.0-next.10
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 +45 -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 +8 -4
- package/dist/lib/open-api/getServices.d.ts.map +1 -1
- package/dist/lib/open-api/getServices.js +1 -1
- package/dist/lib/open-api/getServices.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 +9 -9
- package/src/lib/open-api/getOperationName.ts +34 -7
- package/src/lib/open-api/getServices.ts +16 -5
- package/src/packageVersion.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# @openapi-qraft/plugin
|
|
2
2
|
|
|
3
|
+
## 2.0.0-next.10
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 8c77eb2: Generate comprehensive operation names with consideration of the `--service-name-base` option. Operation names now
|
|
8
|
+
include all path parts and parameters, and the structure can be customized based on the `--service-name-base` value.
|
|
9
|
+
|
|
10
|
+
**Breaking Changes:**
|
|
11
|
+
|
|
12
|
+
- Operation names now include all path parts and parameters by default.
|
|
13
|
+
- `/api/v{api-version}` is no longer automatically removed from the path when generating operation names.
|
|
14
|
+
- The `--service-name-base` option now influences the generated operation names with a new structure.
|
|
15
|
+
|
|
16
|
+
**Examples:**
|
|
17
|
+
|
|
18
|
+
- With `--service-name-base=endpoint[0]`:
|
|
19
|
+
`POST /v1/users/{id}` → `api.v1.postUsersId`
|
|
20
|
+
- With `--service-name-base=endpoint[1]`:
|
|
21
|
+
`GET /v1/users/{id}` → `api.users.getId`
|
|
22
|
+
- With `--service-name-base=endpoint[1]`:
|
|
23
|
+
`POST /v1/users/suspend` → `api.users.postSuspend`
|
|
24
|
+
- With `--service-name-base=endpoint[1]`:
|
|
25
|
+
`POST /v1/users/{id}/{key}` → `api.postIdKey`
|
|
26
|
+
- With `--service-name-base=tags`:
|
|
27
|
+
`POST /v1/users/{id}/{key}` → `api.<tag>.postV1UsersIdKey`
|
|
28
|
+
|
|
29
|
+
This change provides more flexibility in operation name generation and allows for better customization based on project
|
|
30
|
+
requirements.
|
|
31
|
+
|
|
32
|
+
## 2.0.0-next.9
|
|
33
|
+
|
|
34
|
+
## 2.0.0-next.8
|
|
35
|
+
|
|
36
|
+
## 2.0.0-next.7
|
|
37
|
+
|
|
38
|
+
## 2.0.0-next.6
|
|
39
|
+
|
|
40
|
+
## 2.0.0-next.5
|
|
41
|
+
|
|
42
|
+
## 2.0.0-next.4
|
|
43
|
+
|
|
44
|
+
## 2.0.0-next.3
|
|
45
|
+
|
|
46
|
+
## 2.0.0-next.2
|
|
47
|
+
|
|
3
48
|
## 2.0.0-next.1
|
|
4
49
|
|
|
5
50
|
### Minor Changes
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { ServiceBaseNameByEndpointOption } from './getServiceNamesByOperationEndpoint.js';
|
|
2
|
+
import type { ServiceBaseName } from './getServices.js';
|
|
1
3
|
/**
|
|
2
4
|
* Convert the input value to a correct operation (method) classname.
|
|
3
5
|
* This will use the operation ID - if available - and otherwise fallback
|
|
4
6
|
* on a generated name from the URL
|
|
5
7
|
*/
|
|
6
|
-
export declare const getOperationName: (url: string, method: string, operationId: string | undefined) => string;
|
|
8
|
+
export declare const getOperationName: (url: string, method: string, operationId: string | undefined, serviceNameBase: ServiceBaseName) => string;
|
|
7
9
|
export declare const getOperationIdName: (operationId: string) => string;
|
|
10
|
+
export declare const reduceUrlByEndpointPartIndex: (url: string, serviceNameBase: ServiceBaseNameByEndpointOption) => string;
|
|
8
11
|
//# sourceMappingURL=getOperationName.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOperationName.d.ts","sourceRoot":"","sources":["../../../src/lib/open-api/getOperationName.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getOperationName.d.ts","sourceRoot":"","sources":["../../../src/lib/open-api/getOperationName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC/F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAIxD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QACtB,MAAM,UACH,MAAM,eACD,MAAM,GAAG,SAAS,mBACd,eAAe,KAC/B,MAYF,CAAC;AAEF,eAAO,MAAM,kBAAkB,gBAAiB,MAAM,KAAG,MAOxD,CAAC;AAEF,eAAO,MAAM,4BAA4B,QAClC,MAAM,mBACM,+BAA+B,WAgBjD,CAAC"}
|
|
@@ -1,22 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import camelcase from 'camelcase';
|
|
2
|
+
import { getEndpointPartIndex } from './getServiceNamesByOperationEndpoint.js';
|
|
2
3
|
/**
|
|
3
4
|
* Convert the input value to a correct operation (method) classname.
|
|
4
5
|
* This will use the operation ID - if available - and otherwise fallback
|
|
5
6
|
* on a generated name from the URL
|
|
6
7
|
*/
|
|
7
|
-
export const getOperationName = (url, method, operationId) => {
|
|
8
|
+
export const getOperationName = (url, method, operationId, serviceNameBase) => {
|
|
8
9
|
if (operationId)
|
|
9
10
|
return getOperationIdName(operationId);
|
|
10
|
-
const urlWithoutPlaceholders =
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const urlWithoutPlaceholders = (serviceNameBase === 'tags'
|
|
12
|
+
? url
|
|
13
|
+
: reduceUrlByEndpointPartIndex(url, serviceNameBase))
|
|
14
|
+
.replace(/{(.*?)}/g, '$1')
|
|
13
15
|
.replace(/\//g, '-');
|
|
14
|
-
return
|
|
16
|
+
return camelcase(`${method}-${urlWithoutPlaceholders}`);
|
|
15
17
|
};
|
|
16
18
|
export const getOperationIdName = (operationId) => {
|
|
17
|
-
return
|
|
19
|
+
return camelcase(operationId
|
|
18
20
|
.replace(/^[^a-zA-Z]+/g, '')
|
|
19
21
|
.replace(/[^\w-]+/g, '-')
|
|
20
22
|
.trim());
|
|
21
23
|
};
|
|
24
|
+
export const reduceUrlByEndpointPartIndex = (url, serviceNameBase) => {
|
|
25
|
+
const pathSegments = (url.startsWith('/') ? url.slice(1) : url).split('/');
|
|
26
|
+
// skip the first segment
|
|
27
|
+
const pathOperationNameStartIndex = getEndpointPartIndex(serviceNameBase) + 1;
|
|
28
|
+
if (pathSegments.length + 1 <= pathOperationNameStartIndex) {
|
|
29
|
+
throw new Error(`Invalid service name base '${serviceNameBase}'. The path '${url}' does not contain enough segments to generate a service name.`);
|
|
30
|
+
}
|
|
31
|
+
const reducedPath = pathSegments.slice(pathOperationNameStartIndex).join('/');
|
|
32
|
+
return url.startsWith('/') ? `/${reducedPath}` : reducedPath;
|
|
33
|
+
};
|
|
22
34
|
//# sourceMappingURL=getOperationName.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOperationName.js","sourceRoot":"","sources":["../../../src/lib/open-api/getOperationName.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getOperationName.js","sourceRoot":"","sources":["../../../src/lib/open-api/getOperationName.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,GAAW,EACX,MAAc,EACd,WAA+B,EAC/B,eAAgC,EACxB,EAAE;IACV,IAAI,WAAW;QAAE,OAAO,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAExD,MAAM,sBAAsB,GAAG,CAC7B,eAAe,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C,CAAC"}
|
|
@@ -11,9 +11,6 @@ export type Service = {
|
|
|
11
11
|
fileBaseName: string;
|
|
12
12
|
operations: ServiceOperation[];
|
|
13
13
|
};
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated move to separate file
|
|
16
|
-
*/
|
|
17
14
|
export type ServiceOperation = {
|
|
18
15
|
method: 'get' | 'put' | 'post' | 'patch' | 'delete' | 'options' | 'head' | 'trace';
|
|
19
16
|
path: string;
|
|
@@ -24,7 +21,14 @@ export type ServiceOperation = {
|
|
|
24
21
|
mediaType: string | undefined;
|
|
25
22
|
errors: Record<string, string | undefined>;
|
|
26
23
|
success: Record<string, string | undefined>;
|
|
27
|
-
parameters:
|
|
24
|
+
parameters: {
|
|
25
|
+
name: string;
|
|
26
|
+
in: 'header' | 'query' | 'cookie';
|
|
27
|
+
description: string;
|
|
28
|
+
required: boolean;
|
|
29
|
+
schema: any;
|
|
30
|
+
example: string | undefined;
|
|
31
|
+
}[] | undefined;
|
|
28
32
|
security: Array<Record<string, string[] | undefined>> | undefined;
|
|
29
33
|
};
|
|
30
34
|
export interface ServiceOutputOptions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getServices.d.ts","sourceRoot":"","sources":["../../../src/lib/open-api/getServices.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAIhE,OAAO,EAEL,+BAA+B,EAChC,MAAM,yCAAyC,CAAC;AAGjD,MAAM,MAAM,eAAe,GAAG,+BAA+B,GAAG,MAAM,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,gBAAgB,EAAE,CAAC;CAChC,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"getServices.d.ts","sourceRoot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K,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC;CACnE,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED,eAAO,MAAM,WAAW,gBACT,iBAAiB,0CAI3B,oBAAoB,cAwGxB,CAAC;AAEF,eAAO,MAAM,eAAe,WAClB,OAAO,KACd,MAAM,IAAI,CAAC,OAAO,oBAAoB,EAAE,MAAM,CAG9C,CAAC;AAEJ,QAAA,MAAM,oBAAoB,gFAS+B,CAAC"}
|
|
@@ -55,7 +55,7 @@ export const getServices = (openApiJson, { postfixServices = 'Service', serviceN
|
|
|
55
55
|
method,
|
|
56
56
|
path,
|
|
57
57
|
errors,
|
|
58
|
-
name: getOperationName(path, method, methodOperation.operationId),
|
|
58
|
+
name: getOperationName(path, method, methodOperation.operationId, serviceNameBase),
|
|
59
59
|
description: methodOperation.description,
|
|
60
60
|
summary: methodOperation.summary,
|
|
61
61
|
deprecated: methodOperation.deprecated,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getServices.js","sourceRoot":"","sources":["../../../src/lib/open-api/getServices.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,kCAAkC,GAEnC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"getServices.js","sourceRoot":"","sources":["../../../src/lib/open-api/getServices.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,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1,2 @@
|
|
|
1
|
-
export declare const packageVersion = "2.0.0-next.
|
|
1
|
+
export declare const packageVersion = "2.0.0-next.10";
|
|
2
2
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,kBAAkB,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/plugin",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.10",
|
|
4
4
|
"packageManager": "yarn@4.0.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -29,19 +29,19 @@
|
|
|
29
29
|
"camelcase": "^8.0.0",
|
|
30
30
|
"commander": "^11.1.0",
|
|
31
31
|
"micromatch": "^4.0.8",
|
|
32
|
-
"openapi-typescript": "^7.
|
|
33
|
-
"ora": "^8.0
|
|
34
|
-
"yaml": "^2.
|
|
32
|
+
"openapi-typescript": "^7.4.0",
|
|
33
|
+
"ora": "^8.1.0",
|
|
34
|
+
"yaml": "^2.5.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@openapi-qraft/test-fixtures": "1.0.0",
|
|
38
|
-
"@types/micromatch": "^4",
|
|
39
|
-
"@types/node": "^
|
|
38
|
+
"@types/micromatch": "^4.0.9",
|
|
39
|
+
"@types/node": "^20.16.5",
|
|
40
40
|
"commander": "^11.1.0",
|
|
41
|
-
"eslint": "^9.
|
|
41
|
+
"eslint": "^9.10.0",
|
|
42
42
|
"rimraf": "^5.0.10",
|
|
43
|
-
"typescript": "^5.
|
|
44
|
-
"vitest": "^1.
|
|
43
|
+
"typescript": "^5.6.2",
|
|
44
|
+
"vitest": "^1.6.0"
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"dist",
|
|
@@ -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
|
+
};
|
|
@@ -21,9 +21,6 @@ export type Service = {
|
|
|
21
21
|
operations: ServiceOperation[];
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated move to separate file
|
|
26
|
-
*/
|
|
27
24
|
export type ServiceOperation = {
|
|
28
25
|
method:
|
|
29
26
|
| 'get'
|
|
@@ -42,7 +39,16 @@ export type ServiceOperation = {
|
|
|
42
39
|
mediaType: string | undefined;
|
|
43
40
|
errors: Record<string, string | undefined>;
|
|
44
41
|
success: Record<string, string | undefined>;
|
|
45
|
-
parameters:
|
|
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;
|
|
46
52
|
security: Array<Record<string, string[] | undefined>> | undefined;
|
|
47
53
|
};
|
|
48
54
|
|
|
@@ -135,7 +141,12 @@ export const getServices = (
|
|
|
135
141
|
method,
|
|
136
142
|
path,
|
|
137
143
|
errors,
|
|
138
|
-
name: getOperationName(
|
|
144
|
+
name: getOperationName(
|
|
145
|
+
path,
|
|
146
|
+
method,
|
|
147
|
+
methodOperation.operationId,
|
|
148
|
+
serviceNameBase
|
|
149
|
+
),
|
|
139
150
|
description: methodOperation.description,
|
|
140
151
|
summary: methodOperation.summary,
|
|
141
152
|
deprecated: methodOperation.deprecated,
|
package/src/packageVersion.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file was generated automatically
|
|
2
|
-
export const packageVersion = '2.0.0-next.
|
|
2
|
+
export const packageVersion = '2.0.0-next.10';
|