Skip to content

[BUG][TYPESCRIPT] Non-nullable type is generated as nullable #23340

Closed

Description

@FrenchGithubUser

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

This interface is generated:

export interface TitleGroupHierarchyLite {
    'affiliated_artists': Array<AffiliatedArtistLite>;
    'category'?: TitleGroupCategory | null;
    'content_type': ContentType | null;
    'covers': Array<string>;
    'edition_groups': Array<EditionGroupHierarchyLite>;
    'id': number;
    'name': string;
    'original_release_date': string | null;
    'original_release_date_only_year_known': boolean;
    'platform'?: Platform | null;
    'series'?: SeriesLite | null;
    'tags': Array<string>;
}

but content_type should not be nullable (according to the openapi spec)

openapi-generator version

I tried with latest and it gives the same bug

OpenAPI declaration file content or url

https://pastebin.com/K1QVzVDK

Generation Details
npx openapi-generator-cli generate -g typescript-axios -i http://127.0.0.1:8080/swagger-json/openapi.json   -o ./src/services/api-schema -t .openapi-generator/templates --config .openapi-generator/openapi-generator.config.json --global-property=apiDocs=false,modelDocs=false,skipFormModel=false

mustache template: https://github.com/Arcadia-Solutions/arcadia/blob/main/frontend/.openapi-generator/templates/api.mustache

Steps to reproduce

generate the api.ts file with the provided command, template and openapi json schema.

Related issues/PRs

None found

Suggest a fix

No idea :/

Activity

  1. KannaKim commented on Jul 18, 2026

    @KannaKim
    Contributor

    Could you provide us with a minimal spec file that reproduces the issue? The declaration file you shared is quite lengthy, so a smaller example would make it easier to review.

  2. FrenchGithubUser commented on Jul 19, 2026

    @FrenchGithubUser
    Author

    this reproduces the bug 7.23.0:

    {
      "openapi": "3.1.0",
      "info": { "title": "repro-23340", "version": "1.0.0" },
      "paths": {
        "/home": {
          "get": {
            "operationId": "getHome",
            "responses": {
              "200": {
                "description": "ok",
                "content": {
                  "application/json": {
                    "schema": {
                      "type": "object",
                      "required": ["data"],
                      "properties": { "data": { "$ref": "#/components/schemas/HomePage" } }
                    }
                  }
                }
              }
            }
          }
        },
        "/search": {
          "get": {
            "operationId": "search",
            "parameters": [
              {
                "name": "content_type",
                "in": "query",
                "required": false,
                "schema": { "oneOf": [ { "type": "null" }, { "$ref": "#/components/schemas/ContentType" } ] }
              }
            ],
            "responses": { "200": { "description": "ok" } }
          }
        }
      },
      "components": {
        "schemas": {
          "ContentType": { "type": "string", "enum": ["movie"] },
          "TitleGroupLite": {
            "type": "object",
            "required": ["content_type"],
            "properties": { "content_type": { "$ref": "#/components/schemas/ContentType" } }
          },
          "HomePage": {
            "type": "object",
            "required": ["latest_uploads"],
            "properties": {
              "latest_uploads": { "type": "array", "items": { "$ref": "#/components/schemas/TitleGroupLite" } }
            }
          },
          "TitleGroupHierarchyLite": {
            "type": "object",
            "required": ["id", "content_type"],
            "properties": {
              "id": { "type": "integer", "format": "int32" },
              "content_type": { "$ref": "#/components/schemas/ContentType" }
            }
          }
        }
      }
    }

    Generate with:

    npx --yes @openapitools/openapi-generator-cli generate \
      -g typescript-axios -i minimal-repro.json -o out \
      --global-property=apiDocs=false,modelDocs=false
    

    Actual vs expected

    Two schemas have an identical content_type property (required, plain $ref to the ContentType enum), but only one comes out nullable:

    export interface TitleGroupHierarchyLite {
        'id': number;
        'content_type': ContentType | null;   // BUG — spec says required, non-nullable
    }
    
    export interface TitleGroupLite {
        'content_type': ContentType;           // correct
    }

    Both should be ContentType (no | null). No custom templates are involved — the default templates reproduce it.

    Trigger conditions

    The bug only appears when all three of these are present at once. Removing any single one makes it disappear:

    1. A query parameter named content_type whose schema is a nullable enum ref — oneOf: [ {type: null}, {$ref: ContentType} ]. Dropping it, or making it a plain non-nullable $ref, fixes the output.
    2. An operation whose response is an inline object the generator extracts into a synthetic model (GetHome200Response here, from { data: $ref HomePage }). A direct $ref response (no inline wrapper) fixes the output.
    3. A schema with a property named content_type (plain $ref to the enum) and at least one other property (id). A schema whose only property is content_type is generated correctly.

    Analysis (from Claude)

    It looks like the nullability of the enum used in the content_type parameter leaks onto unrelated schema properties that share the name content_type and reference the same enum — and it only surfaces once inline-model extraction runs for another operation.

    This was reduced from my full spec: the nullable parameter comes from GET /api/search/title-groups/lite (a content_type: Option<ContentType> query param), the inline response wrapper from GET /api/home, and the poisoned property is TitleGroupHierarchyLite.content_type.

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