Skip to content

[BUG] GET methos query option bug #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rhkdgns95 opened this issue Apr 12, 2021 · 1 comment · Fixed by #245
Closed

[BUG] GET methos query option bug #236

rhkdgns95 opened this issue Apr 12, 2021 · 1 comment · Fixed by #245

Comments

@rhkdgns95
Copy link

rhkdgns95 commented Apr 12, 2021

Bug Report Quick Checklist

  • I am on the latest version of swagger-typescript-api (v8.0.3)
  • I use package manager yarn.
  • I run swagger-typescript-api on OS Window 10 PRO.
  • I run swagger-typescript-api on Node.js v12.16.1

Describe the bug

(async () => {
  const res = await api.pet.findPetsByStatus({
    status: ["pending", "available"],
  });
  console.log("RES: ", res);
})();

image

  • It becomes a code generator normally.
  • However, if you write an array string in the query content when requesting the GET method, the character value is requested along with the index value, not the string corresponding to the first index of the string array.

ex) https://petstore.swagger.io/v2/pet/findByStatus?status=available&status=pending&status=sold
image

Current situation

0=p&1=v     // pending [0] : "p" + available [1] : "v"

Expected

status=pending&status=solid&status=available

To Reproduce

  • _generated_/index.ts
  private addArrayQueryParam(query: QueryParamsType, key: string) {
    const value = query[key];
    if (Array.isArray(value) && ["string", "number", "boolean"].includes(typeof value[0])) {
      return value.map((v) => `${key}=${v}`).join("&");
    } else {
      return `${value.map(this.addQueryParam).join("&")}`;
    }
  }

Refs

@SaschaGalley
Copy link
Contributor

I have created a pull request for this issue, hope this can get merged soon.

@js2me js2me linked a pull request Apr 23, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants