swagger-test: Testing of Swagger APIs

[ bsd3, library, program, testing ] [ Propose Tags ]

This package provides a library and executable tool that supports testing APIs specified with Swagger. It allows one to generate arbitrary Swagger requests for any given specification.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.2.5, 0.2.6, 0.2.7
Dependencies aeson, attoparsec, base (>=4.7 && <5), binary, bytestring, case-insensitive, filepath, http-client, http-client-tls, http-media, http-types, insert-ordered-containers, lens, optparse-applicative, QuickCheck (>=2.10 && <2.11), random, scientific, swagger-test, swagger2, syb, text, unordered-containers, vector [details]
License BSD-3-Clause
Copyright 2017 Rodrigo Setti. All rights reserved
Author Rodrigo Setti
Maintainer rodrigosetti@gmail.com
Category Testing
Home page https://github.com/rodrigosetti/swagger-test
Bug tracker https://github.com/rodrigosetti/swagger-test/issues
Source repo head: git clone https://github.com/rodrigosetti/swagger-test
Uploaded by rodrigosetti at 2017-09-01T02:41:55Z
Distributions
Executables swagger-test
Downloads 4559 total (24 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-09-01 [all 1 reports]

Readme for swagger-test-0.1.0

[back to package description]

swagger-test

This is a tool for Property Based Testing of swagger APIs.

It basically allow you to approximate the computation of the following proposition:

valid(response, schema), response = execute(request), ∀ request ∈ schema

Which translates to:

For all valid requests that can be derived from my Swagger schema, the API response obtained from executing that request is valid according to the same Swagger schema.

The tool exposes several ways to configure get value from parts of it, for example, you may be interested in getting just a random valid request from the schema (use the generate command), or validating if a given response (from a particular operation) is valid (use the validate command), or, run one sample instance of the full proposition, which picks a random request and validate it's resulting response (use the request command).

The generator random request values are reproducible by re-using the same seed value, or one can focus on a particular operation by specifying the operation id.

The tool also simplifies integration with other systems by allowing to configure output formats as standard HTTP message, JSON, or curl. Additionally, there are Haskell modules exposed as a library if one wants to build on top of it.

Command Line Interface

swagger-test supports three commands:

  • generate - generates a new random valid request from Swagger schema.
  • validate - validate a response to a given operation id, according to the schema.
  • request - generate and make the request, then validates the response (combines generate and validate).
swagger-test --help
Testing tool for Swagger APIs

Usage: swagger-test [-s|--schema FILENAME] COMMAND
  Generate Swagger requests and validates responses

Available options:
  -s,--schema FILENAME     swagger JSON schema file to read
                           from (default: "swagger.json")
  -h,--help                Show this help text

Available commands:
  generate                 Generate a random request according to Schema
  validate                 Validate a response against Schema
  request                  Generate, make the request, and validate response

Sub-commands

Generate

Usage: swagger-test generate [--seed N] [-o|--operation ID]
                             [--request-format http|curl|none|json] [-i|--info]
                             [--size N]
  Generate a request

Available options:
  --seed N                 specify the seed for the random generator
  -o,--operation ID        specify a operation id to test (default pick
                           randomly)
  --request-format http|curl|none|json
                           output format of the HTTP request (default: http)
  -i,--info                render information about seed and operation id
  --size N                 control the size of the generated
                           request (default: 30)
  -h,--help                Show this help text

Validate

Usage: swagger-test validate [FILENAME] (-o|--operation ID)
  Validate a response

Available options:
  FILENAME                 http response file to read from (default=stdin)
  -o,--operation ID        specify a operation id to test (default pick
                           randomly)
  -h,--help                Show this help text

Request

Usage: swagger-test request [--seed N] [-o|--operation ID]
                            [--request-format http|curl|none|json]
                            [--response-format http|json|none] [-i|--info]
                            [--size N]
  Generate, make the request, and validate response

Available options:
  --seed N                 specify the seed for the random generator
  -o,--operation ID        specify a operation id to test (default pick
                           randomly)
  --request-format http|curl|none|json
                           output format of the HTTP request (default: none)
  --response-format http|json|none
                           output format of the HTTP request (default: none)
  -i,--info                render information about seed and operation id
  --size N                 control the size of the generated
                           request (default: 30)
  -h,--help                Show this help text