1
1
//import converter from 'swagger2openapi';
2
2
import JsonSchemaRefParser from 'json-schema-ref-parser' ;
3
+ import JsonRefs from 'json-refs' ;
3
4
import converter from 'swagger2openapi' ;
4
5
5
6
export default async function ProcessSpec ( specUrl , resolveCircularRefs ) {
@@ -14,17 +15,19 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
14
15
15
16
let refParserOptions = {
16
17
resolve : {
17
- http : {
18
- withCredentials : false
19
- }
18
+ http : {
19
+ withCredentials : false
20
+ }
20
21
}
21
22
} ;
22
23
try {
23
24
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 ) ;
25
27
}
26
28
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 ) ;
28
31
}
29
32
30
33
if ( resolveCircularRefs === 'false' ) {
@@ -35,7 +38,7 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
35
38
}
36
39
}
37
40
catch ( err ) {
38
- debugger ;
41
+ debugger ;
39
42
console . info ( "%c There was an issue while parsing the spec %o " , "color:orangered" , err ) ;
40
43
jsonParsedSpec = await parser . bundle ( specUrl , refParserOptions ) ;
41
44
}
@@ -59,7 +62,7 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
59
62
let tagObj ;
60
63
let tagText ;
61
64
let tagDescr ;
62
-
65
+
63
66
if ( openApiSpec . paths [ path ] [ methodName ] ) {
64
67
let fullPath = openApiSpec . paths [ path ] [ methodName ] ;
65
68
// If path.methods are tagged, else generate it from path
@@ -84,7 +87,7 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
84
87
tagObj = tags . find ( v => v . name == tagText ) ;
85
88
86
89
if ( ! tagObj ) {
87
- tagObj = {
90
+ tagObj = {
88
91
show : true ,
89
92
"name" : tagText ,
90
93
"description" : tagDescr ?tagDescr . description :"" ,
@@ -178,7 +181,7 @@ export default async function ProcessSpec(specUrl, resolveCircularRefs){
178
181
"info" : openApiSpec . info ,
179
182
"tags" : tags ,
180
183
"externalDocs" : openApiSpec . externalDocs ,
181
- "securitySchemes" : securitySchemes ,
184
+ "securitySchemes" : securitySchemes ,
182
185
"servers" : servers , // In swagger 2, its generated from schemes, host and basePath properties
183
186
"basePath" : openApiSpec . basePath , // Only available in swagger V2
184
187
"totalPathCount" : totalPathCount ,
0 commit comments