Skip to content

Commit 49c5d1d

Browse files
authored
Merge pull request #16 from mhailstone/master
Dereference all JSON references initially
2 parents e1060df + b278c3f commit 49c5d1d

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"main": "rapidoc.js",
2626
"module": "rapidoc.js",
2727
"dependencies": {
28+
"json-refs": "^3.0.12",
2829
"json-schema-ref-parser": "^6.1.0",
2930
"lit-element": "2.0.1",
3031
"lit-html": "1.0.0",

src/utils/parse-utils.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//import converter from 'swagger2openapi';
22
import JsonSchemaRefParser from 'json-schema-ref-parser';
3+
import JsonRefs from 'json-refs';
34
import converter from 'swagger2openapi';
45

56
export default async function ProcessSpec(specUrl, resolveCircularRefs){
@@ -14,17 +15,19 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
1415

1516
let refParserOptions = {
1617
resolve: {
17-
http: {
18-
withCredentials: false
19-
}
18+
http: {
19+
withCredentials: false
20+
}
2021
}
2122
};
2223
try {
2324
if (typeof specUrl==="string") {
24-
convertedSpec = await converter.convertUrl(specUrl, convertOptions);
25+
const resolvedSpec = await JsonRefs.resolveRefsAt(specUrl, {resolveCirculars: resolveCircularRefs==='true'});
26+
convertedSpec = await converter.convertObj(resolvedSpec.resolved, convertOptions);
2527
}
2628
else {
27-
convertedSpec = await converter.convertObj(specUrl, convertOptions);
29+
const resolvedSpec = await JsonRefs.resolveRefs(specUrl, {resolveCirculars: resolveCircularRefs==='true'});
30+
convertedSpec = await converter.convertObj(resolvedSpec.resolved, convertOptions);
2831
}
2932

3033
if (resolveCircularRefs==='false'){
@@ -35,7 +38,7 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
3538
}
3639
}
3740
catch(err){
38-
debugger;
41+
debugger;
3942
console.info("%c There was an issue while parsing the spec %o ", "color:orangered", err);
4043
jsonParsedSpec = await parser.bundle(specUrl, refParserOptions);
4144
}
@@ -59,7 +62,7 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
5962
let tagObj;
6063
let tagText;
6164
let tagDescr;
62-
65+
6366
if (openApiSpec.paths[path][methodName]){
6467
let fullPath = openApiSpec.paths[path][methodName];
6568
// If path.methods are tagged, else generate it from path
@@ -84,7 +87,7 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
8487
tagObj = tags.find(v => v.name == tagText);
8588

8689
if (!tagObj){
87-
tagObj = {
90+
tagObj = {
8891
show : true,
8992
"name" : tagText,
9093
"description" : tagDescr?tagDescr.description:"",
@@ -178,7 +181,7 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
178181
"info" : openApiSpec.info,
179182
"tags" : tags,
180183
"externalDocs": openApiSpec.externalDocs,
181-
"securitySchemes": securitySchemes,
184+
"securitySchemes": securitySchemes,
182185
"servers" : servers, // In swagger 2, its generated from schemes, host and basePath properties
183186
"basePath": openApiSpec.basePath, // Only available in swagger V2
184187
"totalPathCount" : totalPathCount,

0 commit comments

Comments
 (0)