Created
September 7, 2021 20:43
-
-
Save amaralrfl/67a3faa5ad8501274455895374ec0704 to your computer and use it in GitHub Desktop.
Collection criada para ser utilizada no exemplo de validação de JSON Schema no Postman com o ServeRest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"info": { | |
"_postman_id": "5e73b0b1-ff8b-4f12-a38b-d159afb7c242", | |
"name": "ServeRest", | |
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | |
}, | |
"item": [ | |
{ | |
"name": "/produtos", | |
"event": [ | |
{ | |
"listen": "prerequest", | |
"script": { | |
"exec": [ | |
"pm.variables.set(\"schema\", ", | |
"{", | |
" \"type\": \"object\",", | |
" \"required\": [", | |
" \"quantidade\",", | |
" \"produtos\"", | |
" ],", | |
" \"properties\": {", | |
" \"quantidade\": {", | |
" \"type\": \"integer\",", | |
" \"default\": 0", | |
" },", | |
" \"produtos\": {", | |
" \"type\": \"array\",", | |
" \"additionalItems\": true,", | |
" \"items\": {", | |
" \"anyOf\": [", | |
" {", | |
" \"type\": \"object\",", | |
" \"required\": [", | |
" \"nome\",", | |
" \"descricao\",", | |
" \"preco\",", | |
" \"quantidade\",", | |
" \"_id\"", | |
" ],", | |
" \"properties\": {", | |
" \"nome\": {", | |
" \"type\": \"string\"", | |
" },", | |
" \"descricao\": {", | |
" \"type\": \"string\"", | |
" },", | |
" \"preco\": {", | |
" \"type\": \"integer\"", | |
" },", | |
" \"quantidade\": {", | |
" \"type\": \"integer\",", | |
" \"default\": 0", | |
" },", | |
" \"_id\": {", | |
" \"type\": \"string\"", | |
" }", | |
" },", | |
" \"additionalProperties\": true", | |
" }", | |
" ]", | |
" }", | |
" }", | |
" },", | |
" \"additionalProperties\": true", | |
"});" | |
], | |
"type": "text/javascript" | |
} | |
}, | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('Deve retornar uma resposta com Schema válido', function () {", | |
" var jsonData = pm.response.json();", | |
" var schema = pm.variables.get(\"schema\");", | |
" var isSchemaValid = tv4.validate(jsonData, schema);", | |
" if(!isSchemaValid)", | |
" console.error(tv4.error);", | |
" pm.expect(isSchemaValid).to.be.true;", | |
"});" | |
], | |
"type": "text/javascript" | |
} | |
} | |
], | |
"request": { | |
"method": "GET", | |
"header": [], | |
"url": { | |
"raw": "https://serverest.dev/produtos", | |
"protocol": "https", | |
"host": [ | |
"serverest", | |
"dev" | |
], | |
"path": [ | |
"produtos" | |
] | |
} | |
}, | |
"response": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment