X Tutup
Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/targets/objc/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ module.exports = {
keyValuePairs.push(util.format('@"%s": %s', k, this.literalRepresentation(value[k])))
}
return '@{ ' + keyValuePairs.join(join) + ' }'
case '[object Boolean]':
return value ? '@YES' : '@NO'
default:
return '@"' + value.replace(/"/g, '\\"') + '"'
return '@"' + value.toString().replace(/"/g, '\\"') + '"'
}
}
}
4 changes: 3 additions & 1 deletion src/targets/swift/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ module.exports = {
keyValuePairs.push(util.format('"%s": %s', k, this.literalRepresentation(value[k], opts, indentLevel)))
}
return concatArray(keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel)
case '[object Boolean]':
return value.toString()
default:
return '"' + value.replace(/"/g, '\\"') + '"'
return '"' + value.toString().replace(/"/g, '\\"') + '"'
}
}
}
2 changes: 1 addition & 1 deletion test/fixtures/output/c/libcurl/application-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "content-type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}");
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}");

CURLcode ret = curl_easy_perform(hnd);
2 changes: 1 addition & 1 deletion test/fixtures/output/csharp/restsharp/application-json.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var client = new RestClient("http://mockbin.com/har");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}", ParameterType.RequestBody);
request.AddParameter("application/json", "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
2 changes: 1 addition & 1 deletion test/fixtures/output/go/native/application-json.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {

url := "http://mockbin.com/har"

payload := strings.NewReader("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}")
payload := strings.NewReader("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}")

req, _ := http.NewRequest("POST", url, payload)

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/java/okhttp/application-json.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}");
RequestBody body = RequestBody.create(mediaType, "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}");
Request request = new Request.Builder()
.url("http://mockbin.com/har")
.post(body)
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/java/unirest/application-json.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
HttpResponse<String> response = Unirest.post("http://mockbin.com/har")
.header("content-type", "application/json")
.body("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}")
.body("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}")
.asString();
2 changes: 1 addition & 1 deletion test/fixtures/output/javascript/jquery/application-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var settings = {
"content-type": "application/json"
},
"processData": false,
"data": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}"
"data": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}"
}

$.ajax(settings).done(function (response) {
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/output/javascript/xhr/application-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var data = JSON.stringify({
{
"arr_mix_nested": {}
}
]
],
"boolean": false
});

var xhr = new XMLHttpRequest();
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/output/node/native/application-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ req.write(JSON.stringify({ number: 1,
string: 'f"oo',
arr: [ 1, 2, 3 ],
nested: { a: 'b' },
arr_mix: [ 1, 'a', { arr_mix_nested: {} } ] }));
arr_mix: [ 1, 'a', { arr_mix_nested: {} } ],
boolean: false }));
req.end();
3 changes: 2 additions & 1 deletion test/fixtures/output/node/request/application-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var options = { method: 'POST',
string: 'f"oo',
arr: [ 1, 2, 3 ],
nested: { a: 'b' },
arr_mix: [ 1, 'a', { arr_mix_nested: {} } ] },
arr_mix: [ 1, 'a', { arr_mix_nested: {} } ],
boolean: false },
json: true };

request(options, function (error, response, body) {
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/output/node/unirest/application-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ req.send({
{
"arr_mix_nested": {}
}
]
],
"boolean": false
});

req.end(function (res) {
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/output/objc/nsurlsession/application-json.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
@"string": @"f\"oo",
@"arr": @[ @1, @2, @3 ],
@"nested": @{ @"a": @"b" },
@"arr_mix": @[ @1, @"a", @{ @"arr_mix_nested": @{ } } ] };
@"arr_mix": @[ @1, @"a", @{ @"arr_mix_nested": @{ } } ],
@"boolean": @NO };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/ocaml/cohttp/application-json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open Lwt

let uri = Uri.of_string "http://mockbin.com/har" in
let headers = Header.add (Header.init ()) "content-type" "application/json" in
let body = Cohttp_lwt_body.of_string "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}" in
let body = Cohttp_lwt_body.of_string "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}" in

Client.call ~headers ~body `POST uri
>>= fun (res, body_stream) ->
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/php/curl/application-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}",
CURLOPT_POSTFIELDS => "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}",
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/php/http1/application-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'content-type' => 'application/json'
));

$request->setBody('{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}');
$request->setBody('{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}], "boolean": false}');

try {
$response = $request->send();
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/php/http2/application-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$request = new http\Client\Request;

$body = new http\Message\Body;
$body->append('{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}');
$body->append('{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}], "boolean": false}');

$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('POST');
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/python/python3/application-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

conn = http.client.HTTPConnection("mockbin.com")

payload = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}"
payload = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}"

headers = { 'content-type': "application/json" }

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/python/requests/application-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

url = "http://mockbin.com/har"

payload = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}"
payload = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}"
headers = {'content-type': 'application/json'}

response = requests.request("POST", url, data=payload, headers=headers)
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/ruby/native/application-json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request.body = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}"
request.body = "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}"

response = http.request(request)
puts response.read_body
2 changes: 1 addition & 1 deletion test/fixtures/output/shell/curl/application-json.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
curl --request POST \
--url http://mockbin.com/har \
--header 'content-type: application/json' \
--data '{"number":1,"string":"f\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}'
--data '{"number":1,"string":"f\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}], "boolean": false}'
2 changes: 1 addition & 1 deletion test/fixtures/output/shell/httpie/application-json.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
echo '{"number":1,"string":"f\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}' | \
echo '{"number":1,"string":"f\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}], "boolean": false}' | \
http POST http://mockbin.com/har \
content-type:application/json
2 changes: 1 addition & 1 deletion test/fixtures/output/shell/wget/application-json.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
wget --quiet \
--method POST \
--header 'content-type: application/json' \
--body-data '{"number":1,"string":"f\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}]}' \
--body-data '{"number":1,"string":"f\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}], "boolean": false}' \
--output-document \
- http://mockbin.com/har
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let parameters = [
"string": "f\"oo",
"arr": [1, 2, 3],
"nested": ["a": "b"],
"arr_mix": [1, "a", ["arr_mix_nested": []]]
"arr_mix": [1, "a", ["arr_mix_nested": []]],
"boolean": false
]

let postData = NSJSONSerialization.dataWithJSONObject(parameters, options: nil, error: nil)
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/requests/application-json.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
],
"postData": {
"mimeType": "application/json",
"text": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}"
"text": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}], \"boolean\": false}"
}
}
X Tutup