UNPKG

@tsed/schema

Version:
27 lines (26 loc) 1.04 kB
import { decorateMethodsOf, DecoratorTypes, UnsupportedDecoratorType } from "@tsed/core"; import { JsonEntityFn } from "../common/jsonEntityFn.js"; export function Security(nameOrSecurity, ...scopes) { return JsonEntityFn((store, args) => { switch (store.decoratorType) { case DecoratorTypes.METHOD: if (Array.isArray(nameOrSecurity)) { store.operation.security(nameOrSecurity); } else { store.operation.addSecurityScopes(nameOrSecurity, scopes); } break; case DecoratorTypes.CLASS: if (Array.isArray(nameOrSecurity)) { decorateMethodsOf(args[0], Security(nameOrSecurity)); } else { decorateMethodsOf(args[0], Security(nameOrSecurity, ...scopes)); } break; default: throw new UnsupportedDecoratorType(Security, args); } }); }