# openapi-spec-validator

OpenAPI Spec Validator is a CLI, pre-commit hook and python package that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 and OpenAPI 3.1 specification. The validator aims to check for full compliance with the Specification.

## Installation

### Pip + PyPI (recommended)

>     pip install openapi-spec-validator

### Pip + the source

>     pip install -e git+https://github.com/python-openapi/openapi-spec-validator.git#egg=openapi_spec_validator

## Usage

### CLI (Command Line Interface)

- Executable

  > Straight forward way:

  >     openapi-spec-validator openapi.yaml

  > pipes way:

  >     cat openapi.yaml | openapi-spec-validator -

- Docker

  >     docker run -v path/to/openapi.yaml:/openapi.yaml --rm pythonopenapi/openapi-spec-validator /openapi.yaml

- Python interpreter

  >     python -m openapi_spec_validator openapi.yaml

Read more about the CLI (Command Line Interface).

### pre-commit hook

>     repos:
>     -   repo: https://github.com/python-openapi/openapi-spec-validator
>         rev: 0.5.5 # The version to use or 'master' for latest
>         hooks:
>         -   id: openapi-spec-validator

Read more about the pre-commit hook.

### Python package

>     from openapi_spec_validator import validate_spec
>     from openapi_spec_validator.readers import read_from_filename

>     spec_dict, base_uri = read_from_filename('openapi.yaml')

>     # If no exception is raised by validate_spec(), the spec is valid.
>     validate_spec(spec_dict)

>     validate_spec({'openapi': '3.1.0'})

>     Traceback (most recent call last):
>        ...
>     OpenAPIValidationError: 'info' is a required property

Read more about the Python package.

## Related projects

- openapi-core

    Python library that adds client-side and server-side support for the OpenAPI v3.0 and OpenAPI v3.1 specification.

- openapi-schema-validator

    Python library that validates schema against the OpenAPI Schema Specification v3.0 and OpenAPI Schema Specification v3.1.

## License

Copyright (c) 2017-2023, Artur Maciag, All rights reserved. Apache v2