0.0.10 • Published 3 years ago

swaggerlint v0.0.10

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

Swaggerlint

Swaggerlint helps you to have a consistent API style by linting your swagger / OpenAPI Scheme.

Installation

Install it in your project

npm install swaggerlint

Install it globally

npm install --global swaggerlint

Usage

CLI

You can lint your swagger scheme by path

swaggerlint /path/to/swagger.json

Or by providing a URL

swaggerlint https://...

Config flag

swaggerlint will automatically search up the directory tree for a swaggerlint.config.js file. Or you can specify it explicitly

swaggerlint --config /path/to/swaggerlint.config.js

Nodejs

const {swaggerlint} = require('swaggerlint');
const config = require('./configs/swaggerlint.config.js');
const swaggerScheme = require('./swagger.json');

const result = swaggerlint(swaggerScheme, config);

console.log(result); // an array or errors

/**
 * [{
 *   name: 'string', // rule name
 *   msg: 'string', // message from the rule checker
 *   location: ['path', 'to', 'error'] // what caused an error
 * }]
 */

Docker image

If you do not have nodejs installed you can use the swaggerlint docker image.

Config

// swaggerlint.config.js
module.exports = {
    rules: {
        'object-prop-casing': ['camel'],
        'properties-for-object-type': true,
        'latin-definitions-only': true,
    },
};

Rules

You can set any rule value to false to disable it or to true to enable and set its setting to default value.

rule namedescriptiondefault
expressive-path-summaryEnforces an intentional path summary
latin-definitions-onlyBans non Latin characters usage in definition names["placeholder_to_be_removed",{"ignore":[]}]
no-empty-object-typeObject types have to have their properties specified explicitly
no-external-refsForbids the usage of external ReferenceObjects
no-inline-enumsEnums must be in DefinitionsObject or ComponentsObject
no-ref-propertiesDisallows to have additional properties in Reference objects
no-single-allofObject types should not have a redundant single allOf property
no-trailing-slashURLs must NOT end with a slash
object-prop-casingCasing for your object property names"camel"
only-valid-mime-typesChecks mime types against known from mime-db
parameter-casingCasing for your parameters"camel",{"header":"kebab"}
path-param-required-fieldHelps to keep consistently set optional required property in path parameters
required-operation-tagsAll operations must have tags
required-parameter-descriptionAll parameters must have description
required-tag-descriptionAll tags must have description

Documentation

Acknowledgments

This tool has been inspired by already existing swagger validation checkers:

0.0.10

3 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2-0

4 years ago

0.0.1

4 years ago