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

New additionalProperties behavior causes unusable schemas in some cases #2944

@zookatron

Description

@zookatron

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

Metadata

Metadata

Assignees

Labels

bug 🔥Something isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions