3

[https://i.stack.imgur.com/qeFuv.png][1]

I've got few questions about CODE snippets, JSON tiny validator in particular (2) and test tab (1) I'm sending the following POST request ({‌{host}}:{‌{port}}/landlords/{‌{DC_id}}/apartments) to create apartment's instance. The body of the request is the following:


    {
    "address": "Zaharova Street 30",
    "price": 200,
    "square": 20,
    "features": [
    "Good Shopping Facilities","Metro","Recreation area nearby","Friendly and calm neighboors"
    ],
    "active": true
    }
And the exact JSON validation test is the following:


var schema = {
"items": {
"address": "Zaharova Street 30",
"price": 200,
"square": 20,
"features": [
"Good Shopping Facilities","Metro","Recreation area nearby","Friendly and calm neighboors"
],
"active": true
}
};
var data1 = [true, false];
var data2 = [true, 123];
tests["Valid Data1"] = tv4.validate(data1, schema);
tests["Valid Data2"] = tv4.validate(data2, schema);
console.log("Validation failed: ", tv4.error);

I've decided to use this test in order to be sure that apartment was created with the exact parameters that were used in the request body. But I've found that if I change any value inside the JSON validation test (1), and resend the response (I've changed JSON data only in the test tab, not in the body tab) the test still being passed. [https://i.stack.imgur.com/8Dq7B.png][1]

What is the problem ??? Could you show the example how to create that kind of stuff. Best Regards, Artsem.

1 Answers1

7

I had a similar problem, and example below from here helped me resolve it. You seem to be missing "properties" entity.

var schema = {  
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type" : "array",
    "items" : {    
        "type": "object",
        "properties": {
            "id": { 
                "type": "integer" 
            },
            "title": { 
                "type": "string" 
            },
            "url": { 
                "type": "string" 
            },          
            "state": { 
                "type": "string" 
            },
            "body": { 
                "type": "string" 
            },
            "user": {      
                "type" : ["null", "object"],
                "properties" : {
                    "id": { 
                        "type": "integer" 
                    },
                    "login": { 
                        "type": "string" 
                    }
                },
                "additionalProperties": true,
                "required": [ "id", "login" ]
            },
        },
        "additionalProperties": true,
        "required": [ "id", "title", "state", "body", "user", "url"]
    },
}

tests["Valid issues schema"] = tv4.validate(issues, schema);  
console.log(tv4.error);  
Wooram Youn
  • 71
  • 1
  • 4