diff --git a/src/hydra/addParameters.js b/src/hydra/addParameters.js index 17f7dc6..20649d8 100644 --- a/src/hydra/addParameters.js +++ b/src/hydra/addParameters.js @@ -1,25 +1,27 @@ import Parameter from "../Parameter"; import fetchResource from "./fetchResource"; -export default api => { +export default (api, options = {}) => { const promises = []; for (const resource of api.resources) { - const promise = fetchResource(resource.url).then(({ parameters = [] }) => { - const resourceParameters = []; - parameters.forEach(({ property = null, required, variable }) => { - if (null === property) { - return; - } - - const { range = null } = - resource.fields.find(({ name }) => property === name) || {}; - - resourceParameters.push(new Parameter(variable, range, required, "")); - }); - - return resourceParameters; - }); + const promise = fetchResource(resource.url, options).then( + ({ parameters = [] }) => { + const resourceParameters = []; + parameters.forEach(({ property = null, required, variable }) => { + if (null === property) { + return; + } + + const { range = null } = + resource.fields.find(({ name }) => property === name) || {}; + + resourceParameters.push(new Parameter(variable, range, required, "")); + }); + + return resourceParameters; + } + ); promises.push(promise); } diff --git a/src/hydra/fetchResource.js b/src/hydra/fetchResource.js index 7a12e67..aca4cdb 100644 --- a/src/hydra/fetchResource.js +++ b/src/hydra/fetchResource.js @@ -1,8 +1,11 @@ import fetchJsonLd from "./fetchJsonLd"; import get from "lodash.get"; -export default async resourceUrl => { - return await fetchJsonLd(resourceUrl, { itemsPerPage: 0 }).then( +export default async (resourceUrl, options = {}) => { + return await fetchJsonLd( + resourceUrl, + Object.assign({ itemsPerPage: 0 }, options) + ).then( d => ({ parameters: get(d, "body.hydra:search.hydra:mapping") }), diff --git a/src/hydra/parseHydraDocumentation.js b/src/hydra/parseHydraDocumentation.js index 11e37d7..5271be3 100644 --- a/src/hydra/parseHydraDocumentation.js +++ b/src/hydra/parseHydraDocumentation.js @@ -449,6 +449,6 @@ export default function parseHydraDocumentation(entrypointUrl, options = {}) { }) ) .then(({ api, response, status }) => - addParameters(api).then(api => ({ api, response, status })) + addParameters(api, options).then(api => ({ api, response, status })) ); }