@@ -15,6 +15,8 @@ import {
15
15
bundle ,
16
16
loadConfig ,
17
17
stringifyYaml ,
18
+ Document ,
19
+ NormalizedProblem ,
18
20
} from '@redocly/openapi-core' ;
19
21
20
22
import {
@@ -24,6 +26,8 @@ import {
24
26
DEFAULT_OPTIONS ,
25
27
} from './options' ;
26
28
import { SpecProps , ApiDocProps } from './types/common' ;
29
+ import { loadSpecWithConfig } from './loadSpec' ;
30
+
27
31
// eslint-disable-next-line @typescript-eslint/no-var-requires
28
32
const version = require ( '../package.json' ) . version ;
29
33
@@ -57,23 +61,6 @@ export default function redocPlugin(
57
61
return {
58
62
name : 'docusaurus-plugin-redoc' ,
59
63
async loadContent ( ) {
60
- if ( ! isSpecFile ) {
61
- // If spec is a remote url then add it as download url also as a default
62
- url = url || spec ;
63
- if ( debug ) {
64
- console . log ( '[REDOCUSAURUS_PLUGIN] bundling spec from url' , spec ) ;
65
- }
66
- const converted = await loadAndBundleSpec ( spec ! ) ;
67
- return {
68
- converted,
69
- } ;
70
- }
71
-
72
- // If local file
73
- if ( debug ) {
74
- console . log ( '[REDOCUSAURUS_PLUGIN] reading file: ' , spec ) ;
75
- }
76
-
77
64
let redoclyConfig : Config ;
78
65
79
66
if ( config ) {
@@ -89,16 +76,34 @@ export default function redocPlugin(
89
76
redoclyConfig = await loadConfig ( ) ;
90
77
}
91
78
92
- const {
93
- bundle : bundledSpec ,
94
- problems,
95
- fileDependencies,
96
- } = await bundle ( {
97
- ref : spec ,
98
- config : redoclyConfig ,
99
- } ) ;
79
+ let bundledSpec : Document , problems : NormalizedProblem [ ] ;
100
80
101
- filesToWatch = [ path . resolve ( spec ) , ...fileDependencies ] ;
81
+ if ( ! isSpecFile ) {
82
+ // If spec is a remote url then add it as download url also as a default
83
+ url = url || spec ;
84
+ if ( debug ) {
85
+ console . log ( '[REDOCUSAURUS_PLUGIN] bundling spec from url' , spec ) ;
86
+ }
87
+ ( { bundle : bundledSpec , problems } = await loadSpecWithConfig (
88
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
89
+ spec ! ,
90
+ redoclyConfig ,
91
+ ) ) ;
92
+ } else {
93
+ // If local file
94
+ if ( debug ) {
95
+ console . log ( '[REDOCUSAURUS_PLUGIN] reading file: ' , spec ) ;
96
+ }
97
+
98
+ const fileBundle = await bundle ( {
99
+ ref : spec ,
100
+ config : redoclyConfig ,
101
+ } ) ;
102
+
103
+ ( { bundle : bundledSpec , problems } = fileBundle ) ;
104
+
105
+ filesToWatch = [ path . resolve ( spec ) , ...fileBundle . fileDependencies ] ;
106
+ }
102
107
103
108
if ( problems ?. length ) {
104
109
console . error ( '[REDOCUSAURUS_PLUGIN] errors while bundling spec' , spec ) ;
@@ -112,6 +117,7 @@ export default function redocPlugin(
112
117
if ( debug ) {
113
118
console . log ( '[REDOCUSAURUS_PLUGIN] File Bundled' ) ;
114
119
}
120
+ // Pass again to loader to convert swagger to openapi
115
121
const converted = await loadAndBundleSpec ( bundledSpec . parsed ) ;
116
122
117
123
// If download url is not provided then use bundled yaml as a static file (see `postBuild`)
0 commit comments