Skip to content

fix(sdk): required requestBody object properties become optional in flat paramsStructure#3458

Merged
mrlubos merged 4 commits intomainfrom
copilot/fix-requestbody-object-properties
Feb 26, 2026
Merged

fix(sdk): required requestBody object properties become optional in flat paramsStructure#3458
mrlubos merged 4 commits intomainfrom
copilot/fix-requestbody-object-properties

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

When using paramsStructure: 'flat', required properties from an inline requestBody object schema were incorrectly generated as optional — and the parameters argument itself was marked optional even when required fields existed.

Root Cause

In getSignatureParameters(), property.required?.includes(originalName) was evaluated against the individual property schema (which never has a required array), instead of the parent schema.

// Before — always false; `property` is a leaf schema node
isRequired: property.required?.includes(originalName) ?? false,

// After — reads the correct parent schema required array
isRequired: operation.body.schema.required?.includes(originalName) ?? false,

Changes

  • packages/openapi-ts/src/plugins/@hey-api/sdk/shared/signature.ts — fix isRequired lookup to use operation.body.schema.required instead of property.required
  • packages/openapi-ts-tests/sdks/__snapshots__/opencode/ — update flat and export-all snapshots to reflect corrected required/optional signatures across 14 affected operations (e.g. appLog, mcpAdd, tuiAppendPrompt, sessionInit, etc.)

Example

// Before
export const appLog = (parameters?: {
    service?: string;
    level?: 'debug' | 'info' | 'error' | 'warn';
    message?: string;
}) => { ... }

// After
export const appLog = (parameters: {
    service: string;
    level: 'debug' | 'info' | 'error' | 'warn';
    message: string;
}) => { ... }
Original prompt

This section details on the original issue you should resolve

<issue_title>sdk(flat): required requestBody object properties become optional</issue_title>
<issue_description>## Summary
When using @hey-api/sdk with paramsStructure: 'flat', required properties from an object request body are generated as optional in method signatures.

Reproduction

Config:

sdk({
  paramsStructure: 'flat',
})

OpenAPI operation (simplified):

requestBody:
  required: true
  content:
    application/json:
      schema:
        type: object
        required: [owner]
        properties:
          owner:
            type: string
          contact_list:
            type: string

Actual output

Generated SDK method signature is optional:

delAll(parameters?: {
  owner?: string;
  contact_list?: string;
})

Expected output

owner should be required (and parameters required because at least one flattened field is required):

delAll(parameters: {
  owner: string;
  contact_list?: string;
})

Notes

This only affects flattened request-body properties in paramsStructure: 'flat'.
Path/query requiredness works as expected.

Suspected cause

In getSignatureParameters(), requiredness is read from property.required (which does not exist on schema properties), instead of operation.body.schema.required.
</issue_description>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@bolt-new-by-stackblitz
Copy link

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

@changeset-bot
Copy link

changeset-bot bot commented Feb 26, 2026

🦋 Changeset detected

Latest commit: bf50a55

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

@vercel
Copy link

vercel bot commented Feb 26, 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 26, 2026 10:35pm

Request Review

…aramsStructure

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
…amsStructure

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix required requestBody object properties in SDK fix(sdk): required requestBody object properties become optional in flat paramsStructure Feb 26, 2026
@mrlubos mrlubos marked this pull request as ready for review February 26, 2026 22:36
@pullfrog
Copy link

pullfrog bot commented Feb 26, 2026

Leaping into action...

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

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug 🔥 Broken or incorrect behavior. labels Feb 26, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 26, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 26, 2026

Open in StackBlitz

@hey-api/codegen-core

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

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

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

@hey-api/nuxt

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

@hey-api/openapi-ts

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

@hey-api/shared

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

@hey-api/types

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

@hey-api/vite-plugin

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

commit: bf50a55

@mrlubos mrlubos merged commit 75d9833 into main Feb 26, 2026
11 of 16 checks passed
@mrlubos mrlubos deleted the copilot/fix-requestbody-object-properties branch February 26, 2026 23:19
@hey-api hey-api bot mentioned this pull request Feb 26, 2026
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 40.11%. Comparing base (11f5470) to head (bf50a55).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...pi-ts/src/plugins/@hey-api/sdk/shared/signature.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3458   +/-   ##
=======================================
  Coverage   40.11%   40.11%           
=======================================
  Files         478      478           
  Lines       17488    17488           
  Branches     5294     5294           
=======================================
  Hits         7016     7016           
  Misses       8425     8425           
  Partials     2047     2047           
Flag Coverage Δ
unittests 40.11% <0.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.

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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sdk(flat): required requestBody object properties become optional

2 participants