Skip to content

fix: preserve empty array as request body in stripEmptySlots#3451

Merged
mrlubos merged 4 commits intomainfrom
copilot/fix-empty-array-sending
Feb 25, 2026
Merged

fix: preserve empty array as request body in stripEmptySlots#3451
mrlubos merged 4 commits intomainfrom
copilot/fix-empty-array-sending

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

  • Identify root cause: stripEmptySlots in params.ts treats empty arrays as empty objects and removes them
  • Fix stripEmptySlots to skip array values (add !Array.isArray(value) check)
  • Add test case for empty array body
  • Build and verify fix - all 12 unit tests pass
  • Update 242 test snapshots (pnpm test:update)
  • Regenerate all examples (pnpm examples:generate)
Original prompt

This section details on the original issue you should resolve

<issue_title>Body of a json empty array should send to server</issue_title>
<issue_description>### Description

We have an API endpoint where you can update the value with an empty array. However, in the params.gen.ts the function stripEmptySlots removes the array from the body params since it is empty. Here is the params at the start of the function. After the function, the only one remaining is the path.

Image

I would think you could strip all parameters if empty for everything but the body?

Reproducible example or configuration

  await createClient({
    input: openApi,
    output: outpath,
    parser: {
      transforms: {
        propertiesRequiredByDefault: true
      }
    },
    plugins: [
      {
        name: '@hey-api/sdk',
        responseStyle: 'data',
        paramsStructure: 'flat'
      }
    ]
  })

The key call that is failing:

updateItemListForStateUpdates({ connectionId: "xxxxxx", body: [] })

As stated above, since the body is an empty array, the stripEmptySlots removes the body from the params group and then no body is include as part of the POST which causes the issue.

OpenAPI specification (optional)

{
    "openapi": "3.0.1",
    "info": {
        "title": "openHAB REST API",
        "contact": {
            "name": "openHAB",
            "url": "https://www.openhab.org/docs/"
        },
        "version": "8"
    },
    "servers": [
        {
            "url": "/rest"
        }
    ],
    "paths": {
        "/events/states/{connectionId}": {
            "post": {
                "tags": [
                    "events"
                ],
                "summary": "Changes the list of items a SSE connection will receive state updates to.",
                "operationId": "updateItemListForStateUpdates",
                "parameters": [
                    {
                        "name": "connectionId",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "description": "items",
                    "content": {
                        "application/json": {
                            "schema": {
                                "uniqueItems": true,
                                "type": "array",
                                "items": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "404": {
                        "description": "Unknown connectionId"
                    }
                }
            }
        }
    }
}
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@mrlubos</author><body>
@jsjames Can you add spec and config to reproduce?</body></comment_new>
<comment_new><author>@mrlubos</author><body>
@jsjames Drop it in this issue. Minimal spec is enough, don't need the whole document</body></comment_new>
<comment_new><author>@mrlubos</author><body>
@jsjames which version are you using? this looks quite outdated. Can you confirm the problem persists with the latest release?</body></comment_new>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel
Copy link

vercel bot commented Feb 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hey-api-docs Ready Ready Preview, Comment Feb 25, 2026 9:29pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 25, 2026

🦋 Changeset detected

Latest commit: 1518fda

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with sending empty array to server fix: preserve empty array as request body in stripEmptySlots Feb 25, 2026
@mrlubos
Copy link
Member

mrlubos commented Feb 25, 2026

@copilot you're going to have to make sure you updated snapshots with pnpm test:update and examples with pnpm examples:generate

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 25, 2026

@copilot you're going to have to make sure you updated snapshots with pnpm test:update and examples with pnpm examples:generate

Done in b1f91cd — ran pnpm test:update (242 snapshots updated) and pnpm examples:generate (all 14 examples regenerated) to propagate the !Array.isArray(value) change to all generated params.gen.ts files.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fonts.googleapis.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/openapi-ts/openapi-ts/examples/openapi-ts-tanstack-angular-query-experimental/node_modules/.bin/../@angular/cli/bin/ng.js build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Updated the changeset to include '@hey-api/openapi-ts' and modified the fix description.
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 25, 2026
@mrlubos mrlubos marked this pull request as ready for review February 25, 2026 21:28
@pullfrog
Copy link

pullfrog bot commented Feb 25, 2026

Leaping into action...

Pullfrog  | View workflow run | Using OpenCode | Triggered by Pullfrogpullfrog.com𝕏

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug 🔥 Broken or incorrect behavior. labels Feb 25, 2026
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 40.13%. Comparing base (320c30a) to head (1518fda).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3451   +/-   ##
=======================================
  Coverage   40.13%   40.13%           
=======================================
  Files         478      478           
  Lines       17479    17479           
  Branches     5295     5295           
=======================================
  Hits         7016     7016           
  Misses       8418     8418           
  Partials     2045     2045           
Flag Coverage Δ
unittests 40.13% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 25, 2026

Open in StackBlitz

@hey-api/codegen-core

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@3451

@hey-api/json-schema-ref-parser

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/json-schema-ref-parser@3451

@hey-api/nuxt

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@3451

@hey-api/openapi-ts

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@3451

@hey-api/shared

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/shared@3451

@hey-api/types

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/types@3451

@hey-api/vite-plugin

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@3451

commit: 1518fda

@mrlubos mrlubos merged commit cf74327 into main Feb 25, 2026
13 of 18 checks passed
@mrlubos mrlubos deleted the copilot/fix-empty-array-sending branch February 25, 2026 21:37
@hey-api hey-api bot mentioned this pull request Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🔥 Broken or incorrect behavior. lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Body of a json empty array should send to server

2 participants