Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 98ec86a

Browse files
committed
solved bug, now it can track $ref successfully 🤞
1 parent c9d3547 commit 98ec86a

File tree

4 files changed

+5
-29
lines changed

4 files changed

+5
-29
lines changed

‎package-lock.json‎

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"devDependencies": {
2929
"@types/jest": "^26.0.20",
3030
"@types/js-yaml": "^4.0.0",
31-
"@types/yamljs": "^0.2.31",
3231
"jest": "^26.6.3",
3332
"js-yaml": "^4.0.0",
3433
"openapi-types": "^7.2.3",

‎src/graph/builder/finder.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function getRefEdges(json: any, absolutePath: string, edges: EdgesRefDict
8484
if (/components\/schemas/.test(ref)) {
8585
edges.schemaRef[ref] = new RefEdge(absolutePath, ref);
8686
}
87-
} else {
87+
} else if(json!==null){
8888
function handleJson() {
8989
Object.keys(json).forEach((key) => {
9090
getRefEdges(json[key], absolutePath, edges);
@@ -111,7 +111,7 @@ export function resolveReference(graphs: OpenAPIGraphsBuilderInterface['graphs']
111111
};
112112

113113
Object.values(refs.schemaRef)
114-
.filter((r) => graphs?.[r.refToFilePath].nodes.schemas[r.tokenName])
114+
.filter((r) => graphs?.[r.refToFilePath]&&graphs?.[r.refToFilePath].nodes.schemas[r.tokenName])
115115
.forEach((r) => {
116116
const schema = graphs?.[r.refToFilePath].nodes.schemas[r.tokenName];
117117
if (schema) {

‎src/openapi/utils.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,9 @@ const logger = require('pino')({
1717
* @returns the contents of the files as JSON with their path
1818
*/
1919
export async function getOpenApisContent(paths: string[]): Promise<OpenAPIContent[]> {
20-
// TODO Check that only v3 are valid
21-
// Validates it contents, but they are
22-
// const validationPromises: Promise<OpenAPI.Document<{}>>[] = paths.map((p) => SwaggerParser.validate(p));
23-
const validationPromises: Promise<OpenAPI.Document<{}>>[] = paths.map((p) => logger.info(`Validating ${p}`) && SwaggerParser.validate(p));
24-
// Filter only promises which return some content
25-
const validationResponse = await Promise.all(validationPromises)
26-
2720
return (
28-
validationResponse
29-
.map((v, i) => ({ promise: v, path: paths[i] }))
30-
.filter((r) => r.promise.status === 'fulfilled' || logger.warn(`Ignoring ${r.promise.reason}`))
31-
// as you can see, the file is read twice. One in the SwaggerParser.validate function in this same function
32-
// and another one here. It would be cool to get SwaggerParser.validate value dereferenced out-of-the-box
33-
.map((r) => ({ path: r.path, content: loadYaml(readFileSync(r.path, 'utf8')) as OpenAPIV3.Document || logger.warn(`Couldn't load ${r.path}`) }))
21+
paths
22+
.map(p => ({ path: p, content: loadYaml(readFileSync(p, 'utf8')) || logger.warn(`Couldn't load ${p}`) }))
23+
.filter(p => p.content?.openapi?.includes("3.0"))
3424
);
3525
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /