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

fetchResource loads actual items from the API due to wrong queryParameter

未关闭
#115 4 条评论 0 个 reaction 已指派 1 人 已被 @soyuka 认领 在 GitHub 查看
主要语言
TypeScript
星标
113
派生
80
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。