Skip to content

[BUG][typescript] Array items are incorrectly marked as nullable #23905

Open

Description

@HitkoDev
Description

Under some very specific conditions, | null is added to array item type when it shouldn't be there.

openapi-generator version

7.22.0

OpenAPI declaration file content or url
{
    "info": {
        "description": "Test",
        "title": "test",
        "version": "1.0"
    },
    "openapi": "3.1.0",
    "servers": [
        {
            "url": "http://localhost:5000"
        }
    ],
    "components": {
        "schemas": {
            "Response": {
                "title": "Response",
                "type": "object",
                "properties": {
                    "nullable": {
                        "type": "array",
                        "default": null,
                        "items": {
                            "anyOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "type": "null"
                                }
                            ]
                        }
                    }
                },
                "required": [
                    "nullable"
                ]
            },
            "ResponseGet": {
                "title": "ResponseGet",
                "type": "object",
                "properties": {
                    "nonNullable": {
                        "type": "array",
                        "default": null,
                        "items": {
                            "type": "string"
                        }
                    }
                },
                "required": [
                    "nonNullable"
                ]
            }
        }
    },
    "paths": {
        "/api": {
            "get": {
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ResponseGet"
                                }
                            }
                        },
                        "description": "OK"
                    }
                }
            }
        }
    }
}
Generation Details
{
    "generatorName": "typescript"
}
Steps to reproduce

When generating code for the above API spec, the Response class should have 'nullable': Array<string | null>; and the ResponseGet class should have 'nonNullable': Array<string>;. Instead, both receive Array<string | null>;. I'm unable to determine the exact cause; for example, changing "#/components/schemas/ResponseGet" -> "#/components/schemas/Response" causes both models to be generated correctly. Removing "default": null also seems to somehow fix the bug.

Activity

  1. KannaKim commented on Jun 28, 2026

    @KannaKim
    Contributor

    Alternatively, adding

    {
    "nullable": false
    }

    fix the issue.
    Full yaml looks like this:

    {
        "info": {
            "description": "Test",
            "title": "test",
            "version": "1.0"
        },
        "openapi": "3.1.0",
        "servers": [
            {
                "url": "http://localhost:5000"
            }
        ],
        "components": {
            "schemas": {
                "Response": {
                    "title": "Response",
                    "type": "object",
                    "properties": {
                        "nullable": {
                            "type": "array",
                            "default": null,
                            "items": {
                                "anyOf": [
                                    {
                                        "type": "string"
                                    },
                                    {
                                        "type": "null"
                                    }
                                ]
                            }
                        }
                    },
                    "required": [
                        "nullable"
                    ]
                },
                "ResponseGet": {
                    "title": "ResponseGet",
                    "type": "object",
                    "properties": {
                        "nonNullable": {
                            "type": "array",
                            "default": null,
                            "items": {
                                "type": "string",
                                "nullable": false
                            }
                        }
                    },
                    "required": [
                        "nonNullable"
                    ]
                }
            }
        },
        "paths": {
            "/api": {
                "get": {
                    "responses": {
                        "200": {
                            "content": {
                                "application/json": {
                                    "schema": {
                                        "$ref": "#/components/schemas/ResponseGet"
                                    }
                                }
                            },
                            "description": "OK"
                        }
                    }
                }
            }
        }
    }

    In this case we get

     'nonNullable': Array<string>;

    for ResponseGet, as desired

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions