elements

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(doc *openapi3.T, err error) (http.HandlerFunc, error)

NewHandler creates a new http.HandlerFunc that produces an HTML-producing route, which uses Stoplight Elements' OpenAPI viewer for a given OpenAPI specification. Returns an error if the OpenAPI was invalid, or any errors are returned when trying to prepare the handler

Example
rawSpec := `
openapi: 3.1.0
info:
  version: 1.0.0
  title: Example OpenAPI spec
paths: {}
`

loader := openapi3.NewLoader()
doc, err := loader.LoadFromData([]byte(rawSpec))

handler, err := NewHandler(doc, err)
if err != nil {
	panic(err)
}

http.Handle("/docs", handler)

// then we'd usually strart the server, i.e:
// log.Fatal(http.ListenAndServe(":8080", nil))

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL