Created by: Michael Montanaro
View Demo
·
Report Bug
·
Request Feature
Table of Contents
This repo is a walkthrough on how to validate schema files against API's via their server responses using Postman. The example is simple but highly applicable and easily modified to meet your use case. Following the steps below will get you more familiar with Postman before you attempt to switch over to your own projects.
The following will lead you through how to use the files in this repo to conduct the same testing in Postman for practice:
- Clone this repo (below uses HTTPS method):
git clone https://github.com/montymi/SchemaAPITesting.git
- Navigate into the directory and copy the contents of
postmanHTTPresponse.json
- Go to mocky.io, click
New Mock
and paste the contents of the json file into the HTTP Response Body section - Change the expiration date of this mock HTTP server (if you would like)
- Click
GENERATE MY HTTP RESPONSE
and copy the url that is generated (will be used later so save it somewhere if necessary) - Sign into your Postman account, it is completely free for individual use
That's it for the setup, go to Usage for next steps.
Below will take you through steps necessary to setup a testing environment and run the created tests. It is important to note that some of the techniques/steps below (ie. environment setup) are strictly good practice, but can be substituted for other methods.
- Create and name a workspace (ex. Schema Validation)
- On the left side of the screen, click on
Environments
- Click
+
, name the environment (ie.Live
) - In the variable column, write
url
- In the initial value column (and the current value column), paste the link to the created
mocky.io
site - In the top right, click
No Environment
and select the name of your environment in the drop down menu - On the left side of the screen, click
Collections
- Click the
+
, name the collection (ie.Basic Schema
) - Create two new requests (ie.
PASSED Test
andFAILED Test
) - In the
get
bar of both requests, type{{url}}
- Note: this can just be substituted with the
mocky.io
link
- Click on the
Tests
tab and paste in the contents of thepostmanTesting.js
file that is in this directory - Based on desired outcome, change line 22 to be
failedSchema
orpassedSchema
- Note:
failedSchema
includes atest
parameter that is required and thus fails because it is not present in the HTTP response
- Click on the main collection tag (ie.
Basic Schema
) - Click on the
Runs
tab and clickRun Collection
- Lastly, no need to change any settings, just click the
Run
button near the bottom of the page
- IMPORTANT: In order to import your own schema file, the link must be for the raw content not the general github page
- README.md -> Walkthrough of testing procedure
- failed-schema.json -> schema validated against HTTP response that will FAIL because of added
test
parameter marked as required - passed-schema.json -> schema validated against HTTP response that will PASS because the parameters match
- postmanHTTPResponse.json -> file whose contents are set to be the HTTP response by the
mocky
server - postmanTesting.js -> file whose contents are pasted into the
Tests
section of a Postman request
Contributions are, in my opinion, the greatest part of OSS and are what will be the key to continuing the growth of the community. One of the main goals of this README is to facilitate contributions of potential developers. In this section, developers must be sure to lay out any coding styling choices that they may have so that the source code can remain as uniform as possible. One such project that has an immpressive contributions page is htop by htop-dev who point all potential incoming contributors to their style guide
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/Example
) - Commit your Changes (
git commit -m 'Adding example feature'
) - Push to the Branch (
git push origin feature/Example
) - Open a Pull Request
Distributed under the GNU General Public License. See LICENSE.txt
for more information.