Closed
Description
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
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
- I’m willing to open a PR (see CONTRIBUTING.md)
Metadata
Metadata
Assignees
Labels
No labels