Skip to content
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

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

Open
1 of 2 tasks
darkbasic opened this issue Jan 31, 2025 · 0 comments
Open
1 of 2 tasks
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@darkbasic
Copy link

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

@darkbasic darkbasic added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

1 participant