Examples
Check more than the status
Success criteria beyond the status: a condition on the body, a regex on a header and a JSONPath on the body, plus one that fails on purpose.
What it tests: a product search answers 200, finds results, returns JSON and has at least one product with a price above 0. A second workflow fails on purpose.
Download the contract Download the ArazzoOpen it in Luvin
Section titled “Open it in Luvin”- Download the files with the buttons above.
- In Luvin, create a collection with New collection on the workspace home, or open one you already have.
- Under Quick actions, click Import Arazzo or contracts and choose the downloaded
.yamlfiles together. - In the sidebar, open the workflow Search phones.
- In the run bar, choose Real API.
- Press Run. The results open at the bottom.
The key lines
Section titled “The key lines”arazzo: 1.0.1info: title: Success criteria beyond the status version: 1.0.0sourceDescriptions: - name: dummyjson url: ./dummyjson.openapi.yaml type: openapiworkflows: - workflowId: searchPhones summary: Search products and check the status, a number, a header and a price inputs: type: object properties: q: { type: string, example: phone } steps: - stepId: search operationId: searchProducts parameters: - name: q in: query value: $inputs.q - name: limit in: query value: 3 - name: select in: query value: title,price successCriteria: - condition: $statusCode == 200 - condition: $response.body#/total > 0 - context: $response.header.Content-Type condition: ^application/json type: regex - context: $response.body condition: $.products[?(@.price > 0)] type: jsonpath outputs: total: $response.body#/total firstTitle: $response.body#/products/0/title outputs: total: $steps.search.outputs.total
- workflowId: impossiblePrice summary: Fails on purpose - no phone costs more than 100000 steps: - stepId: search operationId: searchProducts parameters: - name: q in: query value: phone - name: limit in: query value: 3 - name: select in: query value: title,price successCriteria: - condition: $statusCode == 200 - context: $response.body condition: $.products[?(@.price > 100000)] type: jsonpath| Line | What it does |
|---|---|
| 30 | A simple condition on the status. Simple is the default type. |
| 31 | A simple condition on a value of the body: the search found at least one product. |
| 32-34 | A regex criterion. Its context is the header Content-Type, which must start with application/json. |
| 35-37 | A jsonpath criterion on the whole body. It passes when the path finds at least one match: here, a product with a price above 0. |
| 44-60 | The second workflow, impossiblePrice, asks for a price above 100000. No phone costs that much, so it fails on purpose. |
What you get
Section titled “What you get”Both workflows call GET /products/search?q=phone&limit=3&select=title,price.
| Workflow | Step | HTTP status | Result |
|---|---|---|---|
searchPhones |
search |
200 | All four criteria hold. Output total = 23. Passed. |
impossiblePrice |
search |
200 | The API answered 200, but the JSONPath criterion does not hold. Failed. |
The reason Luvin prints for impossiblePrice is:
JSONPath found no matches in $response.body.A status of 200 is not enough: the step fails because a criterion fails. The workflow stops there and its outputs stay empty. In expect.json of the recipe this workflow is marked failed, because failing is what it should do.
A criterion of type regex explains itself too. With condition: ^text/html on the same header, the reason reads:
$response.header.Content-Type = "application/json; charset=utf-8" does not match /^text/html/Try this
Section titled “Try this”- Change
qtolaptopin the Inputs tab and runsearchPhonesagain. The total becomes5and the criteria still hold. - In
impossiblePrice, change100000to100. The criterion now finds the products that cost more than 100 and the workflow passes.