api-platform / api-platform/api-doc-parser
fetchResource loads actual items from the API due to wrong queryParameter
- Ngôn ngữ chính
- TypeScript
- Star
- 113
- Fork
- 80
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
**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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.