OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-axios] oneOf leads to NULL_SCHEMA_ERR while generating interface

Open
#19,552 0 comments 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 (example)?
  • 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

Using oneOf in the schema and generating code using typescript-axios generator leads to it injecting NULL_SCHEMA_ERR in the interface declaration.

Moreover, it sends a warn log message:

[[rootLedger] assets/openapi/rootledger.yaml] [main] WARN  o.o.codegen.DefaultCodegen - Null schema found. Default type to `NULL_SCHEMA_ERR`
openapi-generator version

7.8.0 stable

OpenAPI declaration file content or url
LedgerFilterBody:
      type: object
      oneOf:
        - required:
            - ledgerId
          properties:
            ledgerId:
              type: string
              description: Filter by ledger ID.
              example: "10120323"
        - required:
            - ledgerName
          properties:
            ledgerName:
              type: string
              description: Filter by ledger name.
              example: "myledger"
Generation Details
{
  "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.8.0",
    "generators": {
      "rootLedger": {
        "generatorName": "typescript-axios",
        "inputSpec": "assets/openapi/rootledger.yaml",
        "output": "src/gen/rootledger",
        "additionalProperties": {
          "supportsES6": "true",
          "withInterfaces": true
        }
      }
    }
  }
}

Generates a problematic interface:

/**
 * 
 * @export
 * @interface LedgerFilterBody
 */
export interface LedgerFilterBody {
    [key: string]: NULL_SCHEMA_ERR; // -- why????

}

This leads to a build error because NULL_SCHEMA_ERR isn't defined.

Steps to reproduce
  1. Create a schema file containing LedgerFilterBody (can probably copy-paste)
  2. Try to generate code using above config.
Related issues/PRs

Found a few, but none of them lead to NULL_SCHEMA_ERR

Hint

If I restructure my schema like below, it starts generating code fine:

LedgerFilterBody:
  type: object
  properties:
    ledgerId:
      type: string
      nullable: true
      description: Filter by ledger ID.
    ledgerName:
      type: string
      nullable: true
      description: Filter by ledger name.
  oneOf:
    - required: [ledgerId]
    - required: [ledgerName]
/**
 * 
 * @export
 * @interface LedgerFilterBody
 */
export interface LedgerFilterBody {
    /**
     * Filter by ledger ID.
     * @type {string}
     * @memberof LedgerFilterBody
     */
    'ledgerId'?: string | null;
    /**
     * Filter by ledger name.
     * @type {string}
     * @memberof LedgerFilterBody
     */
    'ledgerName'?: string | null;
}

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

Use the supplied LedgerFilterBody schema and typescript-axios configuration as the reproduction starting point; inspect the generator path that handles oneOf schemas and emits interfaces. Done means generation no longer emits NULL_SCHEMA_ERR for this valid schema and the resulting TypeScript interface builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, 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.