Documentation
¶
Overview ¶
Package openapi builder provides a simple package for building an Open Api Spec document following the version 3.0. This package uses the builder pattern to create each route of an api.
Index ¶
- Variables
- func FormatRoutePath(endpoint string) string
- func Merge[T any](base T, override T) T
- func TypeToSwagger(kind reflect.Kind) string
- type Body
- type Builder
- func (this *Builder) Add(route *RouteBuilder)
- func (this *Builder) AddRoute(payload RoutePayload) *Builder
- func (this *Builder) Build() *Document
- func (this Builder) CreateBody(body any) Body
- func (this *Builder) CreateParameters(payload RoutePayload) []Parameter
- func (this Builder) CreateResponse(responses map[string]any) map[string]Response
- func (this *Builder) Route(method string, path string, opt ...Options) *RouteBuilder
- type Document
- type Info
- type Items
- type MediaTypeObject
- type OpenapiComponent
- type Options
- type Parameter
- type Path
- type Response
- type Route
- type RouteBuilder
- func (this *RouteBuilder) AddBody(payload any, options ...Options) *RouteBuilder
- func (this *RouteBuilder) AddHeaderParam(name string, typename string, options ...Options) *RouteBuilder
- func (this *RouteBuilder) AddHeaderParams(payload any, options ...Options) *RouteBuilder
- func (this *RouteBuilder) AddPathParam(name string, typename string, options ...Options) *RouteBuilder
- func (this *RouteBuilder) AddPathParams(payload any) *RouteBuilder
- func (this *RouteBuilder) AddQueryParam(name string, typename string, options ...Options) *RouteBuilder
- func (this *RouteBuilder) AddQueryParams(payload any) *RouteBuilder
- func (this *RouteBuilder) AddResponse(statusCode int, payload any, options ...Options) *RouteBuilder
- func (this *RouteBuilder) AddTag(tag ...string) *RouteBuilder
- func (this *RouteBuilder) Build() map[string]map[string]Path
- type RoutePayload
- type Schema
- type WriteOptions
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func FormatRoutePath ¶
func TypeToSwagger ¶
Types ¶
type Body ¶
type Body struct {
Description string `json:"description"`
Required bool `json:"required"`
Content map[string]MediaTypeObject `json:"content,omitempty"`
MediaType string `json:"-"`
}
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func (*Builder) Add ¶
func (this *Builder) Add(route *RouteBuilder)
func (*Builder) AddRoute ¶
func (this *Builder) AddRoute(payload RoutePayload) *Builder
func (Builder) CreateBody ¶
func (*Builder) CreateParameters ¶
func (this *Builder) CreateParameters(payload RoutePayload) []Parameter
func (Builder) CreateResponse ¶
type Document ¶
type Document struct {
Openapi string `json:"openapi"`
Info Info `json:"info"`
Components map[string]OpenapiComponent `json:"components,omitempty"`
Paths map[string]map[string]Path `json:"paths,omitempty"`
}
func (*Document) Write ¶
func (this *Document) Write(options ...WriteOptions) error
type Items ¶
type MediaTypeObject ¶
type MediaTypeObject struct {
Schema Schema `json:"schema,omitempty"`
}
type OpenapiComponent ¶
type OpenapiComponent struct {
}
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"`
Schema Schema `json:"schema"`
Required bool `json:"required"`
Description string `json:"description"`
}
func TypeToParam ¶
TypeToParam converte cada campo exportado e serializável de um struct em um Parameter. O `In` fica vazio aqui — quem chama é que decide se é path, query ou header.
type Response ¶
type Response struct {
Description string `json:"description"`
// key string is the media type - in this moment only application/json
Content map[string]MediaTypeObject `json:"content"`
}
type Route ¶
type Route = RoutePayload
type RouteBuilder ¶
type RouteBuilder struct {
// contains filtered or unexported fields
}
func NewRouteBuilder ¶
func NewRouteBuilder(path string, method string, options ...Options) *RouteBuilder
func (*RouteBuilder) AddBody ¶
func (this *RouteBuilder) AddBody(payload any, options ...Options) *RouteBuilder
func (*RouteBuilder) AddHeaderParam ¶ added in v0.2.0
func (this *RouteBuilder) AddHeaderParam(name string, typename string, options ...Options) *RouteBuilder
func (*RouteBuilder) AddHeaderParams ¶ added in v0.2.0
func (this *RouteBuilder) AddHeaderParams(payload any, options ...Options) *RouteBuilder
func (*RouteBuilder) AddPathParam ¶
func (this *RouteBuilder) AddPathParam(name string, typename string, options ...Options) *RouteBuilder
func (*RouteBuilder) AddPathParams ¶
func (this *RouteBuilder) AddPathParams(payload any) *RouteBuilder
func (*RouteBuilder) AddQueryParam ¶
func (this *RouteBuilder) AddQueryParam(name string, typename string, options ...Options) *RouteBuilder
func (*RouteBuilder) AddQueryParams ¶
func (this *RouteBuilder) AddQueryParams(payload any) *RouteBuilder
func (*RouteBuilder) AddResponse ¶
func (this *RouteBuilder) AddResponse(statusCode int, payload any, options ...Options) *RouteBuilder
func (*RouteBuilder) AddTag ¶
func (this *RouteBuilder) AddTag(tag ...string) *RouteBuilder
type RoutePayload ¶
type RoutePayload struct {
Method string `json:"method"`
Path string `json:"path"`
Tags []string `json:"tags"`
Summary string `json:"summary"`
Description string `json:"description"`
Parameter any
Query any
Header any
Body any
// String is the response status
// The format of the response will always be application/json
Responses map[string]any
}
type Schema ¶
type Schema struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Items Items `json:"items,omitzero,omitempty"`
Properties map[string]Schema `json:"properties,omitempty"`
Ref string `json:"$ref,omitempty"`
}
func TypeToSchema ¶
TypeToSchema converte um tipo Go no Schema OpenAPI equivalente, recompondo structs, slices, arrays e ponteiros recursivamente.
type WriteOptions ¶
Click to show internal directories.
Click to hide internal directories.