[BUG] [typescript-axios] parameter with date format has incorrect types
See original GitHub issueDescription
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:
- Created 3 years ago
- Reactions:2
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
sameproblem for typescript-rxjs. walkaround: change
fromDate.toISOString()
tonew Date(fromDate).toISOString()
@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.