Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"type": "object" With No Addtional Properties Generates Object Allowing Any Properties of Type Unknown #1183

Open
buffalom opened this issue Oct 22, 2024 · 2 comments
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon
Milestone

Comments

@buffalom
Copy link

buffalom commented Oct 22, 2024

Description

For a schema with "additionalProperties": false, the generator produces an object that allows any properties with type unknown:

export type ProductA = {
  [key: string]: unknown;
};

In my use case (OpenAPI spec in Stackblitz in swagger-usecase.json), this leads to issues where a type extends another type with any properties:

export type Product = {
    $type: string;
};

export type ProductA = Product & {
    [key: string]: unknown;
};

export type ProductB = Product & {
    otherProperty: string;
};

Instead, I would expect "additionalProperties": false to generate the following:

export type ProductA = {
  [key: string]: never;
};

That way, checks like 'otherProperty' in product would actually work and narrow down the type.

However, I am unsure if this would work in all cases, or if unknown is correct in some cases.

Reproducible example or configuration

https://stackblitz.com/edit/hey-api-openapi-ts-additional-properties-bug-repro?file=src%2Fclient%2Ftypes.gen.ts&view=editor

OpenAPI specification (optional)

{
  "openapi": "3.0.1",
  "info": {
    "title": "Test",
    "version": "v1"
  },
  "components": {
    "schemas": {
      "ProductA": {
        "allOf": [
          {
            "type": "object",
            "additionalProperties": false
          }
        ]
      }
    }
  }
}

System information (optional)

"@hey-api/openapi-ts": "0.53.11"
@buffalom buffalom added the bug 🔥 Something isn't working label Oct 22, 2024
Copy link

stackblitz bot commented Oct 22, 2024

@mrlubos mrlubos added this to the Parser milestone Oct 22, 2024
@mrlubos mrlubos added the prioritized 🚚 This issue has been prioritized and will be worked on soon label Oct 22, 2024
@mrlubos
Copy link
Member

mrlubos commented Oct 22, 2024

Thanks @buffalom, added to the parser milestone and will be addressed there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon
Projects
None yet
Development

No branches or pull requests

2 participants