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

fetchResource loads actual items from the API due to wrong queryParameter

Aperta
#115 4 commenti 0 reazioni 1 assegnatario Rivendicata da @soyuka Vedi su GitHub
Lingua principale
TypeScript
Stelle
113
Fork
80
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.