@@ -4,9 +4,9 @@ import axios from "axios"
4
4
import RefParser from "@apidevtools/json-schema-ref-parser"
5
5
import jsf from "json-schema-faker"
6
6
import YAML from "yaml"
7
- import { pathOr } from "ramda"
8
7
import Admonition from "@theme/Admonition"
9
8
import CodeBlock from "@theme/CodeBlock"
9
+ import { pathOr } from "../../utils/pathOr"
10
10
11
11
const parser = new RefParser ( )
12
12
@@ -128,83 +128,86 @@ export default function ConfigMarkdown(props: { src: string; binary: string }) {
128
128
} )
129
129
130
130
useEffect ( ( ) => {
131
- axios . get ( props . src ) . then ( ( { data : schema } ) => {
132
- new Promise ( ( resolve , reject ) => {
133
- parser . dereference (
134
- schema ,
135
- {
136
- resolve : {
137
- ory : oryResolver ,
131
+ fetch ( props . src )
132
+ . then ( ( r ) => r . json ( ) )
133
+ . then ( ( schema ) => {
134
+ new Promise ( ( resolve , reject ) => {
135
+ parser . dereference (
136
+ schema ,
137
+ {
138
+ resolve : {
139
+ ory : oryResolver ,
140
+ } ,
138
141
} ,
139
- } ,
140
- ( err , result ) => ( err ? reject ( err ) : resolve ( result ) ) ,
141
- )
142
- } )
143
- . then ( ( schema : any ) => {
144
- const removeAdditionalProperties = ( o ) => {
145
- delete o [ "additionalProperties" ]
146
- if ( o . properties ) {
147
- Object . keys ( o . properties ) . forEach ( ( key ) =>
148
- removeAdditionalProperties ( o . properties [ key ] ) ,
149
- )
142
+ ( err , result ) => ( err ? reject ( err ) : resolve ( result ) ) ,
143
+ )
144
+ } )
145
+ . then ( ( schema : any ) => {
146
+ const removeAdditionalProperties = ( o ) => {
147
+ delete o [ "additionalProperties" ]
148
+ if ( o . properties ) {
149
+ Object . keys ( o . properties ) . forEach ( ( key ) =>
150
+ removeAdditionalProperties ( o . properties [ key ] ) ,
151
+ )
152
+ }
150
153
}
151
- }
152
-
153
- const enableAll = ( o ) => {
154
- if ( o . properties ) {
155
- Object . keys ( o . properties ) . forEach ( ( key ) => {
156
- if ( key === "enable" ) {
157
- o . properties [ key ] = true
158
- }
159
- enableAll ( o . properties [ key ] )
160
- } )
154
+
155
+ const enableAll = ( o ) => {
156
+ if ( o . properties ) {
157
+ Object . keys ( o . properties ) . forEach ( ( key ) => {
158
+ if ( key === "enable" ) {
159
+ o . properties [ key ] = true
160
+ }
161
+ enableAll ( o . properties [ key ] )
162
+ } )
163
+ }
161
164
}
162
- }
163
-
164
- removeAdditionalProperties ( schema )
165
- enableAll ( schema )
166
- if ( schema . definitions ) {
167
- Object . keys ( schema . definitions ) . forEach ( ( key ) => {
168
- removeAdditionalProperties ( schema . definitions [ key ] )
169
- enableAll ( schema . definitions [ key ] )
170
- } )
171
- }
172
165
173
- jsf . option ( {
174
- useExamplesValue : true ,
175
- useDefaultValue : false , // do not change this!!
176
- fixedProbabilities : true ,
177
- alwaysFakeOptionals : true ,
178
- } )
166
+ removeAdditionalProperties ( schema )
167
+ enableAll ( schema )
168
+ if ( schema . definitions ) {
169
+ Object . keys ( schema . definitions ) . forEach ( ( key ) => {
170
+ removeAdditionalProperties ( schema . definitions [ key ] )
171
+ enableAll ( schema . definitions [ key ] )
172
+ } )
173
+ }
179
174
180
- const values = jsf . generate ( schema )
181
- const doc = YAML . parseDocument ( YAML . stringify ( values ) )
175
+ jsf . option ( {
176
+ useExamplesValue : true ,
177
+ useDefaultValue : false , // do not change this!!
178
+ fixedProbabilities : true ,
179
+ alwaysFakeOptionals : true ,
180
+ } )
182
181
183
- const comments = [ `# ${ pathOr ( props . binary , [ "title" ] , schema ) } ` , "" ]
182
+ const values = jsf . generate ( schema )
183
+ const doc = YAML . parseDocument ( YAML . stringify ( values ) )
184
184
185
- const description = pathOr ( "" , [ "description" ] , schema )
186
- if ( description ) {
187
- comments . push ( " " + description )
188
- }
185
+ const comments = [
186
+ `# ${ pathOr ( props . binary , [ "title" ] , schema ) } ` ,
187
+ "" ,
188
+ ]
189
189
190
- console . log ( { doc } )
190
+ const description = pathOr ( "" , [ "description" ] , schema )
191
+ if ( description ) {
192
+ comments . push ( " " + description )
193
+ }
191
194
192
- doc . commentBefore = comments . join ( "\n" )
193
- doc . spaceAfter = false
194
- doc . spaceBefore = false
195
+ doc . commentBefore = comments . join ( "\n" )
196
+ doc . spaceAfter = false
197
+ doc . spaceBefore = false
195
198
196
- doc . contents . items . forEach ( enhance ( schema , [ ] ) )
199
+ doc . contents . items . forEach ( enhance ( schema , [ ] ) )
197
200
198
- return Promise . resolve ( {
199
- // schema,
200
- // values,
201
- yaml : doc . toString ( ) ,
201
+ return Promise . resolve ( {
202
+ // schema,
203
+ // values,
204
+ yaml : doc . toString ( ) ,
205
+ } )
202
206
} )
203
- } )
204
- . then ( ( out ) => {
205
- setContent ( out . yaml )
206
- } )
207
- } )
207
+ . then ( ( out ) => {
208
+ setContent ( out . yaml )
209
+ } )
210
+ } )
208
211
} , [ props . src ] )
209
212
210
213
return (
0 commit comments