New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vitest-openapi

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vitest-openapi

[![npm](https://img.shields.io/npm/v/vitest-openapi.svg)](https://www.npmjs.com/package/vitest-openapi) [![test](https://github.com/yutak23/vitest-openapi/actions/workflows/test.yaml/badge.svg)](https://github.com/yutak23/vitest-openapi/actions/workflows/

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
decreased by-40.66%
Maintainers
1
Weekly downloads
 
Created
Source

vitest-openapi

npm test style included

Use Vitest to assert that HTTP responses satisfy an OpenAPI spec.

This library makes jest-openapi functionality available to Vitest.

Features

  • Validates the status and body of HTTP responses against your OpenAPI spec (see usage)
  • Validates objects against schemas defined in your OpenAPI spec (see usage)
  • Load your OpenAPI spec just once in your tests (load from a filepath or object)
  • Supports OpenAPI 2 and 3
  • Supports OpenAPI specs in YAML and JSON formats
  • Supports $ref in response definitions (i.e. $ref: '#/definitions/ComponentType/ComponentName')
  • Informs you if your OpenAPI spec is invalid
  • Supports responses from axios, request-promise, supertest, superagent, and chai-http
  • Use in Vitest

Installation

npm

$ npm install vitest-openapi

yarn

$ yarn add vitest-openapi

Usage

import { describe, expect, it } from 'vitest';
import vitestOpenAPI from 'vitest-openapi';
import axios from 'axios';

// Load an OpenAPI file (YAML or JSON) into this plugin
vitestOpenAPI('path/to/openapi.yml');

// Write your test
describe('GET /example/endpoint', () => {
	it('should satisfy OpenAPI spec', async () => {
		// Get an HTTP response from your server (e.g. using axios)
		const res = await axios.get('http://localhost:3000/example/endpoint');

		expect(res.status).toEqual(200);

		// Assert that the HTTP response satisfies the OpenAPI spec
		expect(res).toSatisfyApiSpec();
	});
});

※See also the Usage section of jest-openapi for more information.

Requirement

If you use TypeScript, need vitest >= 0.31.0 (see the site Extending Matchers).

License

MIT licensed

Keywords

FAQs

Package last updated on 02 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc