OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-axios] parameter with date format has incorrect types

Open
#6,771 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

If a date format is specified for a parameter, the generated code for axios will include the following:

      if (fromDate !== undefined) {
        localVarQueryParameter['fromDate'] =
          (fromDate as any) instanceof Date
            ? (fromDate as any).toISOString().substr(0, 10)
            : fromDate;
      }

However, the type for that argument in the generated method is fromDate?: string, which prevent us from actually passing a Date instance.

Either we remove that code, or change the type definition to be fromDate?: string | Date

openapi-generator version

4.3.1

OpenAPI declaration file content or url
     parameters:
        - in: query
          name: fromDate
          schema:
            type: string
            format: date
Command line used for generation
openapi-generator \
        generate \
        -g typescript-axios \
        -i "../external-api/$name.yaml" \
        -o "generated-src/$name"

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 with the typescript-axios generator and reproduce the provided OpenAPI declaration and generation command. Inspect the generated method signature and query-parameter handling for a date-formatted parameter. Done means the generated TypeScript type and runtime date handling agree, with the generated output matching the intended behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.