Skip to content

[BUG][typescript-axios] Allof keyword makes nullable fields become non-nullable #21065

Description

@Halvadar
Description

When using openapi-generator 7.12.0 with OpenAPI 3.1.0 specification, fields marked as nullable in the referred schema are not properly generated as nullable in the TypeScript output, if the schema is combined using the allOf keyword. The same specification works correctly when using OpenAPI 3.0.0.

When a field is defined with type: [string, "null"] in schema in OpenAPI 3.1.0, if the schema is combined using allOf keyword, the generated TypeScript interface does not maintain the nullable property in the generated code.

openapi-generator version

7.12.0

OpenAPI declaration file content
openapi: 3.1.0
info:
  version: 1.0.0
  title: Example - OpenAPI 3.1
  description: Example

components:
  schemas:
    TargetSchema:
      properties:
        id:
          type: [string, "null"]
        name:
          type: string
    RefSchemaWithAllOf:
      allOf:
        - $ref: "#/components/schemas/TargetSchema"
Generated API
/**
 * 
 * @export
 * @interface RefSchemaWithAllOf
 */
export interface RefSchemaWithAllOf {
    /**
     * 
     * @type {string}
     * @memberof RefSchemaWithAllOf
     */
    'id'?: string;
    /**
     * 
     * @type {string}
     * @memberof RefSchemaWithAllOf
     */
    'name'?: string;
}
/**
 * 
 * @export
 * @interface TargetSchema
 */
export interface TargetSchema {
    /**
     * 
     * @type {string}
     * @memberof TargetSchema
     */
    'id'?: string | null;
    /**
     * 
     * @type {string}
     * @memberof TargetSchema
     */
    'name'?: string;
}
Generation Details

Using CLI:

openapi-generator-cli generate -g typescript-axios -i swagger.yml
Steps to reproduce
  1. Create the OpenAPI 3.1.0 specification as shown above
  2. Generate TypeScript code using openapi-generator 7.12.0
  3. Observe the generated output

Current output:

export interface RefSchemaWithAllOf {
    'id'?: string;  // Should be string | null
    'name'?: string;
}

Expected output:

export interface RefSchemaWithAllOf {
    'id'?: string | null;
    'name'?: string;
}

Activity

  1. changed the title [-][BUG][typescript-axios] Description[/-] [+][BUG][typescript-axios] OpenAPI 3.1.0 Allof keyword makes nullable fields become non-nullable in generated code[/+] on Apr 9, 2025
  2. changed the title [-][BUG][typescript-axios] OpenAPI 3.1.0 Allof keyword makes nullable fields become non-nullable in generated code[/-] [+][BUG][typescript-axios] Allof keyword makes nullable fields become non-nullable[/+] on Apr 9, 2025
  3. JulianVennen commented on Oct 6, 2026

    @JulianVennen
    Contributor

    This is fixed in v7.26.0. The new output correctly has the null type option:

    export interface RefSchemaWithAllOf {
        'id'?: string | null;
        'name'?: string;
    }
  4. wing328 commented on Oct 7, 2026

    @wing328
    Member

    closed via #25064

    please give it a try with the latest stable version v7.26.0

    happy to reopen if needed

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