question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
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"

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
rainmanhhhcommented, Jul 28, 2020

sameproblem for typescript-rxjs. walkaround: change fromDate.toISOString() to new Date(fromDate).toISOString()

1reaction
rvowlescommented, Jul 28, 2020

@rainmanhhh without a proper deserializer this thing won’t ever work. I’m in the last throes of testing my changes before submitting them back. The model generate and de/serializer will work now without the api libraries, so it will be able to be used with whatever transport you use.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript requires different return type depending on scenario
It will throw TS lint error saying Type 'AxiosResponse' is missing the following properties from Type 'AxiosResponse<any>' is not assignable ...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
axios - npm
Start using axios in your project by running `npm i axios`. ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >
Node.js Date.format() API - GeeksforGeeks
Parameters : This method takes the following arguments as parameters: dateObj: It is the object of the date. formatString: It is the new...
Read more >
Documentation for the typescript-axios Generator
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default. true. ensureUniqueParams, Whether to ensure parameter ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found