https://github.com/markrosemaker/openapi
Tools for parsing, formatting, validating, and programmatically enhancing OpenAPI specifications in Go.
https://github.com/markrosemaker/openapi
api api-documentation api-management api-specification api-tools go json openapi swagger validation yaml
Last synced: 5 months ago
JSON representation
Tools for parsing, formatting, validating, and programmatically enhancing OpenAPI specifications in Go.
- Host: GitHub
- URL: https://github.com/markrosemaker/openapi
- Owner: MarkRosemaker
- License: apache-2.0
- Created: 2024-10-07T13:51:53.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-10T23:37:08.000Z (12 months ago)
- Last Synced: 2025-02-11T00:28:26.030Z (12 months ago)
- Topics: api, api-documentation, api-management, api-specification, api-tools, go, json, openapi, swagger, validation, yaml
- Language: Go
- Homepage:
- Size: 1.12 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: security_requirement.go
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/MarkRosemaker/openapi)
[](https://goreportcard.com/report/github.com/MarkRosemaker/openapi)

[](./LICENSE)
Transform and master your API specs with ease.
Package openapi provides a suite of tools for working with OpenAPI specifications, making it easier to parse, format, manipulate, and generate code from these specs.
Whether you're looking to clean up existing API documentation or integrate API design into your development pipeline, this package is built to streamline your workflow.
**This package is currently being utilized to format OpenAPI specifications in the [go-api-libs](https://github.com/go-api-libs) project.**
## Introduction
The primary goals of this package are:
- **Parsing** OpenAPI specifications into a structured format.
- **Formatting** the parsed specifications, including sorting maps and merging duplicate content.
- **Adding information programmatically** to the specifications.
- **Marshalling** the modified specifications back into their original format.
- **Utilizing** the parsed specification for code generation.
## Features
- **Comprehensive parsing** of OpenAPI specifications.
- **Flexible formatting** options to improve readability and consistency.
- **Ability to merge and deduplicate** content within specifications.
- **Programmatic modification** of specifications before marshalling.
- **Code generation capabilities** based on parsed specifications.
## Usage
```go
package main
import (
"fmt"
"github.com/MarkRosemaker/openapi"
)
func main() {
doc, err := openapi.LoadFromFile("path/to/openapi.json") // or openapi.yaml
if err != nil {
fmt.Println("Error parsing spec:", err)
return
}
if err := doc.Validate(); err != nil {
fmt.Println("Error validating spec:", err)
return
}
// sort keys of each component in alphabetical order
doc.Components.SortMaps()
// write an improved version of your spec
if err := doc.WriteToFile("path/to/openapi.json"); err != nil {
fmt.Println("Error writing to file:", err)
return
}
}
```
## Additional Information
- [**Go Reference**](https://pkg.go.dev/github.com/MarkRosemaker/openapi): The Go reference documentation for the errpath package.
- [**Go Report Card**](https://goreportcard.com/report/github.com/MarkRosemaker/openapi): Check the code quality report.
## Contributing
If you have any contributions to make, please submit a pull request or open an issue on the [GitHub repository](https://github.com/MarkRosemaker/openapi).
## License
This project is licensed under the [Apache 2.0 License](./LICENSE).