Skip to content

Commit 3c9e6a6

Browse files
fix: clj-http handling of literal null JSON bodies (Kong#283)
Co-authored-by: Sergey Zakharchenko <[email protected]>
1 parent da711e9 commit 3c9e6a6

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/targets/clojure/clj_http/client.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,32 @@ class File {
3030
toString = () => `(clojure.java.io/file "${this.path}")`;
3131
}
3232

33-
const jsType = (x?: any) => (typeof x !== 'undefined' ? x.constructor.name.toLowerCase() : null);
33+
const jsType = (input?: any) => {
34+
if (input === undefined) {
35+
return null;
36+
}
37+
38+
if (input === null) {
39+
return 'null';
40+
}
3441

35-
const objEmpty = (x?: any) => (jsType(x) === 'object' ? Object.keys(x).length === 0 : false);
42+
return input.constructor.name.toLowerCase();
43+
};
44+
45+
const objEmpty = (input?: any) => {
46+
if (jsType(input) === 'object') {
47+
return Object.keys(input).length === 0;
48+
}
49+
return false;
50+
};
3651

37-
const filterEmpty = (m: Record<string, any>) => {
38-
Object.keys(m)
39-
.filter(x => objEmpty(m[x]))
52+
const filterEmpty = (input: Record<string, any>) => {
53+
Object.keys(input)
54+
.filter(x => objEmpty(input[x]))
4055
.forEach(x => {
41-
delete m[x];
56+
delete input[x];
4257
});
43-
return m;
58+
return input;
4459
};
4560

4661
const padBlock = (padSize: number, input: string) => {
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
<MISSING>
1+
(require '[clj-http.client :as client])
2+
3+
(client/post "http://mockbin.com/har" {:content-type :json
4+
:form-params {:foo "bar"}})
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
<MISSING>
1+
(require '[clj-http.client :as client])
2+
3+
(client/post "http://mockbin.com/har" {:content-type :json
4+
:form-params {:foo nil}})

src/targets/targets.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ availableTargets()
6161
);
6262
try {
6363
const expected = readFileSync(expectedPath).toString();
64-
if (expected === '<MISSING>') {
65-
console.log(`known missing test for ${targetId}:${clientId} "${fixture}"`);
66-
return;
67-
}
68-
6964
const { convert } = new HTTPSnippet(request);
7065
const result = convert(targetId, clientId); //?
7166

0 commit comments

Comments
 (0)