Categorygithub.com/pb33f/libopenapi
modulepackage
0.18.2
Repository: https://github.com/pb33f/libopenapi.git
Documentation: pkg.go.dev

# README

libopenapi

libopenapi - enterprise grade OpenAPI tools for golang.

Pipeline GoReportCard codecov discord Docs

libopenapi has full support for Swagger (OpenAPI 2), OpenAPI 3, and OpenAPI 3.1. It can handle the largest and most complex specifications you can think of.


Sponsors & users

If your company is using libopenapi, please considering supporting this project, like our very kind sponsors:

speakeasy'

Speakeasy

scalar'

scalar


libopenapi is pretty new, so our list of notable projects that depend on libopenapi is small (let me know if you'd like to add your project)


Come chat with us

Need help? Have a question? Want to share your work? Join our discord and come say hi!

Check out the libopenapi-validator

Need to validate requests, responses, parameters or schemas? Use the new libopenapi-validator module.

Documentation

See all the documentation at https://pb33f.io/libopenapi/


Quick-start tutorial

šŸ‘€ Get rolling fast using libopenapi with the Parsing OpenAPI files using go guide šŸ‘€

Or, follow these steps and see something in a few seconds.

Step 1: Grab the petstore

curl https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.yaml > petstorev3.json

Step 2: Grab libopenapi

go get github.com/pb33f/libopenapi

Step 3: Parse the petstore using libopenapi

Copy 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, errors := document.BuildV3Model()
	if len(errors) > 0 {
		for i := range errors {
			fmt.Printf("error: %e\n", errors[i])
		}
		panic(fmt.Sprintf("cannot create v3 model from document: %d errors reported", len(errors)))
	}

	// The following fails after the first iteration
	for schemaPairs := docModel.Model.Components.Schemas.First(); schemaPairs != nil; schemaPairs = schemaPairs.Next() {
		schemaName := schemaPairs.Key()
		schema := schemaPairs.Value()
		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 properties

Read the full docs at https://pb33f.io/libopenapi/


Logo gopher is modified, originally from egonelbre

# Packages

No description provided by the author
Package datamodel contains two sets of models, high and low.
Package index contains an OpenAPI indexer that will very quickly scan through an OpenAPI specification (all versions) and extract references to all the important nodes you might want to look up, as well as counts on total objects.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package what_changed what changed is a feature that performs an accurate and deep analysis of what has changed between two OpenAPI documents.

# Functions

CompareDocuments will accept a left and right Document implementing struct, build a model for the correct version and then compare model documents for changes.
NewDocument will create a new OpenAPI instance from an OpenAPI specification []byte array.
NewDocumentWithConfiguration is the same as NewDocument, except it's a convenience function that calls NewDocument under the hood and then calls SetConfiguration() on the returned Document.
No description provided by the author

# Structs

DocumentModel represents either a Swagger document (version 2) or an OpenAPI document (version 3) that is built from a parent Document.

# Interfaces

Document Represents an OpenAPI specification that can then be rendered into a model or serialized back into a string document after being manipulated.