Skip to content

openapi 3.1 enum array gets generated as union instead of union array #2129

@darkbasic

Description

@darkbasic

openapi-typescript version

7.6.0

Node.js version

20.17.0

OS + version

Arch Linux

Description

openapi 3.1 json:

{
    "name": "metrics",
    "in": "query",
    "required": true,
    "schema": {
        "type": "array",
        "enum": [
            "product_requirements_mandatory_completed",
            "product_requirements_optional_completed",
            "product_requirements_total_completed"
        ],
        "items": {
            "type": "string"
        },
        "minItems": 1
    }
},

Generated typings:

export interface operations {
  'analytics.data': {
    parameters: {
      query: {
        metrics:
          | 'product_requirements_mandatory_completed'
          | 'product_requirements_optional_completed'
          | 'product_requirements_total_completed'

Expected:

export interface operations {
  'analytics.data': {
    parameters: {
      query: {
        metrics: Array<
          | 'product_requirements_mandatory_completed'
          | 'product_requirements_optional_completed'
          | 'product_requirements_total_completed'
        >

Reproduction

analytics.json:

{
    "openapi": "3.1.0",
    "info": {
        "title": "API Portal",
        "version": "1.0.0",
        "description": "This is the **Analytics API** description"
    },
    "paths": {
        "\/analytics\/data": {
            "get": {
                "operationId": "analytics.data",
                "tags": [
                    "Analytics"
                ],
                "parameters": [
                    {
                        "name": "metrics",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "array",
                            "enum": [
                                "product_requirements_mandatory_completed",
                                "product_requirements_optional_completed",
                                "product_requirements_total_completed"
                            ],
                            "items": {
                                "type": "string"
                            },
                            "minItems": 1
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "`AnalyticsResponseResource`",
                        "content": {
                            "application\/json": {
                                "schema": {
                                    "$ref": "#\/components\/schemas\/AnalyticsResponseResource"
                                }
                            }
                        }
                    },
                    "403": {
                        "$ref": "#\/components\/responses\/AuthorizationException"
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "http": {
                "type": "http",
                "scheme": "bearer",
                "bearerFormat": ""
            }
        },
        "schemas": {
            "AnalyticsResponseDataResource": {
                "type": "object",
                "properties": {
                    "metricValues": {
                        "type": "array",
                        "items": {
                            "anyOf": [
                                {
                                    "type": "integer"
                                },
                                {
                                    "type": "number"
                                }
                            ]
                        }
                    }
                },
                "required": [
                    "metricValues"
                ],
                "title": "AnalyticsResponseDataResource"
            },
            "AnalyticsResponseResource": {
                "type": "object",
                "properties": {
                    "metricHeaders": {
                        "type": "string"
                    },
                    "data": {
                        "type": "array",
                        "items": {
                            "$ref": "#\/components\/schemas\/AnalyticsResponseDataResource"
                        }
                    }
                },
                "required": [
                    "metricHeaders",
                    "data"
                ],
                "title": "AnalyticsResponseResource"
            }
        },
        "responses": {
            "AuthorizationException": {
                "description": "Authorization error",
                "content": {
                    "application\/json": {
                        "schema": {
                            "type": "object",
                            "properties": {
                                "message": {
                                    "type": "string",
                                    "description": "Error overview."
                                }
                            },
                            "required": [
                                "message"
                            ]
                        }
                    }
                }
            }
        }
    }
}
npx openapi-typescript analytics.json -o analytics.ts

Expected result

Array<'product_requirements_mandatory_completed' | 'product_requirements_optional_completed'  | 'product_requirements_total_completed'>

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions