OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-axios] incorrect Date mapping for format: date

Open
#17,318 3 comments 2 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

Generating a typescript-axis client doesn't map a Java LocalDate to a Typescript Date

openapi-generator version

7.0.1

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "",
    "version": ""
  },
  "paths": {
    "/x/": {
      "post": {
        "responses": {
          "200": {
            "description": "Service is alive and responsive"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "departureDate": {
        "type": "string",
        "format": "date"
      }
    }
  }
}
Generation Details

We generate a client using cli. It generates the following TypeScript definition for any Java LocalDate:

     /**
     * 
     * @type {string}
     */
    'departureDate': string;

However we expect it to be:

    /**
     * 
     * @type {Date}
     */
    'departureDate'?: Date;

NOTE: Java LocalDateTime works as expected; generating the TypeScript Date type.

Our script:

openapi-generator generate \                          
-i http://localhost:8089/v3/api-docs \ 
-o client \ 
-g typescript-axios \ 
--server-variables=path=myapi \ 
--type-mappings=Date=Date \ 
--additional-properties=supportsES6=true,npmVersion=1.0.1,typescriptThreePlus=true,npmName=dcs-service-client
Steps to reproduce

Generate a OpenApi specification which includes uses a Java LocalDate. Generate a typescript-axios client based on that specification.

Related issues/PRs

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

Suggest a fix

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 reproducing the issue with the provided OpenAPI schema and the typescript-axios generator command. Inspect the typescript-axios generator entry point and compare handling of format: date with LocalDateTime. Done means the generated departureDate definition uses Date rather than string, with a regression check for this schema.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.