Support array responses
See original GitHub issueA response example
[
{
"product_id": "efbbbf00-0000-0000-0000-000000000000",
"description": "Incredibly fantastic product",
"name": "Fantastic product"
}
]
A content test
---
version: 1
tests:
contentTests:
- openApiOperationId: getProducts
responseBodyTests:
- key: "[]" # << Suggested notation, could be a dot or wathever else
minLength: 1
- key: "[0].name"
value: "Fantastic product"
Generated script
// Set response object as internal variable
let jsonData = {};
try {jsonData = pm.response.json();}catch(e){}
// Response body should have property "[]"
pm.test("[GET]::/products - Content check if property '[]' exists", function() {
pm.expect((typeof jsonData.[] !== "undefined")).to.be.true;
// ---------------------------^ SYNTAX ERROR
});
// Response body should have a minimum length of "1" for "[]"
if (jsonData?.[]) {
// ----------^ SYNTAX ERROR
pm.test("[GET]::/products - Content check if value of '[]' has a minimum length of '1'", function() {
pm.expect(jsonData.[].length).is.at.least(1);
// -------------------^ SYNTAX ERROR
})};
// Response body should have property "[0].name"
pm.test("[GET]::/products - Content check if property '[0].name' exists", function() {
pm.expect((typeof jsonData.[0].name !== "undefined")).to.be.true;
// ---------------------------^ SYNTAX ERROR (see #333 )
});
// Response body should have value "Fantastic product" for "[0].name"
if (jsonData?.[0].name) {
pm.test("[GET]::/products - Content check if value for '[0].name' matches 'Fantastic product'", function() {
pm.expect(jsonData.[0].name).to.eql("Fantastic product");
// -------------------^ SYNTAX ERROR (see #333 )
})};
Expected script
// Set response object as internal variable
let jsonData = {};
try {jsonData = pm.response.json();}catch(e){}
// Response body should be an array
pm.test("[GET]::/products - Content check if response is an array", function() {
pm.expect(jsonData).to.be.an('array');
});
// Response body should have a minimum length of "1"
pm.test("[GET]::/products - Content check if value has a minimum length of '1'", function() {
pm.expect(jsonData.length).is.at.least(1);
});
// Response body should have property "[0].name"
pm.test("[GET]::/products - Content check if property '[0].name' exists", function() {
pm.expect((typeof jsonData[0].name !== "undefined")).to.be.true;
});
// Response body should have value "Fantastic product" for "[0].name"
if (jsonData?.[0].name) {
pm.test("[GET]::/products - Content check if value for '[0].name' matches 'Fantastic product'", function() {
pm.expect(jsonData[0].name).to.eql("Fantastic product");
})};
Tested version: v1.16.1
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
Support array-type response body by default #2809 - GitHub
I would like the openapiv2 and grpc-gateway plugins to support mapping an HTTP response to a repeated field, so that we can have...
Read more >Array Response | Chainlink Documentation
Array Response. On this page. Overview; Example. This guide explains how to make an HTTP GET request to an external API, that returns...
Read more >Different JSON array response - Stack Overflow
The JSON responses are different! The first one is an object, surrounded by { } , which contains a field "gear" that is...
Read more >How to extract data from array within Response Body
I am trying to capture a value from the Response Body and feed it into a custom field on our incident table, something...
Read more >JSON response starts with an array | Support Center
Hi, We have configure service rest and send out pagelist data in json format as response. We are getting the response, but the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@thim81 Thanks for this great job, I’ll test this as soon as possible!
@Kallys We just release Portman v1.17, which includes the enhancement for targeting the root object or array, which should solve your reported issue.