@redocly/respect-core 2.55.0 → 2.56.1
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/lib/modules/description-parser/get-operation-by-id.d.ts +5 -1
- package/lib/modules/description-parser/get-operation-by-id.d.ts.map +1 -1
- package/lib/modules/description-parser/get-operation-by-id.js +17 -2
- package/lib/modules/description-parser/get-operation-by-id.js.map +1 -1
- package/lib/modules/description-parser/get-operation-from-description.js +1 -1
- package/lib/modules/description-parser/get-operation-from-description.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { SourceDescription, TestContext } from '../../types.js';
|
|
1
2
|
import type { OperationDetails } from './get-operation-from-description.js';
|
|
2
|
-
export declare function getOperationById(operationIdStr: string,
|
|
3
|
+
export declare function getOperationById(operationIdStr: string, descriptionDetails: {
|
|
4
|
+
$sourceDescriptions: TestContext['$sourceDescriptions'];
|
|
5
|
+
sourceDescriptions: SourceDescription[] | undefined;
|
|
6
|
+
}): (OperationDetails & Record<string, any>) | undefined;
|
|
3
7
|
//# sourceMappingURL=get-operation-by-id.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-operation-by-id.d.ts","sourceRoot":"","sources":["../../../src/modules/description-parser/get-operation-by-id.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAG5E,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,MAAM,EACtB,
|
|
1
|
+
{"version":3,"file":"get-operation-by-id.d.ts","sourceRoot":"","sources":["../../../src/modules/description-parser/get-operation-by-id.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAG5E,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,MAAM,EACtB,kBAAkB,EAAE;IAClB,mBAAmB,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAC;IACxD,kBAAkB,EAAE,iBAAiB,EAAE,GAAG,SAAS,CAAC;CACrD,GACA,CAAC,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,SAAS,CAmDtD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { red } from 'colorette';
|
|
2
2
|
// TODO: create a type: ExtendedOpenAPIOperation = OpenAPIOperation & { pathParameters: Parameter[], path, ... }
|
|
3
|
-
export function getOperationById(operationIdStr,
|
|
3
|
+
export function getOperationById(operationIdStr, descriptionDetails) {
|
|
4
|
+
const { $sourceDescriptions: descriptions, sourceDescriptions } = descriptionDetails;
|
|
4
5
|
let descriptionName;
|
|
5
6
|
let operationId;
|
|
6
7
|
if (operationIdStr.includes('$sourceDescriptions.')) {
|
|
@@ -10,7 +11,7 @@ export function getOperationById(operationIdStr, descriptions) {
|
|
|
10
11
|
}
|
|
11
12
|
else if (!operationIdStr.includes('.')) {
|
|
12
13
|
operationId = operationIdStr;
|
|
13
|
-
descriptionName =
|
|
14
|
+
descriptionName = findOpenApiDescriptionName(operationId, descriptions, sourceDescriptions);
|
|
14
15
|
}
|
|
15
16
|
else {
|
|
16
17
|
[descriptionName, operationId] = operationIdStr.split('.');
|
|
@@ -42,4 +43,18 @@ export function getOperationById(operationIdStr, descriptions) {
|
|
|
42
43
|
}
|
|
43
44
|
throw new Error(`Unknown operationId ${red(operationId)} at ${red(operationIdStr)}.`);
|
|
44
45
|
}
|
|
46
|
+
// Only openapi descriptions have operations, and the plain operationId must match exactly one of them.
|
|
47
|
+
function findOpenApiDescriptionName(operationId, descriptions, sourceDescriptions = []) {
|
|
48
|
+
const matchingDescriptionNames = sourceDescriptions
|
|
49
|
+
.filter(({ type, name }) => type === 'openapi' &&
|
|
50
|
+
Object.values(descriptions[name]?.paths || {}).some((pathDetails) => Object.values(pathDetails || {}).some((operationDetails) => operationDetails?.operationId === operationId)))
|
|
51
|
+
.map(({ name }) => name);
|
|
52
|
+
if (matchingDescriptionNames.length === 0) {
|
|
53
|
+
throw new Error(`Unknown operationId ${red(operationId)}. No openapi source description defines it.`);
|
|
54
|
+
}
|
|
55
|
+
if (matchingDescriptionNames.length > 1) {
|
|
56
|
+
throw new Error(`The operationId ${red(operationId)} is defined in several source descriptions: ${matchingDescriptionNames.join(', ')}. Use ${red(`$sourceDescriptions.<name>.${operationId}`)} to pick one.`);
|
|
57
|
+
}
|
|
58
|
+
return matchingDescriptionNames[0];
|
|
59
|
+
}
|
|
45
60
|
//# sourceMappingURL=get-operation-by-id.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-operation-by-id.js","sourceRoot":"","sources":["../../../src/modules/description-parser/get-operation-by-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"get-operation-by-id.js","sourceRoot":"","sources":["../../../src/modules/description-parser/get-operation-by-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAKhC,gHAAgH;AAChH,MAAM,UAAU,gBAAgB,CAC9B,cAAsB,EACtB,kBAGC;IAED,MAAM,EAAE,mBAAmB,EAAE,YAAY,EAAE,kBAAkB,EAAE,GAAG,kBAAkB,CAAC;IACrF,IAAI,eAAe,CAAC;IACpB,IAAI,WAAW,CAAC;IAEhB,IAAI,cAAc,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACpD,MAAM,CAAC,EAAE,qBAAqB,EAAE,qBAAqB,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnF,eAAe,GAAG,qBAAqB,CAAC;QACxC,WAAW,GAAG,qBAAqB,CAAC;IACtC,CAAC;SAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE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source, ctx) {
|
|
|
10
10
|
const { $sourceDescriptions, sourceDescriptions } = ctx;
|
|
11
11
|
const { operationId, operationPath } = source;
|
|
12
12
|
if (operationId) {
|
|
13
|
-
return getOperationById(operationId, $sourceDescriptions);
|
|
13
|
+
return getOperationById(operationId, { $sourceDescriptions, sourceDescriptions });
|
|
14
14
|
}
|
|
15
15
|
else if (operationPath) {
|
|
16
16
|
return getOperationByPath(operationPath, { $sourceDescriptions, sourceDescriptions });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-operation-from-description.js","sourceRoot":"","sources":["../../../src/modules/description-parser/get-operation-from-description.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAehE,MAAM,UAAU,2BAA2B,CACzC,IAAY,EACZ,MAAc,EACd,gBAAqC;IAErC,OAAO,gBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,MAAyB,EACzB,GAAgB;IAEhB,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,GAAG,GAAG,CAAC;IACxD,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IAE9C,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,gBAAgB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"get-operation-from-description.js","sourceRoot":"","sources":["../../../src/modules/description-parser/get-operation-from-description.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAehE,MAAM,UAAU,2BAA2B,CACzC,IAAY,EACZ,MAAc,EACd,gBAAqC;IAErC,OAAO,gBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,MAAyB,EACzB,GAAgB;IAEhB,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,GAAG,GAAG,CAAC;IACxD,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IAE9C,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,gBAAgB,CAAC,WAAW,EAAE,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACpF,CAAC;SAAM,IAAI,aAAa,EAAE,CAAC;QACzB,OAAO,kBAAkB,CAAC,aAAa,EAAE,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACxF,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/respect-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.56.1",
|
|
4
4
|
"description": "API testing framework core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@faker-js/faker": "^10.6.0",
|
|
49
49
|
"@noble/hashes": "^1.8.0",
|
|
50
50
|
"@redocly/ajv": "^8.18.3",
|
|
51
|
-
"@redocly/openapi-core": "2.
|
|
51
|
+
"@redocly/openapi-core": "2.56.1",
|
|
52
52
|
"ajv": "npm:@redocly/ajv@^8.18.3",
|
|
53
53
|
"better-ajv-errors": "^2.0.3",
|
|
54
54
|
"colorette": "^2.0.20",
|