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
.merge("responses", {
"400": {
description: ` [fieldName]
Example: File too long file1`
}
})
.set("multipartAdded", true);
before(() => {
ReturnsArray(400, {
description: "Bad Request"
})(Test, "test1", descriptorOf(Test, "test1"));
this.store = Store.fromMethod(Test, "test1");
});
it("should set the responses", () => {
before(() => {
Returns(Test, {
description: "Success"
})(Test, "test2", descriptorOf(Test, "test2"));
this.store = Store.fromMethod(Test, "test2");
});
it("should set the responses", () => {
before(() => {
Responses(400, {
description: "Bad Request"
})(Test, "test", descriptorOf(Test, "test"));
this.store = Store.fromMethod(Test, "test");
});
it("should set the responses", () => {
before(() => {
Returns({
description: "Success",
type: Test
})(Test, "test4", descriptorOf(Test, "test4"));
this.store = Store.fromMethod(Test, "test4");
});
it("should set the responses", () => {
before(() => {
ReturnsArray(Test)(Test, "test3", descriptorOf(Test, "test3"));
this.store = Store.fromMethod(Test, "test3");
});
it("should set the responses", () => {
before(() => {
this.descriptor = {};
this.options = {options: "options"};
Authenticated(this.options)(Test, "test", descriptorOf(Test, "test"));
this.store = Store.fromMethod(Test, "test");
});
before(() => {
MulterOptions({dest: "/"})(Test.prototype, "test", descriptorOf(Test.prototype, "test"));
this.store = Store.fromMethod(Test.prototype, "test");
});
super(target);
this.name = `${nameOf(target)}${methodClassName.charAt(0).toUpperCase() + methodClassName.slice(1)}`;
this.injectedParams = ParamRegistry.getParams(target, methodClassName).filter(param => {
if (param.paramType === ParamTypes.BODY) {
this.hasBody = true;
}
if (param.paramType === ParamTypes.FORM_DATA) {
this.hasFormData = true;
}
return !param.store.get("hidden");
});
const fromMethod = Store.fromMethod(target, methodClassName);
const operation = fromMethod.get("operation");
if (operation && operation.consumes && operation.consumes.indexOf("application/x-www-form-urlencoded") > -1) {
this.hasFormData = true;
}
}
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;
}
};
}