Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/requests/process-method.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions src/requests/process-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* in the schema
*/
import {groupBy, map, upperFirst} from 'lodash';
import {flatMap} from 'tslint/lib/utils';

import {getAccessor, getObjectPropSetter} from '../common';
import * as conf from '../conf';
Expand Down Expand Up @@ -122,7 +123,8 @@ function getParamSeparation(paramGroups: Partial<Record<ParamLocation, Parameter
return map(paramGroups, (group, groupName: ParamLocation) => {
let baseDef: string;
let def: string;
const list = map(group, p => {
const fileGroups: Parameter[] = [];
const list = flatMap(group, p => {
// header params values need to be strings
let suffix: string;
if (groupName === 'header' && p.type !== 'string') suffix = '.toString()';
Expand All @@ -136,7 +138,11 @@ function getParamSeparation(paramGroups: Partial<Record<ParamLocation, Parameter
if (separator) suffix = `.join('${separator}')`;
} else suffix = '';

return getObjectPropSetter(p.name, 'params', suffix);
if ( groupName === 'formData' && p.type === 'file') {
fileGroups.push(p);
return [];
}
return [getObjectPropSetter(p.name, 'params', suffix)];
});

if (groupName === 'query') {
Expand Down Expand Up @@ -171,8 +177,18 @@ function getParamSeparation(paramGroups: Partial<Record<ParamLocation, Parameter
if (groupName === 'header') {
def = `new HttpHeaders(${def})`;
}
def += ';';

if (groupName === 'formData' && fileGroups.length > 0) {
let output = `const ${groupName}Params = `;
output += list.length > 0 ? `Object.assign( new FormData(), ${def});\n` : 'new FormData();\n';
const fileFormData = fileGroups.map(f => // Change this to map(fileGroups, ...)?
`${groupName}Params.set('${f.name}', ${getAccessor(f.name, 'params')});`);
output += fileFormData.join('\n');
output += '\n';
return output;
}

def += ';';
return `const ${groupName}Params = ${def}`;
});
}
Expand Down