@@ -8,9 +8,10 @@ const content = `
8
8
import { pipe } from 'fp-ts/lib/pipeable';
9
9
import { record } from 'fp-ts';
10
10
import { Either, left, right } from 'fp-ts/lib/Either';
11
-
11
+ import { flow } from 'fp-ts/lib/function';
12
+
12
13
const join = (separator: string) => (parts: string[]): string => parts.join(separator);
13
-
14
+
14
15
export const serializePrimitiveParameter = (style: string, name: string, value: unknown): Either<Error, string> => {
15
16
switch (style) {
16
17
case 'matrix': {
@@ -28,42 +29,44 @@ const content = `
28
29
}
29
30
return left(new Error(\`Unsupported style "\${style}" for parameter "\${name}"\`));
30
31
};
31
-
32
+
32
33
export const serializeArrayParameter = (
33
34
style: string,
34
35
name: string,
35
36
value: unknown[],
36
37
explode: boolean,
37
38
): Either<Error, string> => {
39
+ const encodedValue = value.map(flow(String, encodeURIComponent));
40
+
38
41
switch (style) {
39
42
case 'matrix': {
40
43
return right(
41
- value .length === 0
44
+ encodedValue .length === 0
42
45
? \`;\${name}\`
43
46
: explode
44
- ? \`\${value .map(item => \`;\${name}=\${item}\`).join('')}\`
45
- : \`;\${name}=\${value .join(',')}\`,
47
+ ? \`\${encodedValue .map(item => \`;\${name}=\${item}\`).join('')}\`
48
+ : \`;\${name}=\${encodedValue .join(',')}\`,
46
49
);
47
50
}
48
51
case 'label': {
49
- return right(value .map(item => \`.\${item}\`).join(''));
52
+ return right(encodedValue .map(item => \`.\${item}\`).join(''));
50
53
}
51
54
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(',')}\`);
53
56
}
54
57
case 'simple': {
55
- return right(value .join(','));
58
+ return right(encodedValue .join(','));
56
59
}
57
60
case 'spaceDelimited': {
58
- return right(value .join(' '));
61
+ return right(encodedValue .join(' '));
59
62
}
60
63
case 'pipeDelimited': {
61
- return right(value .join('|'));
64
+ return right(encodedValue .join('|'));
62
65
}
63
66
}
64
67
return left(new Error(\`Unsupported style "\${style}" for parameter "\${name}"\`));
65
68
};
66
-
69
+
67
70
export const serializeObjectParameter = (
68
71
style: string,
69
72
name: string,
0 commit comments