All Projects → APIDevTools → Swagger Cli

APIDevTools / Swagger Cli

Licence: mit
Swagger 2.0 and OpenAPI 3.0 command-line tool

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Swagger Cli

Swagger Parser
Swagger 2.0 and OpenAPI 3.0 parser/validator
Stars: ✭ 710 (+121.18%)
Mutual labels:  swagger, json-schema, parser, validation, validator
Fast Xml Parser
Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
Stars: ✭ 1,021 (+218.07%)
Mutual labels:  cli, parser, validator
Aptos
☀️ A tool for validating data using JSON Schema and converting JSON Schema documents into different data-interchange formats
Stars: ✭ 144 (-55.14%)
Mutual labels:  json-schema, cli, validation
Schemasafe
A reasonably safe JSON Schema validator with draft-04/06/07/2019-09 support.
Stars: ✭ 67 (-79.13%)
Mutual labels:  json-schema, validation, validator
openui5-validator
A library to validate OpenUI5 fields
Stars: ✭ 17 (-94.7%)
Mutual labels:  validation, json-schema, validator
Swaggen
OpenAPI/Swagger 3.0 Parser and Swift code generator
Stars: ✭ 385 (+19.94%)
Mutual labels:  swagger, cli, parser
openapi-schemas
JSON Schemas for every version of the OpenAPI Specification
Stars: ✭ 22 (-93.15%)
Mutual labels:  validation, json-schema, swagger
Validr
A simple, fast, extensible python library for data validation.
Stars: ✭ 205 (-36.14%)
Mutual labels:  json-schema, validation, validator
Prance
Resolving Swagger/OpenAPI 2.0 and 3.0 Parser
Stars: ✭ 133 (-58.57%)
Mutual labels:  swagger, parser, validator
Maat
Validation and transformation library powered by deductive ascending parser. Made to be extended for any kind of project.
Stars: ✭ 27 (-91.59%)
Mutual labels:  validation, json-schema, validator
i18n-tag-schema
Generates a json schema for all i18n tagged template literals in your project
Stars: ✭ 15 (-95.33%)
Mutual labels:  validation, json-schema
openapi-schema-validator
OpenAPI schema validator for Python
Stars: ✭ 35 (-89.1%)
Mutual labels:  validation, swagger
NZ-Bank-Account-Validator
A small, zero dependency NZ bank account validation library that runs everywhere.
Stars: ✭ 15 (-95.33%)
Mutual labels:  validation, validator
python-valid8
Yet another validation lib ;). Provides tools for general-purpose variable validation, function inputs/outputs validation as well as class fields validation. All entry points raise consistent ValidationError including all contextual details, with dynamic inheritance of ValueError/TypeError as appropriate.
Stars: ✭ 24 (-92.52%)
Mutual labels:  validation, validator
thai-citizen-id-validator
🦉 Validate Thai Citizen ID with 0 dependencies 🇹🇭
Stars: ✭ 35 (-89.1%)
Mutual labels:  validation, validator
checker
Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.
Stars: ✭ 62 (-80.69%)
Mutual labels:  validation, validator
svelte-form
JSON Schema form for Svelte v3
Stars: ✭ 47 (-85.36%)
Mutual labels:  validation, json-schema
excel validator
Python script to validate data in Excel files
Stars: ✭ 14 (-95.64%)
Mutual labels:  validation, validator
verum-php
Server-Side Validation Library for PHP
Stars: ✭ 17 (-94.7%)
Mutual labels:  validation, validator
validation
Validation on Laravel 5.X|6.X|7.X|8.X
Stars: ✭ 26 (-91.9%)
Mutual labels:  validation, validator

Swagger/OpenAPI CLI

Cross-Platform Compatibility Build Status

Dependencies Coverage Status

npm License Buy us a tree

Features

  • Validate Swagger/OpenAPI files in JSON or YAML format
  • Supports multi-file API definitions via $ref pointers
  • Bundle multiple Swagger/OpenAPI files into one combined file

Related Projects

Installation

Install using npm:

npm install -g @apidevtools/swagger-cli

Usage

swagger-cli <command> [options] <file>

Commands:
    validate                Validates an API definition in Swagger 2.0 or OpenAPI 3.0 format

    bundle                  Bundles a multi-file API definition into a single file

Options:
    -h, --help              Show help for any command
    -v, --version           Output the CLI version number
    -d, --debug [filter]    Show debug output, optionally filtered (e.g. "*", "swagger:*", etc.)

Validate an API

The swagger-cli validate command will validate your Swagger/OpenAPI definition against the Swagger 2.0 schema or OpenAPI 3.0 Schema. It also performs additional validations against the specification, which will catch some things that aren't covered by the schema, such as duplicate parameters, invalid MIME types, etc.

The command will exit with a non-zero code if the API is invalid.

swagger-cli validate [options] <file>

Options:
    --no-schema             Do NOT validate against the Swagger/OpenAPI JSON schema

    --no-spec               Do NOT validate against the Swagger/OpenAPI specification

Git pre-commit hook

There is a useful Python tool called pre-commit that can be used to execute a wide suite of pre-commit checks. The swagger-cli validate command can be integrated as part of a git pre-commit hook by adding the following configuration to the repos entry of an existing .pre-commit-config.yaml file.

-   repo: https://github.com/APIDevTools/swagger-cli
    rev: v2.2.1
    hooks:
    - id: swagger-validation
      args: ["validate", "<path to root swagger>"]

The intention is to point to single root swagger that references multiple swagger definitions. The above hook will execute the swagger-cli validation against the root swagger anytime that a file matching the pattern .*swagger.*\.(json|yaml|yml) is modified. Any failures in this validation will prevent the git commit from being processed.

Combine Multiple Files

The Swagger and OpenAPI specs allows you to split your API definition across multiple files using $ref pointers to reference each file. You can use the swagger-cli bundle command to combine all of those referenced files into a single file, which is useful for distribution or interoperation with other tools.

By default, the swagger-cli bundle command tries to keep the output file size as small as possible, by only embedding each referenced file once. If the same file is referenced multiple times, then any subsequent references are simply modified to point to the single inlined copy of the file. If you want to produce a bundled file without any $ref pointers, then add the --dereference option. This will result in a larger file size, since multiple references to the same file will result in that file being embedded multiple times.

If you don't specify the --outfile option, then the bundled API will be written to stdout, which means you can pipe it to other commands.

The result of this method by default is written as JSON. It can be changed to YAML with the --type option, by passing the yaml value.

swagger-cli bundle [options] <file>

Options:
    -o, --outfile <file>        The output file

    -r, --dereference           Fully dereference all $ref pointers

    -f, --format <spaces>       Formats the output using the given number of spaces
                                (the default is 2 spaces)

    -t, --type <filetype>       Defines the output file type. The valid values are: json, yaml
                                (the default is JSON)

    -w, --wrap <column>         Set the line length for YAML strings
                                (the default is no wrapping)

Contributing

I welcome any contributions, enhancements, and bug-fixes. Open an issue on GitHub and submit a pull request.

Building/Testing

To build/test the project locally on your computer:

  1. Clone this repo
    git clone https://github.com/APIDevTools/swagger-cli.git

  2. Install dependencies
    npm install

  3. Run the tests
    npm test

License

Swagger CLI is 100% free and open-source, under the MIT license. Use it however you want.

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Big Thanks To

Thanks to these awesome companies for their support of Open Source developers ❤

Travis CI SauceLabs Coveralls

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].