acacode / acacode/swagger-typescript-api

--extract-request-params behavior depends on presence of query params

未关闭
#322 4 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
4.1k
派生
436
PR 合并指标
30 天内没有已合并 PR

描述

The procedure call template uses the presence of `requestParams` to decide whether to actually do the `--extract-request-params` behavior, i.e., put path _and_ query params in a single object that is the first argument to the request function.

If `requestParams` is falsy, we essentially fall back to the default behavior.

https://github.com/acacode/swagger-typescript-api/blob/7df956c236d1e7fc051658cd7012c8ea22286b44/templates/default/procedure-call.eta#L24-L34

The problem (for me, anyway) is that `requestParams` is always null for a given route if the route takes no query params:

https://github.com/acacode/swagger-typescript-api/blob/7df956c236d1e7fc051658cd7012c8ea22286b44/src/routes.js#L295-L302

So, for requests that only have path params but no query params, we will never generate a params object representing the path params, instead inlining them as individual arguments. I was able to confirm that commenting out `if (!queryParams || !queryParams.length) return null; ` produces the desired behavior.

This behavior is counterintuitive given the documentation for the flag. It seems clear that both path params and query params are meant to be considered "request params", which means `requestParams` should not be null if there are path params.

```
--extract-request-params extract request params to data contract (default: false)
Also combine path params and query params into one object
```

If getting rid of that check would break the default `extractRequestParams = false` case, then maybe something like this would be appropriate:

```diff
- if (!queryParams || !queryParams.length) return null;
+ if (!extractRequestParams && (!queryParams || !queryParams.length)) return null;
```

贡献指南

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

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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