OpenAPITools / OpenAPITools/openapi-generator

Time stripped away from date-time query parameter

Open
#17,270 1 comment 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

A time part is stripped away from date-time query parameters when using typescript-angular generator version 7.1.0 and type mapping "DateTime": "Date".

The problem points to https://github.com/OpenAPITools/openapi-generator/blob/f834519aebf8a565b1be768e67b1bd0aa8242b25/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache#L135C19-L135C135 where .substring(..) is added if isDateTime property is falsy.

httpParams = httpParams.append(key, (value as Date).toISOString(){{^isDateTime}}.substring(0, 10){{/isDateTime}});

Apparently, isDateTime property does not get set on whether the format is date or date-time as my schema looks as following:

"/api/notification/unseen": {
      "get": {
        "tags": ["notification-controller"],
        "operationId": "getAllUnseen",
        "parameters": [{ "name": "since", "in": "query", "required": false, "schema": { "type": "string", "format": "date-time" } }],
        "responses": {
          "404": { "description": "Not Found", "content": { "*/*": { "schema": { "$ref": "#/components/schemas/CustomErrorResponse" } } } },
          "200": {
            "description": "OK",
            "content": {
              "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/NotificationDTO" } } }
            }
          }
        }
      }
    }

but .substring(0, 10) is appended to generated services.

A temporary solution is to add "isDateTime": true to additionalProperties and always opt for not stripping the time part.

{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "generator-cli": {
    "version": "7.1.0",
    "generators": {
      "api": {
        "...
        "additionalProperties": {
          "ngVersion": "15.2.9",
          ...,
          "isDateTime": true
        },
        "typeMappings": {
          "DateTime": "Date"
        }
      }
    }
  }
}

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 modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache around the query-parameter serialization shown in the issue, then trace how isDateTime is populated for the date-time schema and the DateTime type mapping. Generate the typescript-angular client from the provided schema and confirm that the since parameter preserves its time component instead of applying substring(0, 10).

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, 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.