swagger-strip

1.0.0 • Public • Published

swagger-strip

build status Test coverage NPM version NPM Downloads

strip swagger from one api

Usage

install

npm install swagger-strip

default usage

A demo, data from swagger deafult demo

const swaggerStrip = require('swagger-strip');
swaggerStrip(sourceObject, '/pet/findByStatus');
 
// => result
{
    paths: {
        tags: [ 'pet' ],
        summary: 'Finds Pets by status',
        ...
    },
    refs: { 
        '#/definitions/Pet': {
            type: 'object',
            required: [Array],
            properties: [Object],
            xml: [Object]
        },
        '#/definitions/Category': {...},
        '#/definitions/Tag': {...} },
    tags: [{
        name: 'pet',
        description: 'Everything about your Pets',
        ...
    }]
}

parse json file

const fs = require('fs');
const path = require('path');
const swaggerStrip = require('swagger-strip');
 
const sourceJsonFile = path.join(__dirname, './test.json');
const sourceObject = JSON.parse(fs.readFileSync(sourceJsonFile, 'utf8'));
 
const res = swaggerStrip(sourceObject, '/pet/findByStatus');

parse yml file

parse .yml with js-yaml or what you like;

const sourceYmlFile = path.join(__dirname, './data/test.yml');
const sourceObject = yaml.safeLoad(fs.readFileSync(sourceYmlFile, 'utf8'));
const stripResult = swaggerStrip(sourceObject, '/pet', {
    method: 'post'
});

API

swaggerStrip(sourceObject, path, [options])

sourceObject

swagger source data, maybe you should parse json/yml file to object first

Type: Object

Default: {}

path

some api you want to strip

Type: string

Default: ''

Example: '/pet/findByStatus'

options

Type: Object

Params:

  • method: api method
    • when use swaggerStrip(obj, '/pets'), return paths will equal obj['paths']['/pet/findByStatus']['get']
    • when use swaggerStrip(obj, '/pets', {method: 'post'}), return paths equal obj['paths']['/pet/findByStatus']['post']

Default:

{
    method: `'get'`
}

Development

npm run install
 
npm run test

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i swagger-strip

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

36.7 kB

Total Files

11

Last publish

Collaborators

  • cyseria