Skip to main content

OpenAPI specification tools for analyzing, updating, and generating a CLI.

Project description

openapi-spec-tools

Welcome to OpenAPI specification (OAS) tools!

This is a collection of tools for using OpenAPI specifications. The OpenAPI community has a plethora of tools, and this is intended to supplement those. The tools here provide functionality that has not been readily available elsewhere.

Getting started

The project has been published to PyPi, so you should be able to install it with something like one of the following (depending on how you do Python package management):

% pip install openapi-spec-tools
% poetry add openapi-spec-tools

Generally, there are two intended ways to utilize this package:

  • Use oas and cli-gen as CLI tools to perform actions
  • Use the code in the Python modules for your own purpose

The sections below provide a brief description with links to more examples and details.

OAS

The oas script provides a tool for analyzing and modifying an OpenAPI spec. See OAS.md for more info.

Here's a trivial example:

(.env) % oas analyze models list pet.yaml 
Found 3 models:
    Error
    Pet
    Pets
(.env) % oas analyze models ops pet.yaml Pet
Found Pet is used by 3 operations:
    createPets
    listPets
    showPetById
(.env) % 

CLI Generation

The cli-gen tool allows users to create a user-friendly CLI using the OpenAPI spec and a layout file. The layout file provides the CLI structure and refers to the OpenAPI spec for details of operations. LAYOUT.md has more details about the layout file, and the CLI_GEN.md has more info about CLI generation.

Turn a simple layout like:

main:
  description: Manage pets
  operations:
    - name: add
      operationId: createPets

Into code that produces a CLI that has commands like:

% pets add --help
                                                                                                                                                        
 Usage: pets add [OPTIONS]                                             

 Create a pet
 
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --id                 INTEGER                                                                                                                         │
│ --name               TEXT                                                                                                                            │
│ --tag                TEXT                                                                                                                            │
│ --owner              TEXT                                                                                                                            │
│ --api-host           TEXT                              API host address [env var: API_HOST]                                                          │
│ --api-key            TEXT                              API key for authentication [env var: API_KEY]                                                 │
│ --api-timeout        INTEGER                           API request timeout in seconds for a single request [env var: API_TIMEOUT] [default: 5]       │
│ --log                [critical|error|warn|info|debug]  Log level [env var: LOG_LEVEL] [default: warn]                                                │
│ --format             [table|json|yaml]                 Output format style [env var: OUTPUT_FORMAT] [default: table]                                 │
│ --style              [none|bold|all]                   Style for output [env var: OUTPUT_STYLE] [default: all]                                       │
│ --help                                                 Show this message and exit.                                                                   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
% 

See the examples in examples/ for some more complete works.

client.mk

The client.mk file is an example of a Makefile to invoke the OpenAPI generator via a container. The file can be copied/modified to be invoked with an OpenAPI specfication (other than openapi.yaml) and a real package name. For a more complete list of generator options, look at the OpenAPI generator usage documentation.

Contributing

The DEVELOPMENT.md has more information about getting setup as a developer.

The TODO.md has some ideas where this project can be improved and expanded -- please add your ideas here, or email Rick directly (rickwporter@gmail.com).

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

openapi_spec_tools-0.4.0.tar.gz (43.0 kB view details)

Uploaded Source

Built Distribution

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

openapi_spec_tools-0.4.0-py3-none-any.whl (50.5 kB view details)

Uploaded Python 3

File details

Details for the file openapi_spec_tools-0.4.0.tar.gz.

File metadata

  • Download URL: openapi_spec_tools-0.4.0.tar.gz
  • Upload date:
  • Size: 43.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for openapi_spec_tools-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c9cecf4b189e866e4aed3e7daeaaf5537099023739191a790d64f488d17f30d1
MD5 d0af75051a9a8d30cfc8c590026363c2
BLAKE2b-256 542339fe48c3d251d00c0ffbb4f59c9b8d2cb95f645f1349ea6c97e8522e03f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_spec_tools-0.4.0.tar.gz:

Publisher: pypi_publish.yaml on rickwporter/openapi-spec-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openapi_spec_tools-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_spec_tools-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ddd8a58c363f50e68b08152bbafc715a4740c586eb6f87dce83d3ab1e45f17c9
MD5 74f0369a5a33d3edf1cef3d495fcb4ca
BLAKE2b-256 1010bc74a460800684d9a5783b09d4487732cddc386807f9fe7bf4ca399ef09c

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_spec_tools-0.4.0-py3-none-any.whl:

Publisher: pypi_publish.yaml on rickwporter/openapi-spec-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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