Skip to content

Commit

Permalink
Add schema validation sectio
Browse files Browse the repository at this point in the history
  • Loading branch information
vdespa committed Dec 27, 2019
1 parent 774370b commit abe53da
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# The short X.Y version
version = u''
# The full version, including alpha/beta/rc tags
release = u'Version 1.4.1 - October 2019'
release = u'Version 1.5.0 - December 2019'


# -- General configuration ---------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Simple solutions to common problems

request-creation
assertions
schema-validation
libraries
workflows
newman
Expand Down
70 changes: 70 additions & 0 deletions docs/schema-validation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
*****************
Schema validation
*****************

This section contains different examples of validating JSON responses using the Ajv schema validator. I do not recommend using the tv4 (Tiny Validator for JSON Schema v4).

Response is an object
---------------------

This is the JSON response: ::

{}

This is the JSON schema: ::

const schema = {
"type": "object",
};

And here is the test: ::

pm.test("Validate schema", () => {
pm.response.to.have.jsonSchema(schema);
});


Object has optional property
----------------------------

This is the JSON response: ::

{
"code": "FX002"
}

This is the JSON schema with a property named code of type String: ::

const schema = {
"type": "object",
"properties": {
"code": { "type": "string" }
}
};

Possible types are:
- integer
- number
- boolean
- null
- Object
- array

Object has required property
----------------------------

This is the JSON response: ::

{
"code": "FX002"
}

This is the JSON schema with a property named code of type String that is mandatory: ::

const schema = {
"type": "object",
"properties": {
"code": { "type": "string" }
},
"required": ["code"]
};

0 comments on commit abe53da

Please sign in to comment.