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

OAuthFlow type requiring all security flows to be defined #843

Closed
2 tasks done
fantapop opened this issue Nov 14, 2020 · 1 comment · Fixed by #844
Closed
2 tasks done

OAuthFlow type requiring all security flows to be defined #843

fantapop opened this issue Nov 14, 2020 · 1 comment · Fixed by #844

Comments

@fantapop
Copy link
Contributor

Sorting

  • I'm submitting a ...

    • bug report
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

When using tsoa.json to configure a security definition we're using something like this:

        "mysecurity": {
                "type": "oauth2",
                "flows": {
                    "authorizationCode": {
                        "authorizationUrl": "SET IN EXPRESS MIDDLEWARE",
                        "tokenUrl": "SET IN EXPRESS MIDDLEWARE"
                    }
                }

I'm trying to move this config into a ts file to take advantage of the configuration types as shown in the example here: https://tsoa-community.github.io/docs/generating.html#programmatic

By I'm getting a type error because i haven't specified all the flows. This type is requiring them all:

    export type OAuthFlow = {
        [flowName in OAuth2FlowTypes]: OAuth2SecurityFlow3;
    };
    export type OAuth2FlowTypes = 'authorizationCode' | 'implicit' | 'password' | 'clientCredentials';

Is this purposeful? Making the key optional fixes my issue.

    export type OAuthFlow = {
        [flowName in OAuth2FlowTypes]?: OAuth2SecurityFlow3;
    };
    export type OAuth2FlowTypes = 'authorizationCode' | 'implicit' | 'password' | 'clientCredentials';

Context (Environment)

Version of the library: 3.4.0
Version of NodeJS: 12

  • Confirm you were using yarn not npm: [x]

Breaking change?

no

@WoH
Copy link
Collaborator

WoH commented Nov 14, 2020

One should be enough :D
OpenAPI 3 allows all props to be optional, not sure if there's a case where we don't want any of them, but following the spec and using

export type OAuthFlow = {
  [flowName in OAuth2FlowTypes]?: OAuth2SecurityFlow3;
};

LGTM

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

Successfully merging a pull request may close this issue.

2 participants