Skip to main content

Validates that a .yaml or .json file conforms to the OpenAPI Specifications 3.x.

Project description

amati

amati is designed to validate that a file conforms to the OpenAPI Specification v3.x (OAS).

Name

"amati" means to observe in Malay, especially with attention to detail. It's also one of the plurals of beloved or favourite in Italian.

Usage

python amati/amati.py --help
usage: amati [-h] [-s SPEC] [--consistency-check] [-d DISCOVER] [--local] [--html-report]

Tests whether a OpenAPI specification is valid. Will look an openapi.json or openapi.yaml file in the directory that
amati is called from. If --discover is set will search the directory tree. If the specification does not follow the
naming recommendation the --spec switch should be used. Creates a file <filename>.errors.json alongside the original
specification containing a JSON representation of all the errors.

options:
  -h, --help            show this help message and exit
  -s, --spec SPEC       The specification to be parsed
  --consistency-check   Runs a consistency check between the input specification and the parsed specification
  -d, --discover DISCOVER
                        Searches the specified directory tree for openapi.yaml or openapi.json.
  --local               Store errors local to the caller in a file called <file-name>.errors.json; a .amati/ directory
                        will be created.
  --html-report         Creates an HTML report of the errors, called <file-name>.errors.html, alongside the original
                        file or in a .amati/ directory if the --local switch is used

Docker

A Dockerfile is available on DockerHub or docker pull benale/amati:alpha.

Whilst an alpha build only the image tagged alpha will be maintained. If there are breaking API changes these will be detailed in releases going forward. Releases can be separately watched using the custom option when watching this repository.

To run against a specific specification the location of the specification needs to be mounted in the container.

docker run -v "<path-to-specification>:/<mount-name> benale/amati:alpha <options>

e.g. where you have a specification located in /Users/myuser/myrepo/myspec.yaml and create a mount /data:

docker run -v /Users/myuser/myrepo:/data benale/amati:alpha --spec /data/myspec.yaml --html-report

PyPI

amati is available on PyPI, to run everything:

>>> from amati import amati
>>> check = amati.run('tests/data/openapi.yaml', consistency_check=True, local=True, html_report=True)
>>> check
True

Architecture

amati uses Pydantic, especially the validation, and Typing to construct the entire OAS as a single data type. Passing a dictionary to the top-level data type runs all the validation in the Pydantic models constructing a single set of inherited classes and datatypes that validate that the API specification is accurate. To the extent that Pydantic is functional, amati has a functional core and an imperative shell.

Where the specification conforms, but relies on implementation-defined behavior (e.g. data type formats), a warning will be raised.

Contributing

Prerequisites

Starting

The project uses a pyproject.toml file to determine what to build.

To get started run:

sh bin/startup.sh

Testing and formatting

This project uses:

  • Pytest as a testing framework
  • Pyright on strict mode for type checking
  • Ruff as a linter and formatter
  • Hypothesis for test data generation
  • Coverage on both the tests and code for test coverage

It's expected that there are no errors and 100% of the code is reached and executed. The strategy for test coverage is based on parsing test specifications and not unit tests. amati runs tests on the external specifications, detailed in tests/data/.amati.tests.yaml. To be able to run these tests the GitHub repos containing the specifications need to be available locally. Specific revisions of the repos can be downloaded by running the following, which will clone the repos into ../amati-tests-specs/<repo-name>.

python scripts/tests/setup_test_specs.py

If there are some issues with the specification a JSON file detailing those should be placed into tests/data/ and the name of that file noted in tests/data/.amati.tests.yaml for the test suite to pick it up and check that the errors are expected. Any specifications that close the coverage gap are gratefully received.

To run everything, from linting, type checking to downloading test specs and building and testing the Docker image run:

sh bin/checks.sh

Docker

A Dockerfile is provided, to build:

docker build -t amati -f Dockerfile .

to run against a specific specification the location of the specification needs to be mounted in the container.

docker run -v "<path-to-specification>:/<mount-name> amati <options>

This can be tested against a provided specification, from the root directory

docker run --detach -v "$(pwd):/data" amati <options>

Data

There are some scripts to create the data needed by the project, for example, all the registered TLDs. To refresh the data, run the contents of /scripts/data.

OpenSSF Scorecard

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amati-0.2.15.tar.gz (152.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

amati-0.2.15-py3-none-any.whl (110.5 kB view details)

Uploaded Python 3

File details

Details for the file amati-0.2.15.tar.gz.

File metadata

  • Download URL: amati-0.2.15.tar.gz
  • Upload date:
  • Size: 152.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.22

File hashes

Hashes for amati-0.2.15.tar.gz
Algorithm Hash digest
SHA256 9230cda4c7456ae74af8a2ea85a430b9a83b0cc5698bf443c0737690ff0fd96f
MD5 912ec673de26660fc7650411dc78dfe0
BLAKE2b-256 97d04847016da407220d29752e4399786391eace2c8ba98be0e1e0ef19ca8166

See more details on using hashes here.

File details

Details for the file amati-0.2.15-py3-none-any.whl.

File metadata

  • Download URL: amati-0.2.15-py3-none-any.whl
  • Upload date:
  • Size: 110.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.22

File hashes

Hashes for amati-0.2.15-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca36939aa9846699e9f3e84fb2c9aebb80945d7a82b282699a3fa9bb6e7fd94
MD5 a08ef83dd438dbe985c1af2dbbf01815
BLAKE2b-256 89877526d22a6211e728037bc2e8f0d12aec8c0cb32b105c0652bff65a5649d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page