这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

When additionalProperties: false, the generator produced v.objectWithRest({}, v.never()), creating unusable TypeScript types with [x: string]: undefined index signatures that conflict with actual properties.

Changes

  • Modified packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts to detect additionalProperties.type === 'never' and emit v.strictObject() instead
  • Added test coverage for additionalProperties: false in both simple and nested object schemas
  • Updated test snapshots to reflect the corrected output

Example

Before:

// Generated unusable type with conflicting index signature
v.objectWithRest({
    status: v.optional(v.picklist(['approved', 'declined', 'pending'])),
    tier_id: v.optional(v.string())
}, v.never())
// Type: { [x: string]: undefined; status?: "approved" | ...; tier_id?: string }

After:

// Generates clean, usable type
v.strictObject({
    status: v.optional(v.picklist(['approved', 'declined', 'pending'])),
    tier_id: v.optional(v.string())
})
// Type: { status?: "approved" | ...; tier_id?: string }

Objects with additionalProperties as a schema (not false) continue using v.objectWithRest() correctly.

Original prompt

This section details on the original issue you should resolve

<issue_title>New additionalProperties behavior causes unusable schemas in some cases</issue_title>
<issue_description>### Description

The new additionalProperties handling behavior introduced in #2870 causes issues for Valibot schemas where additionalProperties is false because it generates type errors like this:

TS2322 [ERROR]: Type '{ status: "approved"; calendar_membership_tier_id: string; }' is not assignable to type '{ [x: string]: undefined; status?: "approved" | "declined" | "pending" | undefined; calendar_membership_tier_id?: string | null | undefined; }'.
  Property 'status' is incompatible with index signature.
    Type '"approved"' is not assignable to type 'undefined'.
        membership: { status: "approved" },

This example comes from using the OpenAPI schema at https://dash.readme.com/api/v1/api-registry/a5goh1rvmhgp0l60. As you can see it's generating schema types that start with { [x: string]: undefined; ... } which makes it impossible to use those types in general because any properties you provide will always conflict with that index signature. This problematic index signature is happening because @hey-api/openapi-ts is using v.objectWithRest({...}}, v.never()) for these schemas, we should instead use the strictObject notation for these situations which is the correct way to forbid additional properties on an object in Valibot.

Reproducible example or configuration

import { createClient } from "npm:@hey-api/openapi-ts";

await createClient({
  input: "https://dash.readme.com/api/v1/api-registry/a5goh1rvmhgp0l60",
  output: {
    path: "./src/generated",
    indexFile: false,
  },
  plugins: [
    "valibot",
    {
      name: "@hey-api/client-fetch",
      throwOnError: true,
    },
    {
      name: "@hey-api/transformers",
      dates: true,
    },
    {
      name: "@hey-api/sdk",
      transformer: true,
      validator: true,
      asClass: true,
      responseStyle: "data",
    },
  ],
});
import { vGetV1CalendarListPeopleResponse } from "./generated/valibot.gen.ts";
import { InferInput } from "valibot";
const person: InferInput<typeof vGetV1CalendarListPeopleResponse.entries.entries.item> = { membership: { status: "approved", calendar_membership_tier_id: "tier_id" } };

OpenAPI specification (optional)

https://dash.readme.com/api/v1/api-registry/a5goh1rvmhgp0l60

System information (optional)

No response</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 Nov 7, 2025

🦋 Changeset detected

Latest commit: 3786d2b

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 Nov 7, 2025

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

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Nov 8, 2025 2:39am

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix additionalProperties behavior causing schema issues Fix Valibot strictObject for additionalProperties: false Nov 7, 2025
Copilot finished work on behalf of mrlubos November 7, 2025 22:26
Copilot AI requested a review from mrlubos November 7, 2025 22:26
@codecov
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

❌ Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 28.42%. Comparing base (52fbf53) to head (3786d2b).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
.../openapi-ts/src/plugins/valibot/v1/toAst/object.ts 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2945      +/-   ##
==========================================
+ Coverage   28.27%   28.42%   +0.14%     
==========================================
  Files         389      394       +5     
  Lines       35223    35266      +43     
  Branches     1933     1934       +1     
==========================================
+ Hits         9959    10024      +65     
+ Misses      25237    25215      -22     
  Partials       27       27              
Flag Coverage Δ
unittests 28.42% <0.00%> (+0.14%) ⬆️

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.

@mrlubos mrlubos marked this pull request as ready for review November 8, 2025 02:39
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 8, 2025
@dosubot dosubot bot added the bug 🔥 Something isn't working label Nov 8, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 8, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2945
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2945
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2945
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2945

commit: 3786d2b

@mrlubos mrlubos merged commit fe8a27b into main Nov 8, 2025
16 of 17 checks passed
@mrlubos mrlubos deleted the copilot/fix-additional-properties-issue branch November 8, 2025 03:02
@hey-api hey-api bot mentioned this pull request Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🔥 Something isn't working size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New additionalProperties behavior causes unusable schemas in some cases

2 participants