soda

package module
v3.0.0-...-40c4ab3 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 19 Imported by: 0

README

codecov

Soda

soda := OpenAPI3 + fiber

[WIP] working on fiber/v3

Documentation

Index

Constants

View Source
const (
	KeyInput ck = "soda::input"
)

Variables

View Source
var (
	OpenAPITag        = "oai"
	SeparatorProp     = ";"
	SeparatorPropItem = ","
)
View Source
var (
	UISwaggerUI        = builtinUIRender{/* contains filtered or unexported fields */}
	UIRapiDoc          = builtinUIRender{/* contains filtered or unexported fields */}
	UIStoplightElement = builtinUIRender{/* contains filtered or unexported fields */}
	UIRedoc            = builtinUIRender{/* contains filtered or unexported fields */}
)

Functions

func GenerateSchemaRef

func GenerateSchemaRef(model any, nameTag string, name ...string) *openapi3.SchemaRef

GenerateSchemaRef generates an OpenAPI schema for a given model using the given name tag. It takes in the model to generate a schema for and a name tag to use for naming properties. It returns a *spec.Schema that represents the generated schema.

func GetInput

func GetInput[T any](c fiber.Ctx) *T

GetInput gets the input value from the http request.

func NewAPIKeySecurityScheme

func NewAPIKeySecurityScheme(in string, name string, description ...string) *openapi3.SecurityScheme

func NewJWTSecurityScheme

func NewJWTSecurityScheme(description ...string) *openapi3.SecurityScheme

Types

type Engine

type Engine struct {
	*Router
	// contains filtered or unexported fields
}

func New

func New() *Engine

func NewWith

func NewWith(app *fiber.App) *Engine

func (*Engine) App

func (e *Engine) App() *fiber.App

func (*Engine) OpenAPI

func (e *Engine) OpenAPI() *openapi3.T

func (*Engine) ServeDocUI

func (e *Engine) ServeDocUI(pattern string, ui UIRender) *Engine

func (*Engine) ServeSpecJSON

func (e *Engine) ServeSpecJSON(pattern string) *Engine

func (*Engine) ServeSpecYAML

func (e *Engine) ServeSpecYAML(pattern string) *Engine

type Generator

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

Generator Define the Generator struct.

func NewGenerator

func NewGenerator() *Generator

NewGenerator Create a new generator.

func (*Generator) GenerateParameters

func (g *Generator) GenerateParameters(model reflect.Type) openapi3.Parameters

GenerateParameters generates OpenAPI TestCase for a given model.

func (*Generator) GenerateRequestBody

func (g *Generator) GenerateRequestBody(operationID, nameTag string, model reflect.Type) *openapi3.RequestBody

GenerateRequestBody generates an OpenAPI request body for a given model using the given operation ID and name tag. It takes in the operation ID to use for naming the request body, the name tag to use for naming properties, and the model to generate a request body for. It returns a *spec.RequestBody that represents the generated request body.

func (*Generator) GenerateResponse

func (g *Generator) GenerateResponse(code int, model any, mt string, description string) *openapi3.Response

type HookAfterBind

type HookAfterBind func(ctx fiber.Ctx, input any) error

HookAfterBind is a function type that is called after binding the request. It returns a boolean indicating whether to continue the process.

type HookBeforeBind

type HookBeforeBind func(ctx fiber.Ctx) error

HookBeforeBind is a function type that is called before binding the request. It returns a boolean indicating whether to continue the process.

type OperationBuilder

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

OperationBuilder is a struct that helps in building an operation.

func (*OperationBuilder) AddJSONResponse

func (op *OperationBuilder) AddJSONResponse(code int, model any, description ...string) *OperationBuilder

AddJSONResponse adds a JSON response to the operation.

func (*OperationBuilder) AddSecurity

func (op *OperationBuilder) AddSecurity(securityName string, scheme *openapi3.SecurityScheme) *OperationBuilder

AddSecurity adds a security scheme to the operation.

func (*OperationBuilder) AddTags

func (op *OperationBuilder) AddTags(tags ...string) *OperationBuilder

AddTags adds tags to the operation.

func (*OperationBuilder) IgnoreAPIDoc

func (op *OperationBuilder) IgnoreAPIDoc(ignore bool) *OperationBuilder

SetIgnoreAPIDoc sets whether to ignore the operation when generating the API doc.

func (*OperationBuilder) OK

func (op *OperationBuilder) OK()

OK finalizes the operation building process.

func (*OperationBuilder) OnAfterBind

func (op *OperationBuilder) OnAfterBind(hook HookAfterBind) *OperationBuilder

OnAfterBind adds a hook that is called after binding the request.

func (*OperationBuilder) OnBeforeBind

func (op *OperationBuilder) OnBeforeBind(hook HookBeforeBind) *OperationBuilder

OnBeforeBind adds a hook that is called before binding the request.

func (*OperationBuilder) SetDeprecated

func (op *OperationBuilder) SetDeprecated(deprecated bool) *OperationBuilder

SetDeprecated marks the operation as deprecated or not.

func (*OperationBuilder) SetDescription

func (op *OperationBuilder) SetDescription(desc string) *OperationBuilder

SetDescription sets the description of the operation.

func (*OperationBuilder) SetInput

func (op *OperationBuilder) SetInput(input any) *OperationBuilder

SetInput sets the input type for the operation.

func (*OperationBuilder) SetOperationID

func (op *OperationBuilder) SetOperationID(id string) *OperationBuilder

SetOperationID sets the operation ID of the operation.

func (*OperationBuilder) SetSummary

func (op *OperationBuilder) SetSummary(summary string) *OperationBuilder

SetSummary sets the summary of the operation.

type Router

type Router struct {
	Raw fiber.Router
	// contains filtered or unexported fields
}

func (*Router) Add

func (r *Router) Add(method string, pattern string, handler fiber.Handler, middleware ...fiber.Handler) *OperationBuilder

func (*Router) AddJSONResponse

func (r *Router) AddJSONResponse(code int, model any, description ...string) *Router

func (*Router) AddSecurity

func (r *Router) AddSecurity(securityName string, scheme *openapi3.SecurityScheme) *Router

func (*Router) AddTags

func (r *Router) AddTags(tags ...string) *Router

func (*Router) Delete

func (r *Router) Delete(pattern string, handler fiber.Handler, middleware ...fiber.Handler) *OperationBuilder

func (*Router) Get

func (r *Router) Get(pattern string, handler fiber.Handler, middleware ...fiber.Handler) *OperationBuilder

func (*Router) Group

func (r *Router) Group(prefix string, handlers ...fiber.Handler) *Router

func (*Router) Head

func (r *Router) Head(pattern string, handler fiber.Handler, middleware ...fiber.Handler) *OperationBuilder

func (*Router) OnAfterBind

func (r *Router) OnAfterBind(hook HookAfterBind) *Router

func (*Router) OnBeforeBind

func (r *Router) OnBeforeBind(hook HookBeforeBind) *Router

func (*Router) Options

func (r *Router) Options(pattern string, handler fiber.Handler, middleware ...fiber.Handler) *OperationBuilder

func (*Router) Patch

func (r *Router) Patch(pattern string, handler fiber.Handler, middleware ...fiber.Handler) *OperationBuilder

func (*Router) Post

func (r *Router) Post(pattern string, handler fiber.Handler, middleware ...fiber.Handler) *OperationBuilder

func (*Router) Put

func (r *Router) Put(pattern string, handler fiber.Handler, middleware ...fiber.Handler) *OperationBuilder

func (*Router) SetDeprecated

func (r *Router) SetDeprecated(deprecated bool) *Router

func (*Router) SetIgnoreAPIDoc

func (r *Router) SetIgnoreAPIDoc(ignore bool) *Router

SetIgnoreAPIDoc implements Router.

func (*Router) Trace

func (r *Router) Trace(pattern string, handler fiber.Handler, middleware ...fiber.Handler) *OperationBuilder

type UIRender

type UIRender interface {
	Render(doc *openapi3.T) string
}

Jump to

Keyboard shortcuts

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