hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.39k stars 107 forks source link

Explode option in openapi schema is not being respected #1255

Closed traed closed 1 week ago

traed commented 1 week ago

Description

We have an OpenAPI 3.0 spec that specifies query params like this:

{
  "name": "example",
  "in": "query",
  "description": "",
  "required": false,
  "explode": false,
  "schema": {
      "type": "array",
      "items": {
          "type": "string"
      }
  }
}

We want it to generate a query param for the request like ?example=e1,e2 but when we generate the client we get ?example=e1&example=e2. We could supply the querySerializer argument to fix this but it should not be needed if already supplied in the spec.

The client config looks like this:

/** @type {import('@hey-api/client-fetch').Config} */
const config = {
    baseUrl: PUBLIC_API_URL,
    throwOnError: true,
    credentials: 'include'
};

Reproducible example or configuration

No response

OpenAPI specification (optional)

{
    "openapi": "3.0.0",
    "info": {
        "title": "Test API",
        "license": {
            "name": "Copyright 2024 Test inc."
        },
        "version": "0.1.0"
    },
    "servers": [
        {
            "url": "http://127.0.0.1:3001",
            "description": "API"
        }
    ],
    "paths": {
        "/test": {
            "get": {
                "summary": "Test route",
                "operationId": "get-test",
                "parameters": [
                    {
                        "name": "example",
                        "in": "query",
                        "description": "",
                        "required": false,
                        "explode": false,
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                ],
                "tags": [
                    "Test"
                ],
                "responses": {
                    "200": {
                        "description": "List of test items",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "title": "List of test items",
                                    "required": [
                                        "meta",
                                        "items"
                                    ],
                                    "properties": {
                                        "meta": {
                                            "type": "object",
                                            "title": "Meta data",
                                            "required": [
                                                "total"
                                            ],
                                            "properties": {
                                                "total": {
                                                    "type": "integer",
                                                    "minimum": 0,
                                                    "maximum": 9223372036854775807
                                                }
                                            }
                                        },
                                        "items": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/TestItem"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "token": {
                "type": "http",
                "description": "API token",
                "name": "",
                "in": "",
                "scheme": "bearer",
                "bearerFormat": "base32hex"
            }
        },
        "schemas": {
            "TestItem": {
                "type": "object",
                "required": [
                    "id"
                ],
                "properties": {
                    "id": {
                        "type": "string"
                    }
                }
            }
        }
    },
    "tags": []
}

System information (optional)

MacOS 14.6.1 Node v20.18.0 @hey-api/open-ts v0.55.1

mrlubos commented 1 week ago

Hi @traed, are you using the experimental parser? https://heyapi.dev/openapi-ts/configuration.html#parser

traed commented 1 week ago

Tried it now (openapi-ts -e -o src/lib/api -c @hey-api/client-fetch -i <PATH>) but got the same issue.

mrlubos commented 1 week ago

Thanks! I'll resolve it for the experimental parser, will let you know if the same fix works with the current parser when it's done

mrlubos commented 1 week ago

@traed try it in the next release with experimentalParser set to true, it should work!