swagger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateExample

func GenerateExample(t interface{}) interface{}

GenerateExample generates an example from a struct

func GetTypeName

func GetTypeName(t interface{}) string

GetTypeName gets the type name for a Go type

func SwaggerUI

func SwaggerUI(spec *OpenAPISpec) fiber.Handler

Middleware for serving Swagger UI

Types

type Components

type Components struct {
	Schemas map[string]interface{} `json:"schemas,omitempty"`
}

Components holds reusable components

type Contact

type Contact struct {
	Name  string `json:"name,omitempty"`
	URL   string `json:"url,omitempty"`
	Email string `json:"email,omitempty"`
}

Contact information

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates OpenAPI specifications

func NewGenerator

func NewGenerator(title, version, description string) *Generator

NewGenerator creates a new Swagger generator

func (*Generator) AddRoute

func (g *Generator) AddRoute(route RouteInfo)

AddRoute adds a route to the specification

func (*Generator) AddServer

func (g *Generator) AddServer(url, description string)

AddServer adds a server to the specification

func (*Generator) AddTag

func (g *Generator) AddTag(name, description string)

AddTag adds a tag to the specification

func (*Generator) Generate

func (g *Generator) Generate() (*OpenAPISpec, error)

Generate generates the OpenAPI specification

func (*Generator) GenerateJSON

func (g *Generator) GenerateJSON() ([]byte, error)

GenerateJSON generates the OpenAPI specification as JSON

type Header struct {
	Description string      `json:"description,omitempty"`
	Schema      interface{} `json:"schema,omitempty"`
}

Header represents a header

type Info

type Info struct {
	Title       string   `json:"title"`
	Description string   `json:"description,omitempty"`
	Version     string   `json:"version"`
	Contact     *Contact `json:"contact,omitempty"`
	License     *License `json:"license,omitempty"`
}

Info contains metadata about the API

type License

type License struct {
	Name string `json:"name"`
	URL  string `json:"url,omitempty"`
}

License information

type MediaType

type MediaType struct {
	Schema interface{} `json:"schema,omitempty"`
}

MediaType represents a media type

type OpenAPISpec

type OpenAPISpec struct {
	OpenAPI    string              `json:"openapi"`
	Info       Info                `json:"info"`
	Servers    []Server            `json:"servers,omitempty"`
	Paths      map[string]PathItem `json:"paths"`
	Components Components          `json:"components,omitempty"`
	Tags       []Tag               `json:"tags,omitempty"`
}

OpenAPISpec represents the OpenAPI 3.0 specification

type Operation

type Operation struct {
	Tags        []string              `json:"tags,omitempty"`
	Summary     string                `json:"summary,omitempty"`
	Description string                `json:"description,omitempty"`
	OperationID string                `json:"operationId,omitempty"`
	Parameters  []Parameter           `json:"parameters,omitempty"`
	RequestBody *RequestBody          `json:"requestBody,omitempty"`
	Responses   map[string]Response   `json:"responses"`
	Security    []map[string][]string `json:"security,omitempty"`
}

Operation represents an API operation

type Parameter

type Parameter struct {
	Name        string      `json:"name"`
	In          string      `json:"in"`
	Description string      `json:"description,omitempty"`
	Required    bool        `json:"required,omitempty"`
	Schema      interface{} `json:"schema,omitempty"`
	Example     interface{} `json:"example,omitempty"`
}

Parameter represents a parameter

func HeaderParameter

func HeaderParameter(name, description string, required bool) Parameter

HeaderParameter creates a header parameter

func PathParameter

func PathParameter(name, description string, required bool) Parameter

PathParameter creates a path parameter

func QueryParameter

func QueryParameter(name, description string, required bool) Parameter

QueryParameter creates a query parameter

type PathItem

type PathItem struct {
	Get    *Operation `json:"get,omitempty"`
	Post   *Operation `json:"post,omitempty"`
	Put    *Operation `json:"put,omitempty"`
	Delete *Operation `json:"delete,omitempty"`
	Patch  *Operation `json:"patch,omitempty"`
}

PathItem represents a path in the API

type RequestBody

type RequestBody struct {
	Description string               `json:"description,omitempty"`
	Content     map[string]MediaType `json:"content"`
	Required    bool                 `json:"required,omitempty"`
}

RequestBody represents a request body

type Response

type Response struct {
	Description string               `json:"description"`
	Content     map[string]MediaType `json:"content,omitempty"`
	Headers     map[string]Header    `json:"headers,omitempty"`
}

Response represents a response

type RouteDecorator

type RouteDecorator func(route RouteInfo) RouteInfo

RouteDecorator is a function type for decorating routes

func WithDescription

func WithDescription(description string) RouteDecorator

WithDescription decorates a route with a description

func WithParameters

func WithParameters(parameters ...Parameter) RouteDecorator

WithParameters decorates a route with parameters

func WithSummary

func WithSummary(summary string) RouteDecorator

WithSummary decorates a route with a summary

func WithTags

func WithTags(tags ...string) RouteDecorator

WithTags decorates a route with tags

func WithValidation

func WithValidation(requestType, responseType interface{}) RouteDecorator

WithValidation decorates a route with validation information

type RouteInfo

type RouteInfo struct {
	Method       string
	Path         string
	Handler      string
	Summary      string
	Description  string
	Tags         []string
	RequestType  interface{}
	ResponseType interface{}
	Parameters   []Parameter
}

RouteInfo holds information about a route

type Server

type Server struct {
	URL         string `json:"url"`
	Description string `json:"description,omitempty"`
}

Server information

type SwaggerMiddleware

type SwaggerMiddleware struct {
	// contains filtered or unexported fields
}

SwaggerMiddleware handles automatic Swagger generation

func NewSwaggerMiddleware

func NewSwaggerMiddleware(generator *Generator, enabled bool) *SwaggerMiddleware

NewSwaggerMiddleware creates a new Swagger middleware

func (*SwaggerMiddleware) AutoRegister

func (sm *SwaggerMiddleware) AutoRegister(app *fiber.App)

AutoRegister automatically registers routes from Fiber app

func (*SwaggerMiddleware) RegisterGroup

func (sm *SwaggerMiddleware) RegisterGroup(prefix string, routes []RouteInfo)

RegisterGroup registers a group of routes

func (*SwaggerMiddleware) RegisterRoute

func (sm *SwaggerMiddleware) RegisterRoute(method, path string, decorators ...RouteDecorator)

RegisterRoute manually registers a route

func (*SwaggerMiddleware) RegisterRoutes

func (sm *SwaggerMiddleware) RegisterRoutes(app *fiber.App)

RegisterRoutes registers routes with Swagger

type Tag

type Tag struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

Tag represents a tag

Jump to

Keyboard shortcuts

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