OpenAPITools / OpenAPITools/openapi-generator

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

Open
#21,065 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided OpenAPI 3.1.0 declaration and the typescript-axios generator command. Then trace the generator's allOf handling for referenced schemas and compare it with the direct TargetSchema output. Done means the generated RefSchemaWithAllOf interface preserves id as string | null, with regression coverage for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.