Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.set("multipartAdded", true);
if (!added) {
// middleware is added
UseBefore(MultipartFileMiddleware)(target, propertyKey, descriptorOf(target, propertyKey));
}
if (name === undefined) {
store.merge(MultipartFileMiddleware, {
options,
any: true
});
UseFilter(multiple ? MultipartFilesFilter : MultipartFileFilter, {
useConverter: false,
paramType: ParamTypes.FORM_DATA
})(target, propertyKey, index);
} else {
const expression = multiple ? (name as string) : name + ".0";
store.merge(MultipartFileMiddleware, {
fields: [
{
name,
maxCount
}
],
options
});
UseFilter(MultipartFilesFilter, {
expression,
// middleware is added
UseBefore(MultipartFileMiddleware)(target, propertyKey, descriptorOf(target, propertyKey));
}
if (name === undefined) {
store.merge(MultipartFileMiddleware, {
options,
any: true
});
ParamRegistry.useFilter(multiple ? MultipartFilesFilter : MultipartFileFilter, {
propertyKey,
parameterIndex,
target,
useConverter: false,
paramType: ParamTypes.FORM_DATA
});
} else {
const expression = multiple ? (name as string) : name + ".0";
store.merge(MultipartFileMiddleware, {
fields: [
{
name,
maxCount
}
],
options
});
ParamRegistry.useFilter(MultipartFilesFilter, {
expression,
it("should set params metadata", () => {
this.useFilterStub.should.have.been.calledWithExactly(MultipartFilesFilter, {
expression: "file1.0",
propertyKey: "test",
parameterIndex: 0,
target: Test.prototype,
useConverter: false,
paramType: ParamTypes.FORM_DATA
});
});
});
it("should set params metadata", () => {
this.useFilterStub.should.have.been.calledWithExactly(MultipartFileFilter, {
propertyKey: "test",
parameterIndex: 0,
target: Test.prototype,
useConverter: false,
paramType: ParamTypes.FORM_DATA
});
});
});
before(() => {
const storeGet = (key: string) => {
if (key === "hidden") {
return false;
}
return {test: "test"};
};
this.params = [
{
paramType: ParamTypes.FORM_DATA,
expression: "expression1",
required: true,
store: {
get: storeGet
}
},
{
paramType: ParamTypes.BODY,
expression: "expression1",
required: true,
store: {
get: storeGet
}
}
];
return {test: "test"};
};
this.params = [
{
paramType: ParamTypes.BODY,
expression: "expression1",
required: true,
type: String,
store: {
get: storeGet
}
},
{
paramType: ParamTypes.FORM_DATA,
expression: "expression2.0",
required: false,
store: {
get: storeGet
}
}
];
this.getParamsStub = Sinon.stub(ParamRegistry, "getParams").returns(this.params);
this.builder = new OpenApiParamsBuilder(Ctrl, "test");
this.result = this.builder.getInFormData();
});
after(() => {
.map(param => {
const name = ((param.expression as string) || "").replace(".0", "");
const type = param.paramType === ParamTypes.FORM_DATA ? "file" : swaggerType(param.paramType);
return Object.assign({}, param.store.get("baseParameter"), {
in: "formData",
name,
required: param.required,
type
});
});
}
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");
});