@@ -189,31 +189,41 @@ function findRelatedClass(docs, property) {
189
189
throw new Error ( `Cannot find the class related to ${ property [ "@id" ] } .` ) ;
190
190
}
191
191
192
- async function addFilters ( api ) {
193
- for ( const resource of api . resources ) {
194
- const resourceFilters = [ ] ;
192
+ function addFilters ( api ) {
193
+ const promises = [ ] ;
195
194
196
- let response = await fetchResource ( resource . url ) ;
195
+ for ( const resource of api . resources ) {
196
+ let promise = fetchResource ( resource . url ) . then ( response => {
197
+ const resourceFilters = [ ] ;
197
198
198
- if ( response . filters ) {
199
- for ( const filter of response . filters ) {
200
- let property = filter . property ;
199
+ if ( response . filters ) {
200
+ for ( const filter of response . filters ) {
201
+ let property = filter . property ;
201
202
202
- // TODO : To prevent PropertyFilter, maybe should be handle specifically ?
203
- if ( property === null ) {
204
- continue ;
205
- }
203
+ // TODO : To prevent PropertyFilter, maybe should be handle specifically ?
204
+ if ( property === null ) {
205
+ continue ;
206
+ }
206
207
207
- const resourceFilter = new Filter ( property , filter . variable ) ;
208
+ const resourceFilter = new Filter ( property , filter . variable ) ;
208
209
209
- resourceFilters . push ( resourceFilter ) ;
210
+ resourceFilters . push ( resourceFilter ) ;
211
+ }
210
212
}
211
- }
212
213
213
- resource . filters = resourceFilters ;
214
+ return resourceFilters ;
215
+ } ) ;
216
+
217
+ promises . push ( promise ) ;
214
218
}
215
219
216
- return api ;
220
+ return Promise . all ( promises ) . then ( values => {
221
+ api . resources . map ( ( resource , index ) => {
222
+ resource . filters = values [ index ] ;
223
+ } ) ;
224
+
225
+ return api ;
226
+ } ) ;
217
227
}
218
228
219
229
/**
@@ -483,6 +493,7 @@ export default function parseHydraDocumentation(entrypointUrl, options = {}) {
483
493
)
484
494
. then ( ( { api, response, status } ) => {
485
495
return addFilters ( api ) . then ( api => {
496
+ console . log ( api ) ;
486
497
return { api, response, status } ;
487
498
} ) ;
488
499
} ) ;
0 commit comments