Skip to content

Commit

Permalink
Improve infer path structure with user input (#2480)
Browse files Browse the repository at this point in the history
  • Loading branch information
niclim authored Nov 3, 2023
1 parent 277361c commit 2910f7a
Show file tree
Hide file tree
Showing 16 changed files with 367 additions and 1,057 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.50.16",
"version": "0.50.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.50.16",
"version": "0.50.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.50.16",
"version": "0.50.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.50.16",
"version": "0.50.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.50.16",
"version": "0.50.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.50.16",
"version": "0.50.17",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down
10 changes: 6 additions & 4 deletions projects/optic/src/commands/capture/actions/undocumented.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
CapturedInteraction,
CapturedInteractions,
} from '../sources/captured-interactions';
import { InferPathStructure } from '../operations/infer-path-structure';
import { PathInference } from '../operations/path-inference';
import {
generateEndpointSpecPatches,
generatePathAndMethodSpecPatches,
Expand All @@ -25,7 +25,7 @@ type MethodMap = Map<string, { add: Set<string>; ignore: Set<string> }>;

export async function promptUserForPathPattern(
interactions: CapturedInteractions,
inferredPathStructure: InferPathStructure,
pathInference: PathInference,
options: { update: 'interactive' | 'automatic' }
) {
const filteredInteractions: CapturedInteraction[] = [];
Expand Down Expand Up @@ -59,8 +59,7 @@ export async function promptUserForPathPattern(
const pathInIgnore = [...ignore.values()].some((ignore) =>
minimatch(path, ignore)
);
const guessedPattern =
inferredPathStructure.includeObservedUrlPath(method, path) ?? path;
const guessedPattern = pathInference.getInferedPattern(path);

if (pathInAdd) {
filteredInteractions.push(interaction);
Expand All @@ -69,6 +68,7 @@ export async function promptUserForPathPattern(
continue;
} else if (options.update === 'automatic') {
add.add(guessedPattern);
pathInference.addKnownPath(guessedPattern);
filteredInteractions.push(interaction);
} else {
logger.info(`> ` + chalk.bold.blue(guessedPattern));
Expand Down Expand Up @@ -116,9 +116,11 @@ export async function promptUserForPathPattern(

if (results.action === 'yes') {
add.add(guessedPattern);
pathInference.addKnownPath(guessedPattern);
filteredInteractions.push(interaction);
} else if (results.action === 'no') {
add.add(results.newPath);
pathInference.addKnownPath(results.newPath);
filteredInteractions.push(interaction);
} else if (results.action === 'skip') {
continue;
Expand Down
11 changes: 5 additions & 6 deletions projects/optic/src/commands/capture/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { GroupedCaptures } from './interactions/grouped-interactions';
import { OPTIC_URL_KEY } from '../../constants';
import { uploadCoverage } from './actions/upload-coverage';
import { resolveRelativePath } from '../../utils/capture';
import { InferPathStructure } from './operations/infer-path-structure';
import { PathInference } from './operations/path-inference';
import { getSpinner } from '../../utils/spinner';
import { flushEvents, trackEvent } from '../../segment';
import { getOpticUrlDetails } from '../../utils/cloud-urls';
Expand Down Expand Up @@ -557,11 +557,10 @@ export async function processCaptures(
'Learning path patterns for unmatched requests...'
);
options.bufferLogs ? bufferedOutput.push(summary) : logger.info(summary);
const inferredPathStructure =
await InferPathStructure.fromSpecAndInteractions(
spec.jsonLike,
captures.getUndocumentedInteractions()
);
const inferredPathStructure = await PathInference.fromSpecAndInteractions(
spec.jsonLike,
captures.getUndocumentedInteractions()
);
const {
interactions: filteredInteractions,
ignorePaths: newIgnorePaths,
Expand Down
Loading

0 comments on commit 2910f7a

Please sign in to comment.