Skip to content

Required properties in swagger.json create duplicate interfaces #394

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

Open
JustSamuel opened this issue Aug 21, 2022 · 3 comments
Open

Required properties in swagger.json create duplicate interfaces #394

JustSamuel opened this issue Aug 21, 2022 · 3 comments
Assignees
Labels
bug Something isn't working next release

Comments

@JustSamuel
Copy link

The following definitions

"definitions": {
    "BaseEntityWithoutId": {
      "required": [],
      "properties": {
        "createdAt": {
          "type": "string",
          "description": "The creation date of the object."
        },
        "updatedAt": {
          "type": "string",
          "description": "The last update date of the object."
        },
        "version": {
          "type": "integer",
          "description": "The current version of the object."
        }
      }
    },
    "BaseEntity": {
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "integer",
          "description": "The auto-generated object id."
        }
      },
      "allOf": [
        {
          "$ref": "#/definitions/BaseEntityWithoutId"
        }
      ]
    }
  }

Generates the following file:

export interface BaseEntityWithoutId {
  /** The creation date of the object. */
  createdAt?: string;

  /** The last update date of the object. */
  updatedAt?: string;

  /** The current version of the object. */
  version?: number;
}

export type BaseEntity = { id: number } & { id: number };

Removing the 'id' from required fixes it slightly and gives the following output:

export interface BaseEntityWithoutId {
  /** The creation date of the object. */
  createdAt?: string;

  /** The last update date of the object. */
  updatedAt?: string;

  /** The current version of the object. */
  version?: number;
}

export type BaseEntity = BaseEntityWithoutId & { id?: number };

Am I doing something wrong or is this a bug?

@JustSamuel
Copy link
Author

Fixed by this fork

@js2me
Copy link
Member

js2me commented Aug 22, 2022

@JustSamuel hello, it is a bug, will work on it

@js2me js2me self-assigned this Aug 22, 2022
@js2me js2me added bug Something isn't working next release labels Aug 22, 2022
@js2me
Copy link
Member

js2me commented Aug 29, 2022

Related to #342

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working next release
Projects
None yet
Development

No branches or pull requests

2 participants