Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (target: any, propertyKey: string | symbol, index: number): void => {
const type = getDecoratorType([target, propertyKey, index], true);
switch (type) {
default:
throw new Error("MultipartFile is only supported on parameters");
case "parameter":
const store = Store.fromMethod(target, String(propertyKey));
const multiple = Metadata.getParamTypes(target, propertyKey)[index] === Array;
const options = typeof name === "object" ? name : undefined;
const added = store.has("multipartAdded");
name = (typeof name === "object" ? undefined : name)!;
// create endpoint metadata
store.merge("consumes", ["multipart/form-data"]).set("multipartAdded", true);
store
return (...decoratorArgs: DecoratorParameters): TypedPropertyDescriptor | void => {
switch (getDecoratorType(decoratorArgs, true)) {
case "method":
EndpointRegistry.useBefore(decoratorArgs[0], decoratorArgs[1]!, args);
return decoratorArgs[2] as any;
case "class":
StoreMerge("middlewares", {useBefore: args})(...decoratorArgs);
break;
default:
throw new UnsupportedDecoratorType(UseBefore, decoratorArgs);
}
};
}
return (...args: any[]) => {
const type = getDecoratorType(args);
switch (type) {
case "method":
return Operation({title})(...args);
case "parameter":
return BaseParameter({title})(...args);
default:
originalTitleDecorator(title)(...args);
}
};
}
return (...decoratorArgs: DecoratorParameters): void => {
const metadata = getStorableMetadata(decoratorArgs);
if (!metadata) {
throw new UnsupportedDecoratorType(Allow, decoratorArgs);
}
metadata.allowedRequiredValues = allowedRequiredValues;
if (getDecoratorType(decoratorArgs, true) === "property" && allowedRequiredValues.some(e => e == null)) {
allowNullInSchema(decoratorArgs[0], decoratorArgs[1]);
}
};
}
return (...args: DecoratorParameters) => {
const type = getDecoratorType(args, true);
switch (type) {
case "method":
return StoreMerge("responses", {[status]: response})(...args);
case "class":
decorateMethodsOf(args[0], Responses(status, response));
break;
default:
throw new UnsupportedDecoratorType(Responses, args);
}
};
}
return (...decoratorArgs: DecoratorParameters): TypedPropertyDescriptor | void => {
switch (getDecoratorType(decoratorArgs, true)) {
case "method":
return UseBefore(...args)(...decoratorArgs);
case "class":
decorateMethodsOf(decoratorArgs[0], UseBefore(...args));
break;
default:
throw new UnsupportedDecoratorType(UseBeforeEach, decoratorArgs);
}
};
}
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
const type = getDecoratorType([target, propertyKey, descriptor], true);
switch (type) {
default:
throw new Error("MulterOptions is only supported on method");
case "method":
Store.fromMethod(target, propertyKey).merge(MultipartFileMiddleware, {
options
});
return descriptor;
}
};
}
return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor | number): any => {
const bindingType = getDecoratorType([target, propertyKey, descriptor], true);
switch (bindingType) {
case "parameter":
case "parameter.constructor":
if (symbol) {
const paramTypes = Metadata.getParamTypes(target, propertyKey);
paramTypes[descriptor as number] = symbol;
Metadata.setParamTypes(target, propertyKey, paramTypes);
}
break;
case "property":
Store.from(target).merge("injectableProperties", {
[propertyKey]: {
bindingType,
return (...parameters: any[]) => {
switch (getDecoratorType(parameters)) {
case "property":
return applyDecorators(Property(), StoreMerge(MONGOOSE_SCHEMA, options))(...parameters);
case "class":
StoreMerge(MONGOOSE_SCHEMA, createSchema(parameters[0], options as MongooseSchemaOptions))(...parameters);
break;
}
};
}
return (...parameters: any[]): any => {
let schema: JsonSchema;
switch (getDecoratorType(parameters)) {
case "property":
schema = PropertyRegistry.get(parameters[0], parameters[1]).schema;
break;
case "class":
schema = JsonSchemesRegistry.createIfNotExists(parameters[0]);
break;
}
const result: any = fn(schema!, parameters as DecoratorParameters);
if (typeof result === "function") {
result(...parameters);
}
return parameters[2];
};
}