Skip to content

AdditionalProperties in swagger definition creates broken TS interface #525

Open
@ph3b

Description

@ph3b

Hi!

First of all, great library! Have been using it for a long time and saves so much time aligning contracts between frontend and backends. Great work!

Today I stumbled upon a weird bug while upgrading rom v2 -> v3.

In my swagger definition I have the following object:

Microsoft.AspNetCore.Mvc.ProblemDetails": {
        "required": [
          "detail",
          "instance",
          "title",
          "type"
        ],
        "type": "object",
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "detail": {
            "type": "string"
          },
          "instance": {
            "type": "string"
          }
        },
        "additionalProperties": {
          "type": "object",
          "additionalProperties": false
        }
      }
}

This get's "translated" to the following TS interface:

export interface MicrosoftAspNetCoreMvcProblemDetails {
    [name: string]: {
      [key: string]: any;
    };
    type: string;
    title: string;
    status?: null | number; // int32
    detail: string;
    instance: string;
  }

Which TypeScript immediately complains about with the following message:
Property 'title' of type 'string' is not assignable to 'string' index type '{ [key: string]: any; }'.ts(2411)

image

Using:
dtsgenerator: 3.13.2
typescript: 4.4.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions