Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getAuthorizationMetadata(
target: object,
methodName: string,
): AuthorizationMetadata | undefined {
let targetClass: Function;
if (typeof target === 'function') {
targetClass = target;
target = target.prototype;
} else {
targetClass = target.constructor;
}
const metadata = MetadataInspector.getMethodMetadata(
AUTHORIZATION_METHOD_KEY,
target,
methodName,
);
if (metadata) return metadata;
// Check if the class level has `@authorize`
return MetadataInspector.getClassMetadata(
AUTHORIZATION_CLASS_KEY,
targetClass,
);
}
export function getAuthenticateMetadata(
targetClass: Constructor<{}>,
methodName: string,
): AuthenticationMetadata | undefined {
// First check method level
let metadata = MetadataInspector.getMethodMetadata(
AUTHENTICATION_METADATA_METHOD_KEY,
targetClass.prototype,
methodName,
);
if (metadata) return metadata;
// Check if the class level has `@authenticate`
metadata = MetadataInspector.getClassMetadata(
AUTHENTICATION_METADATA_CLASS_KEY,
targetClass,
);
return metadata;
}
// The operation was defined via @operation(verb, path) with no spec
operationSpec = {
responses: {},
};
endpoint.spec = operationSpec;
}
debug(' operation for method %s: %j', op, endpoint);
debug(' processing parameters for method %s', op);
let params = MetadataInspector.getAllParameterMetadata(
OAI2Keys.PARAMETERS_KEY,
constructor.prototype,
op,
);
if (params == null) {
params = MetadataInspector.getMethodMetadata(
OAI2Keys.METHODS_WITH_PARAMETERS_KEY,
constructor.prototype,
op,
);
}
debug(' parameters for method %s: %j', op, params);
if (params != null) {
const bodyParams = params.filter(p => p && p.in === 'body');
if (bodyParams.length > 1) {
throw new Error('More than one body parameters found: ' + bodyParams);
}
params = DecoratorFactory.cloneDeep(params);
/**
* If a controller method uses dependency injection, the parameters
* might be sparsed. For example,
* ```ts
export function getAuthorizeMetadata(
controllerClass: Constructor<{}>,
methodName: string,
): AuthorizationMetadata | undefined {
return MetadataInspector.getMethodMetadata(
AUTHORIZATION_METADATA_ACCESSOR,
controllerClass.prototype,
methodName,
);
}
export function getLogMetadata(
controllerClass: Constructor<{}>,
methodName: string,
): LevelMetadata {
return (
MetadataInspector.getMethodMetadata(
EXAMPLE_LOG_METADATA_KEY,
controllerClass.prototype,
methodName,
) ?? {level: LOG_LEVEL.OFF}
);
}