Skip to content

Should generate Aliases?: null | string[] instead of Aliases?: string[] #1083

Closed
@loynoir

Description

@loynoir

Description

Should generate Aliases?: null | string[] instead of Aliases?: string[]

Name Version
openapi-typescript 5.4.1
Node.js v18.15.0
OS + version ArchLinux

Story
Docker is using swagger 2.0 https://github.com/moby/moby/blob/master/docs/api/v1.42.yaml

When I use version 6.2.1, I got Swagger 2.0 and older no longer supported. Please use v5..

But when I use version 5.4.1, found type not very correct.

Not sure it is a bug in openapi-typescript, or a bug in docker api spec.

Reproduction

https://github.com/moby/moby/blob/a343ed13e556ec97a26bd5fc34b069a64f86f16b/docs/api/v1.42.yaml#L2406-L2427

  EndpointSettings:
    description: "Configuration for a network endpoint."
    type: "object"
    properties:
      # Configurations
      IPAMConfig:
        $ref: "#/definitions/EndpointIPAMConfig"
      Links:
        type: "array"
        items:
          type: "string"
        example:
          - "container_1"
          - "container_2"
      Aliases:
        type: "array"
        items:
          type: "string"
        example:
          - "server_x"
          - "server_y"

Actual result

$ npm add -D openapi-typescript@5.4.1 
$ npm exec -- openapi-typescript /path/to/docker/api/v1.42.yaml --output v1.42.d.ts

Partial output

  EndpointSettings: {
    IPAMConfig?: definitions["EndpointIPAMConfig"];
    /**
     * @example [
     *   "container_1",
     *   "container_2"
     * ]
     */
    Links?: string[];
    /**
     * @example [
     *   "server_x",
     *   "server_y"
     * ]
     */
    Aliases?: string[];

But in runtime, .Aliases maybe null.

      const a: { Aliases?: string[] } = {
        // @ts-expect-error: not assignable
        Aliases: null,
      }
      void a

So, the type is wrong.

Expected result

    Aliases?: null | string[];

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