Skip to content

A walkthrough of schema validation on server responses with Postman.

License

Notifications You must be signed in to change notification settings

montymi/SchemaAPITesting

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Schema API Validation

Created by: Michael Montanaro


View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact
  7. Acknowledgments

About The Project

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.

(back to top)

Getting Started

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.

(back to top)

Usage

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.

  1. Create and name a workspace (ex. Schema Validation)
  2. On the left side of the screen, click on Environments
  3. Click +, name the environment (ie. Live)
  4. In the variable column, write url
  5. In the initial value column (and the current value column), paste the link to the created mocky.io site
  6. In the top right, click No Environment and select the name of your environment in the drop down menu
  7. On the left side of the screen, click Collections
  8. Click the +, name the collection (ie. Basic Schema)
  9. Create two new requests (ie. PASSED Test and FAILED Test)
  10. In the get bar of both requests, type {{url}}
  • Note: this can just be substituted with the mocky.io link
  1. Click on the Tests tab and paste in the contents of the postmanTesting.js file that is in this directory
  2. Based on desired outcome, change line 22 to be failedSchema or passedSchema
  • Note: failedSchema includes a test parameter that is required and thus fails because it is not present in the HTTP response
  1. Click on the main collection tag (ie. Basic Schema)
  2. Click on the Runs tab and click Run Collection
  3. 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

(back to top)

Structure

  • 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

(back to top)

Contributing

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

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/Example)
  3. Commit your Changes (git commit -m 'Adding example feature')
  4. Push to the Branch (git push origin feature/Example)
  5. Open a Pull Request

(back to top)

License

Distributed under the GNU General Public License. See LICENSE.txt for more information.

(back to top)

Contact

Michael Montanaro - LinkedIn - GitHub - Email

(back to top)

Acknowledgments

(back to top)

About

A walkthrough of schema validation on server responses with Postman.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published