Skip to content

go-openapi-ui is an embedded OpenAPI/Swagger documentation ui for Go using OpenAPI-UI

License

Notifications You must be signed in to change notification settings

rookie-luochao/go-openapi-ui

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-openapi-ui

go-openapi-ui is an embedded OpenAPI documentation ui for Go using OpenAPI-UI and Go's 1.17+'s embed package, with middleware implementations for: net/http, gin, fiber, and echo.

The template is based on the OpenAPI-UI bundle.js with the script already placed in the html instead of depending on a CDN.

This package does not generate openapi spec file. Check this example for using code generation with swag.

Usage

import "github.com/openapi-ui/go-openapi-ui/pkg/doc"

...

doc := doc.Doc{
    Title:       "Example API",
    Description: "Example API Description",
    SpecFile:    "./openapi.json", // "./openapi.yaml"
    SpecPath:    "/openapi.json",  // "/openapi.yaml"
    DocsPath:    "/docs",
    Theme:       "light", // default is light, support light or dark
}
  • net/http
import (
	"net/http"
	"github.com/openapi-ui/go-openapi-ui/pkg/doc"
)

...

http.ListenAndServe(address, doc.Handler())
  • gin
import (
	"github.com/gin-gonic/gin"
	"github.com/openapi-ui/go-openapi-ui/pkg/doc"
	ginopenapiui "github.com/openapi-ui/go-openapi-ui/pkg/middleware/gin"
)

...

r := gin.New()
r.Use(ginopenapiui.New(doc))
  • echo
import (
	"github.com/labstack/echo/v4"
	"github.com/openapi-ui/go-openapi-ui/pkg/doc"
	echoopenapiui "github.com/openapi-ui/go-openapi-ui/pkg/middleware/echo"
)

...

r := echo.New()
r.Use(echoopenapiui.New(doc))
  • fiber
import (
	"github.com/gofiber/fiber/v2"
	"github.com/openapi-ui/go-openapi-ui/pkg/doc"
	fiberopenapiui "github.com/openapi-ui/go-openapi-ui/pkg/middleware/fiber"
)

...

r := fiber.New()
r.Use(fiberopenapiui.New(doc))

See examples

Thanks

LICENSE

MIT

About

go-openapi-ui is an embedded OpenAPI/Swagger documentation ui for Go using OpenAPI-UI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 86.9%
  • Makefile 7.8%
  • HTML 5.3%