openapi
Parse, validate, and manipulate OpenAPI, Swagger, Arazzo, and OpenAPI Overlay documents
About openapi
Main Packages
arazzo
The arazzo package provides an API for working with Arazzo 1.0.x and 1.1.x documents including reading, creating, mutating, walking, validating, linting, upgrading and graphing them, and bootstrapping them from OpenAPI documents.
openapi
The openapi package provides an API for working with OpenAPI documents including reading, creating, mutating, walking, validating, upgrading, and linting them. Supports OpenAPI 3.0.x, 3.1.x, and 3.2.x specifications.
The openapi/linter subpackage provides a configurable linter with 60+ built-in rules covering style, security (OWASP), and semantic validation. Custom rules can be written in TypeScript/JavaScript using the @speakeasy-api/openapi-linter-types package.
swagger
The swagger package provides an API for working with Swagger 2.0 documents including reading, creating, mutating, walking, validating, and upgrading them to OpenAPI 3.0.
overlay
The overlay package provides an API for working with OpenAPI Overlays including applying overlays to specifications, comparing specifications to generate overlays, and validating overlay documents.
asyncapi
The asyncapi package provides an API for working with AsyncAPI 3.0.x and 3.1.x documents including reading, creating, mutating, walking and validating them, resolving references within and across documents, and applying operation and message traits.
CLI Tool
This repository also provides a comprehensive CLI tool for working with OpenAPI specifications, Arazzo workflows, AsyncAPI documents and OpenAPI overlays.
Installation
Homebrew (macOS/Linux):
brew install openapi
Go Install:
go install github.com/speakeasy-api/openapi/cmd/openapi@latest
Script Installation:
Linux/macOS:
curl -fsSL https://go.speakeasy.com/openapi.sh | bash
Windows (PowerShell):
iwr -useb https://go.speakeasy.com/openapi.ps1 | iex
For manual installation, upgrade instructions, custom installation options, and troubleshooting, see the detailed installation guide.
Usage
The CLI provides five main command groups:
-
openapi spec- Commands for working with OpenAPI specifications (documentation)bootstrap- Create a new OpenAPI document with best practice examplesbundle- Bundle external references into components sectionclean- Remove unused components and unused top-level tags from an OpenAPI specificationexplore- Interactively explore an OpenAPI specification in the terminalinline- Inline all references in an OpenAPI specificationjoin- Join multiple OpenAPI documents into a single documentlint- Lint an OpenAPI specification for semantic issues, style, security, and best practices, including referenced endpointslocalize- Localize an OpenAPI specification by copying external references to a target directoryoptimize- Optimize an OpenAPI specification by deduplicating inline schemassanitize- Remove unwanted elements from an OpenAPI specificationsnip- Remove or filter operations in an OpenAPI specification (interactive or CLI)upgrade- Upgrade an OpenAPI specification to the latest supported versionvalidate- Validate an OpenAPI specification documentquery- Query an OpenAPI specification using the oq pipeline language to answer structural and semantic questions about schemas and operationsquery-reference- Print the complete oq query language reference
-
openapi swagger- Commands for working with Swagger 2.0 documents (documentation)validate- Validate a Swagger 2.0 specification documentupgrade- Upgrade a Swagger 2.0 specification to OpenAPI 3.0
-
openapi arazzo- Commands for working with Arazzo workflow documents (documentation)validate- Validate an Arazzo workflow document, including against the OpenAPI, AsyncAPI and Arazzo documents it referencesupgrade- Upgrade an Arazzo workflow document to the latest supported version (1.1.0)lint- Lint an Arazzo workflow document for semantic issues, style and security concerns, with optional fixeslist-rules- List the available Arazzo lint rulesgraph- Render the workflows of an Arazzo document as a Mermaid or Graphviz DOT diagrambootstrap- Generate starter Arazzo workflows from an OpenAPI document, or create an example Arazzo documentexplore- Interactively explore the workflows of an Arazzo document
-
openapi asyncapi- Commands for working with AsyncAPI documents (documentation)validate- Validate an AsyncAPI 3.x document, optionally following references to other files and URLs
-
openapi overlay- Commands for working with OpenAPI overlays (documentation)apply- Apply an overlay to an OpenAPI specificationcompare- Compare two specifications and generate an overlay describing differencesvalidate- Validate an OpenAPI overlay document
Quick Examples
# Validate an OpenAPI specification
openapi spec validate ./spec.yaml
# Lint for semantic issues, style, security, and best practices
openapi spec lint ./spec.yaml
# Lint a multi-file specification directly, without bundling first
openapi spec lint ./split/openapi.yaml
# Include external findings' source files and coordinates in JSON output
openapi spec lint --format json ./split/openapi.yaml
# Lint with custom configuration
openapi spec lint --config lint.yaml ./spec.yaml
# Interactive lint fixing
openapi spec lint --fix-interactive ./spec.yaml
# Bundle external references into components section
openapi spec bundle ./spec.yaml ./bundled-spec.yaml
# Inline all references to create a self-contained document
openapi spec inline ./spec.yaml ./inlined-spec.yaml
# Upgrade OpenAPI spec to latest version
openapi spec upgrade ./spec.yaml ./upgraded-spec.yaml
# Apply an overlay to a specification
openapi overlay apply --overlay overlay.yaml --schema spec.yaml
# Validate an Arazzo workflow document and check it against its source descriptions
openapi arazzo validate ./workflow.arazzo.yaml
# Validate an Arazzo workflow document without loading its source descriptions
openapi arazzo validate --skip-sources ./workflow.arazzo.yaml
# Upgrade an Arazzo 1.0.x workflow document to 1.1.0
openapi arazzo upgrade -w ./workflow.arazzo.yaml
# Lint an Arazzo workflow document and apply the fixes that don't need input
openapi arazzo lint --fix ./workflow.arazzo.yaml
# Render the workflows of an Arazzo document as a Mermaid flowchart
openapi arazzo graph ./workflow.arazzo.yaml
# Generate starter Arazzo workflows from an OpenAPI document
openapi arazzo bootstrap --from ./openapi.yaml ./workflows.arazzo.yaml
# Interactively explore the workflows of an Arazzo document
openapi arazzo explore ./workflow.arazzo.yaml
# Validate an AsyncAPI document without reading anything outside it
openapi asyncapi validate ./asyncapi.yaml
# Validate an AsyncAPI document and the files and URLs it references, failing on warnings
openapi asyncapi validate --resolve --strict ./asyncapi.yaml
# Validate a Swagger 2.0 document
openapi swagger validate ./api.swagger.yaml
# Upgrade Swagger 2.0 to OpenAPI 3.0
openapi swagger upgrade ./api.swagger.yaml ./openapi.yaml
# Query schema graph — find deeply nested components
openapi spec query 'schemas | where(isComponent) | sort-by(depth, desc) | take(10) | select name, depth' ./spec.yaml
# Query schema graph — blast radius of a schema change
openapi spec query 'schemas | where(name == "Error") | blast-radius | length' ./spec.yaml
For detailed usage instructions for each command group, see the individual documentation linked above.
Sub Packages
This repository also contains a number of sub packages that are used by the main packages to provide the required functionality. The below packages may be moved into their own repository in the future, depending on future needs.
json
The json package provides utilities for converting between JSON and YAML.
jsonpointer
The jsonpointer package provides an API for working with RFC 6901 compliant JSON Pointers. Providing functionality for validating JSON Pointers, and extracting the target of a JSON Pointer for various Go types and structures.
jsonschema
The jsonschema package provides various models for working with the different JSON Schema dialects.
sequencedmap
The sequencedmap package provides a map implementation that maintains the order of keys as they are added.
Contributing
This repository is maintained by Speakeasy, but we welcome and encourage contributions from the community to help improve its capabilities and stability.
How to Contribute
-
Discussions: Have a feature request or want to discuss the roadmap? Use GitHub Discussions to share your ideas and engage with the community.
-
Issues: Found a bug or technical issue? Open a GitHub Issue to report it with details about the problem.
-
Pull Requests: We welcome pull requests! If you'd like to contribute code:
- Fork the repository
- Create a new branch for your feature/fix
- Submit a PR with a clear description of the changes and any related issues
-
Feedback: Share your experience using the packages or suggest improvements.
Getting Started: Look for items tagged with "good first issue" in both Discussions and Issues if you want to pick up something to work on.
All contributions, whether they're feature requests, bug reports, or code changes, help make this project better for everyone.
Please ensure your contributions adhere to our coding standards and include appropriate tests where applicable.
Frequently Asked Questions
What is openapi?
openapi is a Third-party APIs library for the Go programming language. Parse, validate, and manipulate OpenAPI, Swagger, Arazzo, and OpenAPI Overlay documents
How do I install openapi?
Install openapi with the Go module system using `go get speakeasy-api/openapi`. Check the repository for the current installation instructions.
What category does openapi belong to?
openapi is listed under Third-party APIs, specifically Third-party APIs.