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

Export getOpenAPIMetadata and setOpenAPIMetadata #61

Merged
merged 1 commit into from
Nov 28, 2020

Conversation

bagbyte
Copy link
Contributor

@bagbyte bagbyte commented Nov 16, 2020

Those 2 methods can be useful to create custom decorators and enrich existing spec

Those methods can be useful to create custom decorators and enrich existing spec
@epiphone
Copy link
Owner

Thanks! Was there a specific use case you had in mind that requires these methods? I'm curious if it could be achieved using one of the already exposed extension points. Did you try passing a function to OpenAPI as in the 2nd example here #21 (comment) ?

@bagbyte
Copy link
Contributor Author

bagbyte commented Nov 17, 2020

@epiphone

I would like to create my own decorator, i.e. @Authorization defined as:

function Authorization(roleOrRoles?: any | any[]): Function {
  ...
  return function(clsOrObject: Function | Object, method?: string) {
    // Adding validation
    getMetadataArgsStorage().responseHandlers.push({
      type: 'authorized',
      target: method ? clsOrObject.constructor : (clsOrObject as Function),
      method: method,
      value: roles,
    });

    // Adding documentation
    const spec = { security: [{ AccessToken: roles.map(r => `ROLE_${AuthUserRole.role(r)}`) }] };

    if (method) {
      setOpenAPIMetadata([spec, ...getOpenAPIMetadata(clsOrObject, method)], clsOrObject, method);
    } else {
      setOpenAPIMetadata([spec, ...getOpenAPIMetadata(clsOrObject)], clsOrObject);
    }
  }
}

@epiphone epiphone merged commit a84535e into epiphone:master Nov 28, 2020
@epiphone
Copy link
Owner

Alright, published in v2.2.0. Let's leave this undocumented for now.

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 this pull request may close these issues.

None yet

2 participants