Skip to content

Commit b3f9126

Browse files
committed
Use indent count for indent JSON in Dart
1 parent 26a479f commit b3f9126

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

codegens/dart-http/lib/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ function parseUrlEncoded (body, indent, trim) {
3131
* @param {Object} body Raw body data
3232
* @param {Boolean} trim indicates whether to trim string or not
3333
* @param {String} contentType the content-type of request body
34+
* @param {Integer} indentCount the number of space to use
3435
*/
35-
function parseRawBody (body, trim, contentType) {
36+
function parseRawBody (body, trim, contentType, indentCount) {
3637
if (contentType && (contentType === 'application/json' || contentType.match(/\+json$/))) {
3738
try {
3839
let jsonBody = JSON.parse(body);
39-
return `request.body = json.encode(${JSON.stringify(jsonBody, null, 4)});`;
40+
return `request.body = json.encode(${JSON.stringify(jsonBody, null, indentCount)});`;
4041

4142
}
4243
catch (error) {
@@ -129,7 +130,7 @@ function parseBody (body, indent, trim, contentType) {
129130
case 'urlencoded':
130131
return parseUrlEncoded(body.urlencoded, indent, trim);
131132
case 'raw':
132-
return parseRawBody(body.raw, trim, contentType);
133+
return parseRawBody(body.raw, trim, contentType, indent.length);
133134
case 'formdata':
134135
return parseFormData(body.formdata, indent, trim);
135136
case 'graphql':

0 commit comments

Comments
 (0)