use yaml 2 for finding line positions (#8607)

This commit is contained in:
Jack Kavanagh
2025-04-14 12:10:58 +02:00
committed by Jay Wu
parent c54ef801c2
commit 9ea702c9bd
5 changed files with 68 additions and 60 deletions

86
package-lock.json generated
View File

@@ -23258,20 +23258,6 @@
"dev": true,
"license": "ISC"
},
"node_modules/temp": {
"version": "0.9.4",
"resolved": "https://registry.npmjs.org/temp/-/temp-0.9.4.tgz",
"integrity": "sha512-yYrrsWnrXMcdsnu/7YMYAofM1ktpL5By7vZhf15CrXijWWrEYZks5AXBudalfSWJLlnen/QUJUB5aoB0kqZUGA==",
"dev": true,
"license": "MIT",
"dependencies": {
"mkdirp": "^0.5.1",
"rimraf": "~2.6.2"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/teeny-request": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-9.0.0.tgz",
@@ -23288,6 +23274,20 @@
"node": ">=14"
}
},
"node_modules/temp": {
"version": "0.9.4",
"resolved": "https://registry.npmjs.org/temp/-/temp-0.9.4.tgz",
"integrity": "sha512-yYrrsWnrXMcdsnu/7YMYAofM1ktpL5By7vZhf15CrXijWWrEYZks5AXBudalfSWJLlnen/QUJUB5aoB0kqZUGA==",
"dev": true,
"license": "MIT",
"dependencies": {
"mkdirp": "^0.5.1",
"rimraf": "~2.6.2"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/temp-file": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/temp-file/-/temp-file-3.4.0.tgz",
@@ -25310,15 +25310,6 @@
"node": ">= 6"
}
},
"node_modules/yaml-source-map": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/yaml-source-map/-/yaml-source-map-2.1.1.tgz",
"integrity": "sha512-eILAwrW4K1WA83mJXF0PLyeBhL4t6v9xyesRYhncG1zh9UPc43mMRgFTCi2FRYpOgUvGECNlNjoiksiX2xBKVg==",
"license": "MIT",
"peerDependencies": {
"yaml": "^1.6.0"
}
},
"node_modules/yargs": {
"version": "17.7.2",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
@@ -25490,7 +25481,7 @@
"html-entities": "^2.5.2",
"httpsnippet": "^2.0.0",
"iconv-lite": "^0.6.3",
"js-yaml": "^3.14.1",
"js-yaml": "^4.1.0",
"jsdom": "^25.0.1",
"jshint": "^2.13.6",
"jsonlint-mod-fixed": "1.7.7",
@@ -25506,8 +25497,7 @@
"swagger-ui-dist": "^5.17.14",
"tough-cookie": "^4.1.3",
"uuid": "^9.0.1",
"yaml": "^1.6.0",
"yaml-source-map": "^2.1.1",
"yaml": "^2.7.1",
"zod": "^3.23.8"
},
"bin": {
@@ -25626,7 +25616,7 @@
"cosmiconfig": "^9.0.0",
"enquirer": "^2.4.1",
"string-argv": "^0.3.2",
"yaml": "^1.6.0"
"yaml": "^2.7.1"
},
"bin": {
"inso": "bin/inso"
@@ -25645,6 +25635,18 @@
"integrity": "sha512-9vAdYbHj6x2fLKC4+oPH0kFzY/orMZyG2Aj+kNylHxKGJ/Ed4dpNyAQYwJOdqO4zdM7XpVHmyejQDcQHrnuXbw==",
"license": "MIT"
},
"packages/insomnia-inso/node_modules/yaml": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.7.1.tgz",
"integrity": "sha512-10ULxpnOCQXxJvBgxsn9ptjq6uviG/htZKk9veJGhlqn3w/DxQ631zFF+nlQXLwmImeS5amR2dl2U8sg6U9jsQ==",
"license": "ISC",
"bin": {
"yaml": "bin.mjs"
},
"engines": {
"node": ">= 14"
}
},
"packages/insomnia-scripting-environment": {
"version": "11.1.0-beta.1",
"license": "Apache-2.0",
@@ -25750,6 +25752,24 @@
"version": "11.1.0-beta.1",
"license": "Apache-2.0"
},
"packages/insomnia/node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
"license": "Python-2.0"
},
"packages/insomnia/node_modules/js-yaml": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
"license": "MIT",
"dependencies": {
"argparse": "^2.0.1"
},
"bin": {
"js-yaml": "bin/js-yaml.js"
}
},
"packages/insomnia/node_modules/quick-lru": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-7.0.0.tgz",
@@ -25762,6 +25782,18 @@
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"packages/insomnia/node_modules/yaml": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.7.1.tgz",
"integrity": "sha512-10ULxpnOCQXxJvBgxsn9ptjq6uviG/htZKk9veJGhlqn3w/DxQ631zFF+nlQXLwmImeS5amR2dl2U8sg6U9jsQ==",
"license": "ISC",
"bin": {
"yaml": "bin.mjs"
},
"engines": {
"node": ">= 14"
}
}
}
}

View File

@@ -52,6 +52,6 @@
"cosmiconfig": "^9.0.0",
"enquirer": "^2.4.1",
"string-argv": "^0.3.2",
"yaml": "^1.6.0"
"yaml": "^2.7.1"
}
}

View File

@@ -70,7 +70,7 @@
"html-entities": "^2.5.2",
"httpsnippet": "^2.0.0",
"iconv-lite": "^0.6.3",
"js-yaml": "^3.14.1",
"js-yaml": "^4.1.0",
"jsdom": "^25.0.1",
"jshint": "^2.13.6",
"jsonlint-mod-fixed": "1.7.7",
@@ -86,8 +86,7 @@
"swagger-ui-dist": "^5.17.14",
"tough-cookie": "^4.1.3",
"uuid": "^9.0.1",
"yaml": "^1.6.0",
"yaml-source-map": "^2.1.1",
"yaml": "^2.7.1",
"zod": "^3.23.8"
},
"devDependencies": {

View File

@@ -43,7 +43,6 @@ import {
import { useUnmount } from 'react-use';
import { SwaggerUIBundle } from 'swagger-ui-dist';
import YAML from 'yaml';
import YAMLSourceMap from 'yaml-source-map';
import { parseApiSpec } from '../../common/api-specs';
import { ACTIVITY_SPEC, DEFAULT_SIDEBAR_SIZE } from '../../common/constants';
@@ -306,15 +305,12 @@ const Design: FC = () => {
scrollPosition.start.line = 1;
} catch {}
const sourceMap = new YAMLSourceMap();
const specMap = sourceMap.index(
YAML.parseDocument(apiSpec.contents, {
keepCstNodes: true,
}),
);
const itemMappedPosition = sourceMap.lookup(pathSegments, specMap);
if (itemMappedPosition) {
scrollPosition.start.line += itemMappedPosition.start.line;
const lineCounter = new YAML.LineCounter();
const doc = YAML.parseDocument(apiSpec.contents, { lineCounter });
const astNode = doc.getIn(pathSegments, true) as YAML.Node;
const nodePosition = astNode.range && lineCounter.linePos(astNode.range[0]);
if (nodePosition) {
scrollPosition.start.line += nodePosition.line;
}
const isServersSection = pathSegments[0] === 'servers';
if (!isServersSection) {

View File

@@ -1,19 +0,0 @@
declare module 'yaml-source-map' {
interface Location {
filename?: string;
start: {
line: number;
col: number;
};
end: {
line: number;
col: number;
};
}
export default class YAMLSourceMap {
constructor();
index(doc: YAML.Document.Parsed): object;
lookup(path: string[], document: object): Location | undefined;
}
}