api-platform / api-platform/api-doc-parser

fetchResource loads actual items from the API due to wrong queryParameter

Offen
#115 4 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @soyuka Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
113
Forks
80
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

**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.

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

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

* [Link to fetchJsonLd](https://github.com/api-platform/api-doc-parser/blob/f8610390c8bd5f8f5e641e3fd240c79af1f958f9/src/hydra/fetchJsonLd.ts#L22)
* [Link to fetchResource calling fetch()](https://github.com/api-platform/api-doc-parser/blob/f8610390c8bd5f8f5e641e3fd240c79af1f958f9/src/hydra/fetchResource.ts#L11)
* [fetch() docs on mdn](https://developer.mozilla.org/en-US/docs/Web/API/fetch#init)

**How to reproduce**

**Possible Solution**

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

```js
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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.