Skip to content

Objects in query params are not being exploded #3437

@pgraug

Description

@pgraug

Description

When generating types for an endpoint with query parameters that contain an object, the default behaviour (style: 'form' and explode: true) should be to "explode" or "spread" the object.

That doesn't seem to be happening in the generated types.

style and explode are added to the IR.ParameterObject in packages/shared/src/openApi/3.0.x/parser/parameter.ts but they don't seem to be used for anything.

Reproducible example or configuration

I've made a small example of the bug here: https://stackblitz.com/edit/hey-api-example-hbrngrmq?file=src%2Fclient%2Ftypes.gen.ts

I currently get this:

export type PostFooData = {
  body?: never;
  path?: never;
  query: {
    externalId: number;
    pagination?: Pagination;
  };
  url: '/foo';
};

But it should output this:

export type PostFooData = {
  body?: never;
  path?: never;
  query: Pagination & {
    externalId: number;
  };
  url: '/foo';
};

Where the Pagination object is exploded which it should be by default for the default style (form).

OpenAPI specification (optional)

{
  "openapi": "3.0.0",
  "info": {
    "title": "OpenAPI 3.0.0 parameter explode object example",
    "version": "1"
  },
  "paths": {
    "/foo": {
      "post": {
        "parameters": [
          {
            "name": "externalId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "pagination",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/Pagination"
            }
          }
        ],
        "responses": {
          "default": {
            "description": "OK"
          }
        }
      }
    },
    "/bar": {
      "get": {
        "parameters": [
          {
            "name": "pagination",
            "in": "query",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/Pagination"
            }
          }
        ],
        "responses": {
          "default": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Pagination": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer",
            "format": "int32"
          },
          "pageSize": {
            "type": "integer",
            "format": "int32"
          }
        },
        "additionalProperties": false
      }
    }
  }
}

System information (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Broken or incorrect behavior.needs info ⏳More information needed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions