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

OpenAPI -> TypeScript adds wildcard prop to each type #24

Open
sashafklein opened this issue May 26, 2022 · 2 comments
Open

OpenAPI -> TypeScript adds wildcard prop to each type #24

sashafklein opened this issue May 26, 2022 · 2 comments

Comments

@sashafklein
Copy link

I'm using typeconv to convert some OpenAPI schemas into TypeScript interfaces. Generally working great, but I noticed one thing.

When I start with the below OpenAPI spec:

{
    components: {
      schemas: {
        Person: {
          type: "object",
          properties: {
            first_name: {
              type: "string",
              example: "Pam",
            },
            last_name: {
              type: "string",
              example: "Halpert",
            },
          },
          required: [],
          title: "Person",
        },
      },
    },
  };

It produces the following type:

export interface Person {
    first_name?: string;
    last_name?: string;
    [key: string]: any;
}

Almost perfect, except for that last line:

    [key: string]: any;

It's appending a wildcard accessor to my type, for some reason, essentially asserting that on Person, any string can access any value, which makes the type not particularly helpful.

Any ideas what this is happening? I could get rid of this line through string manipulation, but I wonder why it's happening, and if there's some option I'm missing.

@jdcookie
Copy link

jdcookie commented May 31, 2022

Add

additionalProperties: false

Person: {
          type: "object",
          properties: {
            first_name: {
              type: "string",
              example: "Pam",
            },
            last_name: {
              type: "string",
              example: "Halpert",
            },
          },
          additionalProperties: false,
          required: [],
          title: "Person",
        },

@ChuckJonas
Copy link

ChuckJonas commented Jun 14, 2022

It would be nice if there was a flag to control this... I know it's technically incorrect, but a lot of 3rd party schema omit specifying additionalProperties: false. If you're trying to use this library to improve developer productivity and reduce bugs when interactive with one of these api, then having [key: string]: any; defeats the usefulness of this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants