1.0.0 • Published 7 years ago
swagger-strip v1.0.0
swagger-strip
strip swagger from one api
Usage
install
npm install swagger-stripdefault 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 equalobj['paths']['/pet/findByStatus']['get']
- when use swaggerStrip(obj, '/pets', {method: 'post'}), return paths equalobj['paths']['/pet/findByStatus']['post']
 
- when use 
Default:
{
    method: `'get'`
}Development
npm run install
npm run testLicense
MIT