Skip to content

Property without type should be declared as unknown #1039

@ggrossetie

Description

@ggrossetie

Description

Name Version
openapi-typescript 6.1.1
Node.js 18.12.2
OS + version Ubuntu 22.04.2

Reproduction

  1. Create a file named api.json with the following content:

api.json

{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "User": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "Info": {
            "nullable": false
          }
        }
      }
    }
  }
}
  1. Run openapi-typescript:
$ npx openapi-typescript api.json --output type.ts
✨ openapi-typescript 6.1.1
🚀 api.json → file:///path/to/type.ts [12ms]
  1. You should get the following result:

type.ts

/**
 * This file was auto-generated by openapi-typescript.
 * Do not make direct changes to the file.
 */


export type paths = Record<string, never>;

export type webhooks = Record<string, never>;

export interface components {
  schemas: {
    User: {
      Info?: Record<string, never>;
    };
  };
  responses: never;
  parameters: never;
  requestBodies: never;
  headers: never;
  pathItems: never;
}

export type external = Record<string, never>;

export type operations = Record<string, never>;

As you can see, schemas.User.Info is defined as Record<string, never> which is incorrect because Info might contain a string, number or boolean and not necessarily an object.

Expected result

export interface components {
  schemas: {
    User: {
      Info?: unknown;
    };
  };
  responses: never;
  parameters: never;
  requestBodies: never;
  headers: never;
  pathItems: never;
}

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions