Skip to content

Additional properties map to empty interfaces (OpenAPI v3) #76

Closed
@eysi09

Description

@eysi09

Hi!

Thinks for a great library, we use it quite a lot for generating API types for our frontend, based on the backend spec.

However, I'm having issues with additionalProperties (using the OpenAPI v3 spec) mapping to empty interfaces.

As an example from our source code, we have the following Typescript interfaces:

export type Primitive = string | number | boolean | null

export interface PrimitiveMap {
  [key: string]: Primitive
}

We use tsoa to generate an OpenAPI v3 spec which looks something like this:

"Primitive": {
  "anyOf": [
    {
      "type": "string"
    },
    {
      "type": "number",
      "format": "double"
    },
    {
      "type": "boolean"
    },
    {
      "type": "number",
      "enum": [
        null
      ],
      "nullable": true
    }
  ]
},
"PrimitiveMap": {
  "properties": {},
  "type": "object",
  "additionalProperties": {
    "$ref": "#/components/schemas/Primitive"
  }
},

AFAICT, the spec looks right. But when I generate the types with swagger-typescript-api I get the following results:

export type Primitive = string | number | boolean | "null" | (string & number & boolean & "null");

export interface PrimitiveMap {}

Notice how the PrimitiveMap is empty.

Instead, I would have expected:

export type Primitive = string | number | boolean | "null" | (string & number & boolean & "null");

export interface PrimitiveMap {
  [key: string]: Primitive
}

All help would be much appreciated!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions