libopenapi has full support for OpenAPI 3, 3.1 and 3.2. It can handle the largest and most complex specifications you can think of.
If your company is using libopenapi, please considering supporting this project, like our very kind sponsors:
libopenapi is kinda new, so our list of notable projects that depend on libopenapi is small (let me know if you'd like to add your project)
- github.com/daveshanley/vacuum - "The world's fastest and most scalable OpenAPI/Swagger linter/quality tool"
- github.com/pb33f/openapi-changes - "The world's sexiest OpenAPI breaking changes detector"
- github.com/pb33f/wiretap - "The world's coolest OpenAPI compliance analysis tool"
- github.com/danielgtaylor/restish - "Restish is a CLI for interacting with REST-ish HTTP APIs"
- github.com/speakeasy-api/speakeasy - "Speakeasy CLI makes validating OpenAPI docs and generating idiomatic SDKs easy!"
- github.com/apicat/apicat - "AI-powered API development tool"
- github.com/mattermost/mattermost - "Software development lifecycle platform"
- github.com/gopher-fleece/gleece - "Building and documenting REST APIs through code-first development"
- Your project here?
Need help? Have a question? Want to share your work? Join our discord and come say hi!
Need to validate requests, responses, parameters or schemas? Use the new libopenapi-validator module.
See all the documentation at https://pb33f.io/libopenapi/
- Installing libopenapi
- Using OpenAPI
- Using Swagger
- The Data Model
- Validation
- Modifying / Mutating the OpenAPI Model
- Mocking / Creating Examples
- Using Vendor Extensions
- The Index
- The Resolver
- The Rolodex
- Circular References
- Bundling Specs
- What Changed / Diff Engine
- FAQ
- About libopenapi
π Get rolling fast using libopenapi with the Parsing OpenAPI files using go guide π
Or, follow these steps and see something in a few seconds.
curl https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/_archive_/schemas/v3.0/pass/petstore.yaml > petstorev3.jsongo get github.com/pb33f/libopenapiCopy and paste this code into a main.go file.
package main import ( "fmt" "os" "github.com/pb33f/libopenapi" ) func main() { petstore, _ := os.ReadFile("petstorev3.json") document, err := libopenapi.NewDocument(petstore) if err != nil { panic(fmt.Sprintf("cannot create new document: %e", err)) } docModel, err := document.BuildV3Model() if err != nil { panic(fmt.Sprintf("cannot create v3 model from document: %e", err)) } // The following fails after the first iteration for schemaName, schema := range docModel.Model.Components.Schemas.FromOldest() { if schema.Schema().Properties != nil { fmt.Printf("Schema '%s' has %d properties\n", schemaName, schema.Schema().Properties.Len()) } } }Run it, which should print out:
Schema 'Pet' has 3 properties Schema 'Error' has 2 propertiesRead the full docs at https://pb33f.io/libopenapi/
Logo gopher is modified, originally from egonelbre
