Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/main/java/com/postman/collection/Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ public static Collection pmcFactory(String json) {
gsonBuilder.registerTypeAdapter(Item.class, new com.postman.collection.adapter.ItemDeserializer());
gsonBuilder.registerTypeAdapter(ItemGroup.class, new com.postman.collection.adapter.ItemGroupDeserializer());
pmcRetVal = gsonBuilder.create().fromJson(json, Collection.class);
//Added to hopefully allow JSON comments
//gsonBuilder.setLenient();
pmcRetVal.init();

return pmcRetVal;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/postman/collection/CollectionElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@ public boolean validate(String altSchemaJSON) throws ValidationException {
{
valMsg = vm.getMessage();
valPath = vm.getPath();

//Ignore `default` keyword
ignoreValidationErrors = ignoreValidationErrors && valMsg.contains("$.variable[") && valMsg.contains(".type: does not have a value in the enumeration [string, boolean, any, number]");
//Ignore "JSON comments"
}



return ((this.validationMessages == null || this.validationMessages.size() == 0) || ignoreValidationErrors);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"info": {
"_postman_id": "422e93b7-b31b-4384-9e80-28c1b8e743c6",
"name": "Body With Comments",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "23889826",
"_collection_link": "https://v10-technical-enablement.postman.co/workspace/JPostman~d827e22e-3694-408d-b18b-d3eea108c001/collection/23889826-422e93b7-b31b-4384-9e80-28c1b8e743c6?action=share&creator=23889826&source=collection_link"
},
"item": [
{
"name": "Raw-text JSON",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"json-field1\":\"value 1\"\n /* JSON Comment */\n ,\"json-field2\":\"value 2\"\n //another JSON comment\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
}
},
"response": [
{
"name": "NORMAL Raw-text JSON",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"json-field1\":\"value 1\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "text",
"header": [],
"cookie": [],
"body": "THis is the expected response"
}
]
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "field3value",
"value": "field-3 variable value",
"type": "string"
},
{
"key": "Xfield3value",
"value": "Xfield-3 variable value",
"type": "string"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"info": {
"_postman_id": "9a5d446d-b91f-4bb3-a59e-0bd183e68143",
"name": "Body With Comments Copy",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "23889826",
"_collection_link": "https://v10-technical-enablement.postman.co/workspace/JPostman~d827e22e-3694-408d-b18b-d3eea108c001/collection/23889826-9a5d446d-b91f-4bb3-a59e-0bd183e68143?action=share&creator=23889826&source=collection_link"
},
"item": [
{
"name": "Raw-text JSON",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"json-field1\":\"value 1\"\n \n ,\"json-field2\":\"value 2\"\n \n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
}
},
"response": [
{
"name": "NORMAL Raw-text JSON",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"json-field1\":\"value 1\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "text",
"header": [],
"cookie": [],
"body": "THis is the expected response"
}
]
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "field3value",
"value": "field-3 variable value",
"type": "string"
},
{
"key": "Xfield3value",
"value": "Xfield-3 variable value",
"type": "string"
}
]
}
20 changes: 19 additions & 1 deletion src/test/java/com/postman/collection/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1608,4 +1608,22 @@ public void testWriteToPostman() {

}

}
@Test
public void testValidateWithBodyComments() {

boolean valid = false;



try {
pmcTest = Collection.pmcFactory(new File(filePath + resourcePath + "/body-with-no-comments.postman_collection.json"));
valid = pmcTest.validate();
}
catch(Exception e) {
e.printStackTrace();
}




}}