OpenAPITools / OpenAPITools/openapi-generator

[BUG] Nullable refs are marked not nullable when unaliasing

Open
#21,612 1 comment 1 reaction 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

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

Given the following OAS:

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

components:
  schemas:
    WrapperType:
      type: integer
      format: int32
    ObjectThing:
      type: object
      required:
      - id
      - field2
      properties:
        id:
          type: string
        field2:
          oneOf:
          - $ref: '#/components/schemas/WrapperType'
          - type: 'null'

The output is

/**
 * 
 * @export
 * @interface ObjectThing
 */
export interface ObjectThing {
    /**
     * 
     * @type {string}
     * @memberof ObjectThing
     */
    'id': string;
    /**
     * 
     * @type {number}
     * @memberof ObjectThing
     */
    'field2': number;
}

Note that field2 should be of type number | null.

openapi-generator version

7.14.0

OpenAPI declaration file content or url
Generation Details
openapi-generator generate --input-spec foo.yaml -g typescript-axios
Steps to reproduce

This occurs in the Python generator as well

Related issues/PRs
Suggest a fix

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 supplied OpenAPI 3.1 schema using the typescript-axios generator, then compare the Python generator output as noted in the report. Trace how the oneOf nullable reference is unaliased; done means field2 is generated as number | null rather than number in the affected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.