0.1.0 • Published 4 years ago

eslint-plugin-swagger v0.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

eslint-plugin-swagger

{•••} An extensible linter with semantic validations for Swagger specifications.

License Readme Score Inline docs Build Status Codacy Badge Coverage Status NSP Status bitHound Dependencies bitHound Dev Dependencies

1. Table of contents

2. Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-swagger:

$ npm install eslint-plugin-swagger --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-swagger globally.

3. Usage

:information_source: Swagger file extensions

eslint-plugin-swagger evaluates Swagger files that have a .json, .yaml, or .yml file extension.

Add swagger to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "swagger"
    ]
}

Then configure the rules you want to use under the rules section.

{
    "rules": {
        "swagger/rule-name": 2
    }
}

Finally, run ESLint against your Swagger documents.

$ eslint path/to/swagger/docs/** --fix

4. Supported rules

options legend
  • :heavy_check_mark: The rule's log threshold can be extended or disabled
  • :wrench: Supports the --fix command line option
optionsRuleDescriptionStatus
no-dup-pathsEach API path should be unique.Completed
no-path-verbsProhibit verbs in api pathsCompleted
:wrench:require-plural-pathsRequire plural nouns in API pathsCompleted

5. Rules in backlog

The product backlog has lots of lonely rules looking for love from nice contributors like you. :kissing_heart: If you're interested, please:

  1. Set up an eslint-plugin development environment.
  2. Read the contribution guidelines.
  3. Select the rule you want to work on to create a pull request.
  4. Follow the Contributor Covenant Code of Conduct.
  5. Achieve fame and glory!

:information_source: Select a rule's name to open a new issue.

optionsRuleDescriptionStatus
no-circular-refsA definition/model's ancestor cannot be a descendant of said model. (Circular Reference)Available
no-definitions-without-refsEach reference-able definition must have references.Available
no-dup-ancestorsA definition/model cannot declare a property that is already defined by one of its ancestors.Available
no-dup-auth-definition-refsEach authorization/security scope in an authorization/security definition should be unique.Available
no-dup-auth-scope-refsEach authorization/security reference should contain only unique scopes. (Example: For an oauth2 authorization/security requirement, when listing the required scopes, each scope should only be listed once.)Available
no-dup-name-type-pairEach operation parameter should have a unique name and type combination, where Swagger 1.2 uses the paramType property and in Swagger 2.0 uses the in property to indicate type.Available
no-dup-op-methodsEach operation in an API should have a unique method property.Available
require-uniform-paramsEach defined operation path parameters must correspond to a named element in the API's path pattern. (For example, you cannot have a path parameter named id for the following path /pets/{petId} but you must have a path parameter named petId.)Available
no-dup-resource-pathsEach resourcePath should be unique for each API Declaration in the API.Available
no-dup-response-message-codeEach code in an operation's responseMessages should be unique.Available
no-empty-requiredsEach definition/model property listed in the required array must be defined in the properties of the model itself or one of its ancestors.Available
no-form-and-bodyAn operation cannot have a form or formData parameter if it has a body parameterAvailable
no-id-model-mismatchEach model's id property must match the corresponding key in the models section of the API Declaration. (For example, a model with an id of Person should be found at the Person property in the API Declaration's models property and the Person's id value must be Person.)Available
no-multiple-inheritanceModels are not allowed to descend from multiple models. (Multiple Inheritance)Available
no-undefined-ref-definitionEach reference must point to an existing definition.Available
operation-bodyEach operation should have only one parameter of type bodyAvailable
path-definitionThe Resource Listing has an API whose path is not defined in any of the API Declarations.Available
require-array-itemsThe items property is required for all schemas/definitions of type array. (See swagger-api/swagger-spec/issues/174)Available
require-default-valueEvery place where a default value can be provided, the default value must validate against the corresponding schema/definition. (This is not handled by JSON Schema validators, at least not the one I am using, so we have to do this manually. See json-schema/JSON-Schema-Test-Suite/pull/67)Available
require-path-definitionFor each API path parameter, all operations for the API path require corresponding path parameter definitions or the corresponding path parameter needs to be in the path's parameters.Available

6. Contributions

:family: We warmly welcome contributors. Check out the guidelines for Contributing to eslint-plugin-swagger and our Contributor Covenant Code of Conduct.

Contributions are stories with a beginning, a middle, and an end, all told through issues and pull requests.

7. License

Apache 2.0 :copyright: Greg Swindle.


Greenkeeper badge StackShare