Registry / testing / swagger-test

swagger-test

JSON →
library0.8.0jsnpmunverified

Specification-driven REST API testing tool that validates HTTP responses against Swagger/OpenAPI specifications. Version 0.8.0 is the latest stable release (as of 2016+), with no active maintenance. It offers both CLI and programmatic usage, supports explicit x-amples extension and automatic inference of test cases. Unlike broader API testing frameworks (e.g., Postman, Dredd), swagger-test focuses purely on Swagger spec conformance with no built-in HTTP client.

npm install swagger-test
INSTALL
IMPORT
SIG · SWAGGER-TEST
S
swagger-test
testingjavascriptv0.8.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const swaggerTest = require('swagger-test');
import swaggerTest from 'swagger-test';
Package uses CommonJS, not ESM. No TypeScript typings.
parse
swaggerTest.parse(spec, options);
swaggerTest(spec);
parse() is a method on the default export. Do not try to call the module directly.
CLI
npm install -g swagger-test; swagger-test
CLI reads Swagger spec from stdin and tests against a running server; base URL must be configured via environment or spec.

Shows how to parse a Swagger spec, infer test cases, and run them against a live server using preq and mocha.

const swaggerTest = require('swagger-test'); const preq = require('preq'); const assert = require('assert'); // Load Swagger specification (e.g., from file) const spec = require('./swagger.json'); // Parse to get test examples const xamples = swaggerTest.parse(spec, { inferXamples: true }); // Run tests (assuming server is running) describe('Swagger tests', function() { xamples.forEach(function(xample) { it(xample.description, function() { return preq[xample.request.method](xample.request) .then(function(response) { assert.deepEqual(response, xample.responses[response.status]); }); }); }); });
Debug
Known issues
breakingPackage is abandoned; no updates since 2016. May not work with newer Node.js versions or OpenAPI 3.x.
fix
Consider migrating to Dredd or another active API testing tool.
affects: >=0.8.0
gotchaCLI reads from stdin but requires base URL; if not set, requests may fail or hit wrong host.
fix
Set the x-amples.base-url property in your Swagger spec or configure via environment.
affects: *
gotchaInferred examples use default values from spec; if your spec lacks examples, tests may be minimal or fail.
fix
Add explicit x-amples to generate meaningful test cases.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'swagger-test'
Package not installed or not in node_modules
fix
npm install swagger-test
TypeError: swaggerTest is not a function
Calling the module directly instead of using .parse()
fix
const xamples = swaggerTest.parse(spec);
response did not match specification
Actual HTTP response does not conform to the Swagger spec's expected response
fix
Fix your server's response or update the specification.
Upgrade
Version history
0.8.0latest on npm
Audit
Dependencies
preqoptionalUsed in examples as HTTP client for testing
Agent activity
4 hits · last 30 days
node
4
Resources
swagger-test — npm install swagger-test · libregistry