Socket
Book a DemoInstallSign in
Socket

data2swagger

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data2swagger

convert data to swagger format

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

data2swagger

Build Status Coverage Status

Convert data(string, number, array, json) into swagger schema format with 0 dependencies.

Install

yarn add data2swagger

How to use

const json2swagger = require('data2swagger');

json2swagger(key, value)

Examples

// string
const result = json2swagger('data', 'charlie');
// { data: { type: 'string', example: 'charlie' } }

// number
const result = json2swagger('data1', 123);
// { data1: { type: 'number', example: 123 } }

// boolean
const result = json2swagger('data2', true);
// { data2: { type: 'boolean', example: true } }

// object
const result = json2swagger('data2', {
  charlie: {
    test1: 'yes',
    test2: 123,
    test3: true
  }
});
/** {
  data2: {
    type: 'object',
    properties: {
      charlie: {
        type: 'object',
        properties: {
          test1: { type: 'string', example: 'yes' },
          test2: { type: 'number', example: 123 },
          test3: { type: 'boolean', example: true }
        }
      }
    }
  }
} **/

// array
const result = json2swagger('data2', [
  {
    charlie: {
      test1: 'yes',
      test2: 123,
      test3: true
    }
  }
]);
/** {
  data2: {
    type: 'array',
    items: {
      type: 'object',
      properties: {
        charlie: {
          type: 'object',
          properties: {
            test1: { type: 'string', example: 'yes' },
            test2: { type: 'number', example: 123 },
            test3: { type: 'boolean', example: true }
          }
        }
      }
    }
  }
} **/

Keywords

swagger

FAQs

Package last updated on 01 Jun 2020

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