Skip to content

Commit

Permalink
Add missing endpoints to verbose mode capture (#2637)
Browse files Browse the repository at this point in the history
  • Loading branch information
niclim authored Jan 2, 2024
1 parent 2849178 commit 39bf290
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "openapi-workspaces",
"license": "MIT",
"private": true,
"version": "0.53.16",
"version": "0.53.17",
"workspaces": [
"projects/json-pointer-helpers",
"projects/openapi-io",
Expand Down
2 changes: 1 addition & 1 deletion projects/fastify-capture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/fastify-capture",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.53.16",
"version": "0.53.17",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion projects/json-pointer-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/json-pointer-helpers",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.53.16",
"version": "0.53.17",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion projects/openapi-io/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/openapi-io",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.53.16",
"version": "0.53.17",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion projects/openapi-utilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/openapi-utilities",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.53.16",
"version": "0.53.17",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion projects/optic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/optic",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.53.16",
"version": "0.53.17",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,8 @@ GET /books
$workspace$/openapi.yml
...and 1 endpoint that did not receive traffic
Unmatched endpoints:
POST /books
66.7% coverage of your documented operations. 5 requests did not match a documented path (6 total requests).
9 diffs detected in documented operations
Expand Down
10 changes: 10 additions & 0 deletions projects/optic/src/commands/capture/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,16 @@ export async function processCaptures(
);
options.bufferLogs ? bufferedOutput.push(txt) : logger.info(txt);
}
if (options.verbose) {
const text = [chalk.gray(`Unmatched endpoints:`)];
for (const endpoint of endpointCounts.paths.unmatched) {
text.push(
` ${chalk.gray(`${endpoint.method.toUpperCase()} ${endpoint.path}`)}`
);
}
for (const line of text)
options.bufferLogs ? bufferedOutput.push(line) : logger.info(line);
}
}

// document new endpoints
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { jsonPointerHelpers } from '@useoptic/json-pointer-helpers';
import { OpenAPIV3, getEndpointId } from '@useoptic/openapi-utilities';
import {
OpenAPIV3,
getEndpointId,
getPathAndMethodFromEndpointId,
} from '@useoptic/openapi-utilities';
import crypto from 'crypto';
import fs from 'node:fs/promises';
import path from 'path';
Expand Down Expand Up @@ -269,17 +273,29 @@ export class GroupedCaptures {
counts() {
let total = 0;
let unmatched = 0;
const unmatchedPaths: { method: string; path: string }[] = [];
const matchedPaths: { method: string; path: string }[] = [];
let matched = 0;
for (const [, node] of this.paths) {
total++;
if (node.hars.length === 0 && node.interactions.length === 0) unmatched++;
if (node.hars.length !== 0 || node.interactions.length !== 0) matched++;
if (node.hars.length === 0 && node.interactions.length === 0) {
unmatched++;
unmatchedPaths.push(node.endpoint);
}
if (node.hars.length !== 0 || node.interactions.length !== 0) {
matched++;
matchedPaths.push(node.endpoint);
}
}

return {
total,
unmatched,
matched,
paths: {
unmatched: unmatchedPaths,
matched: matchedPaths,
},
};
}

Expand Down
2 changes: 1 addition & 1 deletion projects/rulesets-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/rulesets-base",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.53.16",
"version": "0.53.17",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion projects/standard-rulesets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@useoptic/standard-rulesets",
"license": "MIT",
"packageManager": "[email protected]",
"version": "0.53.16",
"version": "0.53.17",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down

0 comments on commit 39bf290

Please sign in to comment.