OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-axios] Generation failed when using enum with date or date-time

Open
#8,221 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

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

The generation failed with errors like Exception: java.util.Date cannot be cast to java.lang.String, when the spec file contains enum with date or date-time.

openapi-generator version

5.0.0-beta2

OpenAPI declaration file content or url
---
openapi: 3.0.0
info:
  title: Test API
  description: Test API
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.0
tags:
- name: someTag
  description: Some test tag
paths:
  "/entities":
    get:
      tags:
      - someTag
      summary: Get entities
      description: Get all entities
      operationId: getAllEntities
      parameters:
      - name: enumParameter
        in: query
        description: A parameter of type enum with date
        required: false
        schema:
          type: string
          format: date
          enum:
          - '1999-12-12'
          - '2000-11-11'
      responses:
        '200':
          description: entities
          content:
            application/json:
              schema:
                type: number

Generation Details
npx openapi-generator-cli generate --input-spec /input-dir/open-api.json --generator-name typescript-axios --output /output-dir/openapi --template-dir /template-dir/templates --api-package api --model-package model --additional-properties withSeparateModelsAndApi=true --skip-validate-spec
Steps to reproduce
  1. Generate the client by using the command and the spec file above.
  2. Generation will fail with the error message shown above.
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/2404

Suggest a fix
  1. Check whether this feature is supported by the java version, since the related issue above is still open, I assume no.
  2. If yes, the type script should also do the same.
  3. If no, the open api generator can decide, whether you would like to support this or not. But in the the mean time, maybe instead of throwing an error that breaks the whole generation, you can show some warning messages.

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

Run the supplied OpenAPI YAML through the typescript-axios generator using the documented npx command, starting with the enum handling for date and date-time values. Compare the failure with the expected generated client behavior and review related issue #2404; done means generation completes without the reported class-cast exception.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.