openapi-cli-generator

command module
v0.0.0-...-5380d48 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 17 Imported by: 0

README

OpenAPI CLI Generator

GoDoc Go Report Card Platforms

openapi-to-cli

Note: this project has been modernized to Go 1.24 and refactored to generate self-contained CLI artifacts.


This project generates powerful, ready-to-use CLIs from OpenAPI 3 specifications. Unlike other generators, the resulting CLI is self-contained: all necessary support code (HTTP, auth, formatting) is bundled directly into your project's internal/ directory, removing any dependency on this generator library.

Features

  • Zero-Dependency Artifacts: Bundles all support code in internal/.
  • Automatic Documentation: Generates a comprehensive README.md for your new CLI.
  • Authentication: API keys and OAuth2 (including Auth0 and PKCE support).
  • Modern CLI Primitives: Powered by Cobra and Viper.
  • Flexible Input: stdin or CLI shorthand.
  • Advanced Filtering: Integrated JMESPath for response projection.
  • Pretty Output: Colored output via Chroma and structured logging via zerolog.

Getting Started

1. Install the Generator
$ GOPROXY=direct go install github.com/valknarthing/openapi-cli-generator@latest
2. Create Your CLI Project
# Set up your new project directory
$ mkdir my-api-cli && cd my-api-cli

# Initialize your Go module
$ go mod init my-api-cli

# Initialize the generator structure (bundles internal/ support code)
$ openapi-cli-generator init my-api-cli

# Generate the API commands and README.md
$ openapi-cli-generator generate openapi.yaml
3. Build and Install
# Fetch external dependencies
$ go mod tidy

# Build & install your new CLI
$ go install .

# Start using it!
$ my-api-cli --help

OpenAPI Extensions

Change the behavior of your generated CLI using these extensions:

Name Description
x-cli-aliases Sets up command aliases for operations.
x-cli-description Provide an alternate description for the CLI.
x-cli-ignore Ignore this path, operation, or parameter.
x-cli-hidden Hide this path, or operation.
x-cli-name Provide an alternate name for the CLI.
x-cli-waiters Generate commands/params to wait until a certain state is reached.

Customization

Since all support code is now in your internal/ folder, you have full control over the generated CLI. Your main.go is the entrypoint where you can:

  • Add custom global flags.
  • Register HTTP middleware.
  • Add pre-run/post-run logic.

See the generated README.md in your new project for specific details on how to use your new CLI.

Development

This project uses Go 1.24+ features like go:embed for asset management.

# Build the generator locally
$ go build -o openapi-cli-generator main.go

# Run tests
$ ./test.sh

License

MIT - See LICENSE for details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package apikey provides authentication profile support for APIs that require a pre-generated constant authenticationn key passed via a header, query parameter, or cookie value in each request.
Package apikey provides authentication profile support for APIs that require a pre-generated constant authenticationn key passed via a header, query parameter, or cookie value in each request.
j
Package oauth provides authentication profile support for APIs that require OAuth 2.0 auth.
Package oauth provides authentication profile support for APIs that require OAuth 2.0 auth.
Package shorthand provides a quick way to generate structured data via command line parameters.
Package shorthand provides a quick way to generate structured data via command line parameters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL