Skip to content

[Typescript-angular] Bug generating APIs with Date-Time parameters #5223

@mcpummec

Description

@mcpummec
Description

When generating APIs with Date-Time parameters, the generated service returns the error "key may not be null if value is Date".

openapi-generator version

This was introduced by 4.2.3. I'm having no issues running 4.0.1.

OpenAPI declaration file content or url

"parameters": [{
"name": "date",
"in": "query",
"type": "string",
"format": "date-time"
}
]

Command line used for generation

openapi-generator generate -g typescript-angular -i [swaggerUri] -o [outputPath] -c scripts/open-api-generator.conf.json

Steps to reproduce
  • Generate API
  • call service with signature
    "public getData(date?: Date, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable"
  • exception is thrown: "Error: key may not be null if value is Date"
Related issues/PRs

Possibly related to #4404

Suggest a fix/enhancement

The problem is addToHttpParams and addToHttpParamsRecursive.
For values with 'typeof values ==="object"', addToHttpParamsRecursive is called without the 'key' property. But if 'value instanceof Date', a key is required; otherwise the error is raised.

sample.txt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions