iriswagui

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 7 Imported by: 0

README

iriswagui

This package allows the user to easily add a Swagger UI to an Iris application. It does so by embedding the Swagger UI assets and adding a party to a parent party that implements all the necessary endpoints.

Basic usage example:

package main

import (
	"flag"
	"log"

	"github.com/alchemy/iriswagui"
	"github.com/kataras/iris/v12"
)

func main() {
	specPath := flag.String("spec", "data/swagger.json", "specification file `path`")
	addr := flag.String("addr", "127.0.0.1:8888", "listening address `host:port`")

	app := iris.New()
	party := app.Party("/documentation")

	config := iriswagui.Config{
		SpecRefs: []iriswagui.SwaggerSpecRef{
			{Name: "MyAPI", URL: *specPath},
		},
	}
    // Swagger UI will be served from /documentation/swagger
	err := iriswagui.HandleSwaggerUI(party, "/swagger", config)
	if err != nil {
		log.Fatalln(err)
	}

	err = app.Listen(*addr)
	if err != nil {
		log.Fatalln(err)
	}
}

Swagger UI configuration

Swagger UI is highly customizable. This package Config struct offers only minimal configuration optios.
For instance is accepts only a list of specification files and wether to use deep linking or not.
If only one specification file is added, Swagger UI will be configured to use BasicLayout, otherwise StandaloneLayout will be used along with the SwaggerUIBundle.plugins.Topbar plugin.
However a complete custom configration can be specified by using the ExternalConfigURL field og the Config struct. When this field is not empty the configuration object will be fetched from this URL, ignoring all other fields.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleSwaggerUI

func HandleSwaggerUI(party iris.Party, relativePath string, config Config) error

HandleSwaggerUI adds a new sub-party to party with all the necessary endpoints to serve the Swagger UI based on config.

Types

type Config

type Config struct {
	// ExternalConfigURL is the URL of an external configuration JavaScript object.
	// If it is non empty the UI configuration will be base on this object only, all
	// other parameters will be ingored.
	ExternalConfigURL string
	// SpecRefs is a list of API specifications [SwaggerSpecRef].
	// If only one SpecRef is present Swagger UI will be configured with the BasicLayout,
	// otherwise with the StandaloneLayout and the SwaggerUIBundle.plugins.Topbar plugin.
	SpecRefs []SwaggerSpecRef
	// DeepLinking will determine the value of the corresponfing parameter
	// of the Swagger UI configuration.
	DeepLinking bool
}

Config represents a (minimal) swagger UI configuration.

type SwaggerSpecRef

type SwaggerSpecRef struct {
	Name string
	URL  string
}

SwaggerSpecRef represents a single swagger specification file. The URL field can be and absolute URL or a local path. In the letter case a route to serve that file will be added to the Swagger UI party.

Jump to

Keyboard shortcuts

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