OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-fetch] `oneOf` containing `enum` tries to import nonexistent instanceOf function

Open
#14,611 3 comments 4 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

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 a schema with a oneOf component containing enums leads to leads to broken code where the type tries to import instanceOf functions that aren't generated for enums.

openapi-generator version

6.2.1 and 6.3.0.

OpenAPI declaration file content or url
JSON
{
  "openapi": "3.0.0",
  "info": { "title": "Foo", "version": "1.0.0" },
  "servers": [],
  "paths": {},
  "components": {
    "schemas": {
      "Timezone": {
        "oneOf": [
          {
            "description": "(UTC-12:00) International Date Line West",
            "type": "string",
            "enum": [
              "DatelineStandardTime"
            ]
          },
          {
            "description": "(UTC-11:00) Coordinated Universal Time-11",
            "type": "string",
            "enum": [
              "UtcMinus11"
            ]
          },
          {
            "description": "(UTC-10:00) Aleutian Islands",
            "type": "string",
            "enum": [
              "AleutianStandardTime"
            ]
          }
        ]
      }
    }
  }
}
Generation Details
    yarn openapi-generator-cli generate \
        --input-spec {{OPENAPI_SPEC}} \
        --generator-name typescript-fetch \
        --output ./src/api \
        --additional-properties \
    "supportsES6=true,\
    withInterfaces=true,\
    enumNameSuffix=,\
    enumPropertyNaming=UPPERCASE,\
    modelPropertyNaming=camelCase,\
    typescriptThreePlus=true,\
    stringEnums=true\
    "
Steps to reproduce
  • Write the schema to a file.
  • Run the code typescript-fetch generator
  • Try to compile the generated typescript files
  • It fails because the type tries to import e.g. instanceOfTimezoneOneOf which doesn't exist.

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 running the provided OpenAPI schema through the typescript-fetch generator with the listed options, then compile the generated TypeScript files. Trace the generated Timezone oneOf model and its enum variants to find where the nonexistent instanceOfTimezoneOneOf import is introduced. Done means the same schema generates TypeScript that compiles without that import.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.