Skip to content
New issue

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

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

Already on GitHub? # to your account

[BUG][Typescript axios] Generated call to accessToken doesn't match type definition #2956

Closed
2 of 6 tasks
bebsworthy opened this issue May 21, 2019 · 3 comments · Fixed by #3555
Closed
2 of 6 tasks

Comments

@bebsworthy
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used? 4.0.1#master
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?

The code generated for accessToken is :

// http bearer authentication required
            if (configuration && configuration.accessToken) {
                const accessToken = typeof configuration.accessToken === 'function'
                    ? configuration.accessToken()
                    : configuration.accessToken;
                localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
            }

(As per https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache)

configuration.accessToken() is called without parameters

Type definition for accessToken is

accessToken?: string | ((name: string, scopes?: string[]) => string);

name is a mandatory parameter
Typescript outputs the following error semantic error TS2554 Expected 1-2 arguments, but got 0.

Type definition for accessToken should probably be:

accessToken?: string | ((name?: string, scopes?: string[]) => string);

or, if the parameters are never used:

accessToken?: string | (() => string);
  • [Optional] Bounty to sponsor the fix (example)
Description
openapi-generator version
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix
@mAAdhaTTah
Copy link

Ran into this same issue. Trying to generate a TS client that works between React Native & Web and having no luck. Axios is the closest but this is blocking. I could PR this, but should the accessToken type change based on if it's BasicBearer or should the call site change to include those values?

@macjohnny
Copy link
Member

@mAAdhaTTah a PR is very welcome

@macjohnny
Copy link
Member

cc @nicokoenig

macjohnny pushed a commit that referenced this issue Aug 5, 2019
* [typescript] change accessToken name parameter to optional

* [typescript] update samples for ts-fetch and ts-rxjs
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants