@@ -8,9 +8,10 @@ const content = `
88 import { pipe } from 'fp-ts/lib/pipeable';
99 import { record } from 'fp-ts';
1010 import { Either, left, right } from 'fp-ts/lib/Either';
11-
11+ import { flow } from 'fp-ts/lib/function';
12+
1213 const join = (separator: string) => (parts: string[]): string => parts.join(separator);
13-
14+
1415 export const serializePrimitiveParameter = (style: string, name: string, value: unknown): Either<Error, string> => {
1516 switch (style) {
1617 case 'matrix': {
@@ -28,42 +29,44 @@ const content = `
2829 }
2930 return left(new Error(\`Unsupported style "\${style}" for parameter "\${name}"\`));
3031 };
31-
32+
3233 export const serializeArrayParameter = (
3334 style: string,
3435 name: string,
3536 value: unknown[],
3637 explode: boolean,
3738 ): Either<Error, string> => {
39+ const encodedValue = value.map(flow(String, encodeURIComponent));
40+
3841 switch (style) {
3942 case 'matrix': {
4043 return right(
41- value .length === 0
44+ encodedValue .length === 0
4245 ? \`;\${name}\`
4346 : explode
44- ? \`\${value .map(item => \`;\${name}=\${item}\`).join('')}\`
45- : \`;\${name}=\${value .join(',')}\`,
47+ ? \`\${encodedValue .map(item => \`;\${name}=\${item}\`).join('')}\`
48+ : \`;\${name}=\${encodedValue .join(',')}\`,
4649 );
4750 }
4851 case 'label': {
49- return right(value .map(item => \`.\${item}\`).join(''));
52+ return right(encodedValue .map(item => \`.\${item}\`).join(''));
5053 }
5154 case 'form': {
52- return right(explode ? \`\${value .map(item => \`\${name}=\${item}\`).join('&')}\` : \`\${name}=\${value .join(',')}\`);
55+ return right(explode ? \`\${encodedValue .map(item => \`\${name}=\${item}\`).join('&')}\` : \`\${name}=\${encodedValue .join(',')}\`);
5356 }
5457 case 'simple': {
55- return right(value .join(','));
58+ return right(encodedValue .join(','));
5659 }
5760 case 'spaceDelimited': {
58- return right(value .join(' '));
61+ return right(encodedValue .join(' '));
5962 }
6063 case 'pipeDelimited': {
61- return right(value .join('|'));
64+ return right(encodedValue .join('|'));
6265 }
6366 }
6467 return left(new Error(\`Unsupported style "\${style}" for parameter "\${name}"\`));
6568 };
66-
69+
6770 export const serializeObjectParameter = (
6871 style: string,
6972 name: string,
0 commit comments