Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript-axios] toIsoString() with type string #2745

Closed
duckytutu opened this issue Apr 26, 2019 · 8 comments · Fixed by #3423
Closed

[typescript-axios] toIsoString() with type string #2745

duckytutu opened this issue Apr 26, 2019 · 8 comments · Fixed by #3423

Comments

@duckytutu
Copy link

duckytutu commented Apr 26, 2019

Im using Docker to generate my OpenAPI
https://openapi-generator.tech/docs/installation#docker

This is one of my generate
image

Any idea why startDate for example, input as string but still has the line
localVarQueryParameter['startDate'] = (startDate as any).toISOString();

It cause an error: toIsoString() is not a function

@auto-labeler
Copy link

auto-labeler bot commented Apr 26, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@macjohnny
Copy link
Member

maybe you have a type mapping in your configuration? e.g.

                                    <typeMappings>
                                        <typeMapping>DateTime=string</typeMapping>
                                    </typeMappings>

the generated code should be improved to something like

if (startDate !== undefined && startDate instanceof Date) {...}

would you like to open a PR to fix this?

@tsiq-jeremy
Copy link
Contributor

Hey, I see the same issue occurring with typescript/fetch using

{
   ...
   "type": "string",
   "format": "date",
}

Since the parameter getting passed in is ALWAYS going to be a string, it should never be calling toIsoString() on it. Can we just update it to not worry about calling that function?

localVarQueryParameter['{{baseName}}'] = {{paramName}};

@macjohnny
Copy link
Member

in order not to break existing code, it would be simpler to check for both Date and string:

if (startDate !== undefined && startDate instanceof Date) {...}

@tsiq-jeremy
Copy link
Contributor

@macjohnny works for me! Im going to open up a PR with an update to do this. So I also did a bit more digging into the issue on why this is occurring. If the format is "date", then the parameter type is a string, while if the format is "DateTime", the the parameter it is looking for is a Date.

In `AbstractTypeScriptClientCodegen.java:

typeMapping.put("date", "string");
typeMapping.put("DateTime", "Date");

While in typescript-fetch/api.mustache I found:

                {{#isDate}}
                localVarQueryParameter['{{baseName}}'] = ({{paramName}} as any).toISOString();
                {{/isDate}}

Which is causing the type mismatch.

@macjohnny
Copy link
Member

@tsiq-jeremy could you please open the PR here in openapi generator?

@fuzzzerd
Copy link
Contributor

This seems to be affecting the typescript fetch client too. Looks like there was a pull against the swagger-gen fetch client, but not the openapi generator fetch client.

@macjohnny
Copy link
Member

@fuzzerd would you like to port #3423 to the typrscript fetch client?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants