Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 of 6 tasks
SyedAhkam opened this issue Sep 9, 2024 · 0 comments
Open
5 of 6 tasks

Comments

@SyedAhkam
Copy link

SyedAhkam commented Sep 9, 2024

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant