Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchResource loads actual items from the API due to wrong queryParameter #115

Open
Sirs0ri opened this issue Jul 1, 2022 · 0 comments
Open

Comments

@Sirs0ri
Copy link

Sirs0ri commented Jul 1, 2022

API Platform version(s) affected: 2.6.8

Description

The API doc parser uses fetch() via the fetchResource() method to load API metadata, and fails to apply the query parameter { itemsperpage: 0 } correctly to limit the request to only metadata and no API items.

fetchResource() tries to set the query parameter via a secondary options parameter, however fetch() doesn't support that - params have to be part of the url instead.

// Current code:
fetchJsonLd(
  resourceUrl,
  Object.assign({ itemsPerPage: 0 }, options)
)

// Fixed code:
fetchJsonLd(
  resourceUrl + "?itemsPerPage=0",
  options
)

How to reproduce

Possible Solution

Replace the Object.assign() call with an URL including the query parameter, possibly by building an URL:

const url = new URL(resource.url);
const params = new URLSearchParams(["itemsPerPage", 0]);
url.search = params.toString();

fetchJsonLd(url, options)

Additional Context

Please excuse that my code examples are in plain JS, not TS, since I'm not familiar enough with typescript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant