Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed indentation for generated Json body for request and response. #6

Merged
merged 2 commits into from
Oct 7, 2019
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
7 changes: 4 additions & 3 deletions lib/helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const SDK = require('postman-collection'),
_ = require('lodash'),
jsf = require('json-schema-faker');
jsf = require('json-schema-faker'),
INDENT_COUNT = 2;

jsf.option({
alwaysFakeOptionals: true
Expand Down Expand Up @@ -227,7 +228,7 @@ helper = {
convertedResponse.code = res.code;
convertedResponse.name = res.name || res.code;
res.body &&
(convertedResponse.body = JSON.stringify(helper.convertBody(res.body, types, null)));
(convertedResponse.body = JSON.stringify(helper.convertBody(res.body, types, null), null, INDENT_COUNT));
_.forEach(res.headers, (header) => {
convertedResponse.headers.add(helper.convertHeader(header, types));
});
Expand Down Expand Up @@ -392,7 +393,7 @@ helper = {
method.description && (request.description = method.description);
method.body && (request.body = new SDK.RequestBody({
mode: 'raw',
raw: JSON.stringify(helper.convertBody(method.body, globalParameters.types, request))
raw: JSON.stringify(helper.convertBody(method.body, globalParameters.types, request), null, INDENT_COUNT)
})) && request.headers.add(helper.getContentTypeHeader(mediaType));
method.responses && (item.responses.add(helper.convertResponse(method.responses, globalParameters.types)));
securedBy && (request.auth = helper.convertSecurityScheme(securedBy[0], globalParameters.securitySchemes));
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/valid-raml/ramlSpecBasicCollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"cookie": [],
"code": "201",
"name": "201",
"body": "{\"groupName\":\"groupName example\",\"deptCode\":12345}"
"body": "{\n \"groupName\": \"groupName example\",\n \"deptCode\": 12345\n}"
}
],
"event": [],
Expand Down Expand Up @@ -80,7 +80,7 @@
"method": "POST",
"body": {
"mode": "raw",
"raw": "{\"firstname\":\"someName\",\"lastname\":\"someLastName\",\"age\":10}"
"raw": "{\n \"firstname\": \"someName\",\n \"lastname\": \"someLastName\",\n \"age\": 10\n}"
},
"auth": {
"type": "basic",
Expand Down Expand Up @@ -121,4 +121,4 @@
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"description": "This is a simple raml API."
}
}
}
38 changes: 29 additions & 9 deletions test/fixtures/valid-raml/ramlSpecExamplesCollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
{
"response": [],
"event": [],
"name": "/organization",
"request": {
"url": "{{baseUrl}}/organization",
"url": {
"path": [
"organization"
],
"host": [
"{{baseUrl}}"
],
"query": [],
"variables": []
},
"header": [
{
"key": "Content-Type",
Expand All @@ -18,10 +28,10 @@
"description": "the identifier for the user who posts a new organization"
}
],
"method": "post",
"method": "POST",
"body": {
"mode": "raw",
"raw": "{\"name\":\"Doe Enterprise\",\"value\":\"Silver\"}"
"raw": "{\n \"name\": \"Doe Enterprise\",\n \"value\": \"Silver\"\n}"
}
}
},
Expand All @@ -32,14 +42,24 @@
"cookie": [],
"code": "201",
"name": "201",
"body": "{\"name\":\"Acme\"}"
"body": "{\n \"name\": \"Acme\"\n}"
}
],
"event": [],
"description": "Returns an organization entity.",
"name": "/organization",
"request": {
"url": "{{baseUrl}}/organization",
"method": "get"
"url": {
"path": [
"organization"
],
"host": [
"{{baseUrl}}"
],
"query": [],
"variables": []
},
"method": "GET",
"description": "Returns an organization entity."
}
}
],
Expand All @@ -50,8 +70,8 @@
"event": [],
"variable": [
{
"type": "any",
"key": "baseUrl"
"type": "string",
"value": ""
}
],
"info": {
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/valid-raml/ramlSpecTypesCollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"method": "POST",
"body": {
"mode": "raw",
"raw": "{\"name\":\"Doe Enterprise\",\"value\":\"Silver\"}"
"raw": "{\n \"name\": \"Doe Enterprise\",\n \"value\": \"Silver\"\n}"
}
}
},
Expand All @@ -62,7 +62,7 @@
"cookie": [],
"code": "201",
"name": "201",
"body": "{\"name\":\"Software Corp\",\"address\":\"35 Central Street\"}"
"body": "{\n \"name\": \"Software Corp\",\n \"address\": \"35 Central Street\"\n}"
}
],
"event": [],
Expand Down Expand Up @@ -119,6 +119,6 @@
"name": "Types raml API",
"version": "",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"description": "# Description\n\n\n\n# Documentation\n\n"
"description": ""
}
}
}