Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openapi-sampler

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-sampler

Tool for generation samples based on OpenAPI payload/response schema

  • 1.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
793K
increased by5.59%
Maintainers
1
Weekly downloads
 
Created

What is openapi-sampler?

The openapi-sampler npm package is used to generate sample data from OpenAPI specifications. It helps in creating mock data for API responses based on the defined schemas in the OpenAPI document.

What are openapi-sampler's main functionalities?

Generate Sample from Schema

This feature allows you to generate a sample object based on a given JSON schema. The sample data will adhere to the types and examples specified in the schema.

const openapiSampler = require('openapi-sampler');
const schema = {
  type: 'object',
  properties: {
    id: { type: 'integer', example: 1 },
    name: { type: 'string', example: 'John Doe' }
  }
};
const sample = openapiSampler.sample(schema);
console.log(sample);

Generate Sample from OpenAPI Document

This feature allows you to generate sample data directly from an OpenAPI document. It extracts the schema from the specified path and response, and generates a sample based on it.

const openapiSampler = require('openapi-sampler');
const openapiDoc = {
  openapi: '3.0.0',
  info: { title: 'Sample API', version: '1.0.0' },
  paths: {
    '/user': {
      get: {
        responses: {
          '200': {
            description: 'A user object',
            content: {
              'application/json': {
                schema: {
                  type: 'object',
                  properties: {
                    id: { type: 'integer', example: 1 },
                    name: { type: 'string', example: 'John Doe' }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
};
const sample = openapiSampler.sample(openapiDoc.paths['/user'].get.responses['200'].content['application/json'].schema);
console.log(sample);

Other packages similar to openapi-sampler

Keywords

FAQs

Package last updated on 20 Nov 2024

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