Versions in this module Expand all Collapse all v0 v0.1.1 Apr 5, 2024 v0.1.0 Apr 5, 2024 Changes in this version + const TypeArray + const TypeBoolean + const TypeInteger + const TypeNumber + const TypeObject + const TypeString + var DefaultCBORFormat = Format + var DefaultJSONFormat = Format + var ErrSchemaInvalid = errors.New("schema is invalid") + var ErrUnknownContentType = errors.New("unknown content type") + var GenerateOperationID = func(method, path string, response any) string + var GenerateSummary = func(method, path string, response any) string + var NewError = func(status int, msg string, errs ...error) StatusError + func AutoRegister(api API, server any) + func DefaultSchemaNamer(t reflect.Type, hint string) string + func Delete[I, O any](api API, path string, handler func(gin.Context, *I) (*O, error)) + func Get[I, O any](api API, path string, handler func(gin.Context, *I) (*O, error)) + func Patch[I, O any](api API, path string, handler func(gin.Context, *I) (*O, error)) + func Post[I, O any](api API, path string, handler func(gin.Context, *I) (*O, error)) + func Put[I, O any](api API, path string, handler func(gin.Context, *I) (*O, error)) + func ReadCookie(ctx Context, name string) (*http.Cookie, error) + func ReadCookies(ctx Context) []*http.Cookie + func Register[I, O any](api API, op Operation, handler func(gin.Context, *I) (*O, error)) + func SetReadDeadline(w http.ResponseWriter, deadline time.Time) error + func Validate(r Registry, s *Schema, path *PathBuffer, mode ValidateMode, v any, ...) + func WithOptions[Options any](f func(cmd *cobra.Command, args []string, options *Options)) func(*cobra.Command, []string) + func WriteErr(api API, ctx Context, status int, msg string, errs ...error) error + type API interface + Adapter func() Adapter + Marshal func(w io.Writer, contentType string, v any) error + Middlewares func() Middlewares + Negotiate func(accept string) (string, error) + OpenAPI func() *OpenAPI + Transform func(ctx Context, status string, v any) (any, error) + Unmarshal func(contentType string, data []byte, v any) error + UseMiddleware func(middlewares ...func(ctx Context, next func(Context))) + func NewAPI(config Config, a Adapter) API + type Adapter interface + Handle func(op *Operation, handler func(ctx Context)) + ServeHTTP func(http.ResponseWriter, *http.Request) + type AddOpFunc func(oapi *OpenAPI, op *Operation) + type AutoConfig struct + Headers map[string]string + Params map[string]string + Prompt map[string]AutoConfigVar + Security string + type AutoConfigVar struct + Default interface{} + Description string + Enum []interface{} + Example string + Exclude bool + type CLI = humacli.CLI + func NewCLI[O any](onParsed func(Hooks, *O)) CLI + type Components struct + Callbacks map[string]*PathItem + Examples map[string]*Example + Extensions map[string]any + Headers map[string]*Header + Links map[string]*Link + Parameters map[string]*Param + PathItems map[string]*PathItem + RequestBodies map[string]*RequestBody + Responses map[string]*Response + Schemas Registry + SecuritySchemes map[string]*SecurityScheme + func (c *Components) MarshalJSON() ([]byte, error) + type Config struct + CreateHooks []func(Config) Config + DefaultFormat string + DocsPath string + Formats map[string]Format + OpenAPIPath string + SchemasPath string + Transformers []Transformer + func DefaultConfig(title, version string) Config + type Contact struct + Email string + Extensions map[string]any + Name string + URL string + func (c *Contact) MarshalJSON() ([]byte, error) + type ContentTypeFilter interface + ContentType func(string) string + type Context interface + AppendHeader func(name, value string) + BodyReader func() io.Reader + BodyWriter func() io.Writer + Context func() *gin.Context + EachHeader func(cb func(name, value string)) + GetMultipartForm func() (*multipart.Form, error) + Header func(name string) string + Host func() string + Method func() string + Operation func() *Operation + Param func(name string) string + Query func(name string) string + SetHeader func(name, value string) + SetReadDeadline func(time.Time) error + SetStatus func(code int) + URL func() url.URL + func WithContext(ctx Context, override *gin.Context) Context + func WithValue(ctx Context, key string, value any) Context + type Encoding struct + AllowReserved bool + ContentType string + Explode *bool + Extensions map[string]any + Headers map[string]*Header + Style string + func (e *Encoding) MarshalJSON() ([]byte, error) + type ErrorDetail struct + Location string + Message string + Value any + func (e *ErrorDetail) Error() string + func (e *ErrorDetail) ErrorDetail() *ErrorDetail + type ErrorDetailer interface + ErrorDetail func() *ErrorDetail + type ErrorModel struct + Detail string + Errors []*ErrorDetail + Instance string + Status int + Title string + Type string + func (e *ErrorModel) Add(err error) + func (e *ErrorModel) ContentType(ct string) string + func (e *ErrorModel) Error() string + func (e *ErrorModel) GetStatus() int + type Example struct + Description string + Extensions map[string]any + ExternalValue string + Ref string + Summary string + Value any + func (e *Example) MarshalJSON() ([]byte, error) + type ExternalDocs struct + Description string + Extensions map[string]any + URL string + func (e *ExternalDocs) MarshalJSON() ([]byte, error) + type Format struct + Marshal func(writer io.Writer, v any) error + Unmarshal func(data []byte, v any) error + type Header = Param + type Hooks = humacli.Hooks + type Info struct + Contact *Contact + Description string + Extensions map[string]any + License *License + TermsOfService string + Title string + Version string + func (i *Info) MarshalJSON() ([]byte, error) + type License struct + Extensions map[string]any + Identifier string + Name string + URL string + func (l *License) MarshalJSON() ([]byte, error) + type Link struct + Description string + Extensions map[string]any + OperationID string + OperationRef string + Parameters map[string]any + Ref string + RequestBody any + Server *Server + func (l *Link) MarshalJSON() ([]byte, error) + type MediaType struct + Encoding map[string]*Encoding + Example any + Examples map[string]*Example + Extensions map[string]any + Schema *Schema + func (m *MediaType) MarshalJSON() ([]byte, error) + type Middlewares []func(ctx Context, next func(Context)) + func (m Middlewares) Handler(endpoint func(Context)) func(Context) + type ModelValidator struct + func NewModelValidator() *ModelValidator + func (v *ModelValidator) Validate(typ reflect.Type, value any) []error + type OAuthFlow struct + AuthorizationURL string + Extensions map[string]any + RefreshURL string + Scopes map[string]string + TokenURL string + func (o *OAuthFlow) MarshalJSON() ([]byte, error) + type OAuthFlows struct + AuthorizationCode *OAuthFlow + ClientCredentials *OAuthFlow + Extensions map[string]any + Implicit *OAuthFlow + Password *OAuthFlow + func (o *OAuthFlows) MarshalJSON() ([]byte, error) + type OpenAPI struct + Components *Components + Extensions map[string]any + ExternalDocs *ExternalDocs + Info *Info + JSONSchemaDialect string + OnAddOperation []AddOpFunc + OpenAPI string + Paths map[string]*PathItem + Security []map[string][]string + Servers []*Server + Tags []*Tag + Webhooks map[string]*PathItem + func (o *OpenAPI) AddOperation(op *Operation) + func (o *OpenAPI) MarshalJSON() ([]byte, error) + func (o *OpenAPI) YAML() ([]byte, error) + type Operation struct + BodyReadTimeout time.Duration + Callbacks map[string]*PathItem + DefaultStatus int + Deprecated bool + Description string + Errors []int + Extensions map[string]any + ExternalDocs *ExternalDocs + Hidden bool + MaxBodyBytes int64 + Metadata map[string]any + Method string + OperationID string + Parameters []*Param + Path string + RequestBody *RequestBody + Responses map[string]*Response + Security []map[string][]string + Servers []*Server + SkipValidateBody bool + SkipValidateParams bool + Summary string + Tags []string + func (o *Operation) MarshalJSON() ([]byte, error) + type Param struct + AllowEmptyValue bool + AllowReserved bool + Deprecated bool + Description string + Example any + Examples map[string]*Example + Explode *bool + Extensions map[string]any + In string + Name string + Ref string + Required bool + Schema *Schema + Style string + func (p *Param) MarshalJSON() ([]byte, error) + type PathBuffer struct + func NewPathBuffer(buf []byte, offset int) *PathBuffer + func (b *PathBuffer) Bytes() []byte + func (b *PathBuffer) Len() int + func (b *PathBuffer) Pop() + func (b *PathBuffer) Push(s string) + func (b *PathBuffer) PushIndex(i int) + func (b *PathBuffer) Reset() + func (b *PathBuffer) String() string + func (b *PathBuffer) With(s string) string + type PathItem struct + Delete *Operation + Description string + Extensions map[string]any + Get *Operation + Head *Operation + Options *Operation + Parameters []*Param + Patch *Operation + Post *Operation + Put *Operation + Ref string + Servers []*Server + Summary string + Trace *Operation + func (p *PathItem) MarshalJSON() ([]byte, error) + type Registry interface + Map func() map[string]*Schema + RegisterTypeAlias func(t reflect.Type, alias reflect.Type) + Schema func(t reflect.Type, allowRef bool, hint string) *Schema + SchemaFromRef func(ref string) *Schema + TypeFromRef func(ref string) reflect.Type + func NewMapRegistry(prefix string, namer func(t reflect.Type, hint string) string) Registry + type RequestBody struct + Content map[string]*MediaType + Description string + Extensions map[string]any + Ref string + Required bool + func (r *RequestBody) MarshalJSON() ([]byte, error) + type Resolver interface + Resolve func(ctx Context) []error + type ResolverWithPath interface + Resolve func(ctx Context, prefix *PathBuffer) []error + type Response struct + Content map[string]*MediaType + Description string + Extensions map[string]any + Headers map[string]*Param + Links map[string]*Link + Ref string + func (r *Response) MarshalJSON() ([]byte, error) + type Schema struct + AdditionalProperties any + AllOf []*Schema + AnyOf []*Schema + ContentEncoding string + Default any + DependentRequired map[string][]string + Deprecated bool + Description string + Enum []any + Examples []any + ExclusiveMaximum *float64 + ExclusiveMinimum *float64 + Extensions map[string]any + Format string + Items *Schema + MaxItems *int + MaxLength *int + MaxProperties *int + Maximum *float64 + MinItems *int + MinLength *int + MinProperties *int + Minimum *float64 + MultipleOf *float64 + Not *Schema + OneOf []*Schema + Pattern string + PatternDescription string + Properties map[string]*Schema + ReadOnly bool + Ref string + Required []string + Title string + Type string + UniqueItems bool + WriteOnly bool + func SchemaFromField(registry Registry, f reflect.StructField, hint string) *Schema + func SchemaFromType(r Registry, t reflect.Type) *Schema + func (s *Schema) MarshalJSON() ([]byte, error) + func (s *Schema) PrecomputeMessages() + type SchemaLinkTransformer struct + func NewSchemaLinkTransformer(prefix, schemasPath string) *SchemaLinkTransformer + func (t *SchemaLinkTransformer) OnAddOperation(oapi *OpenAPI, op *Operation) + func (t *SchemaLinkTransformer) Transform(ctx Context, status string, v any) (any, error) + type SchemaProvider interface + Schema func(r Registry) *Schema + type SecurityScheme struct + BearerFormat string + Description string + Extensions map[string]any + Flows *OAuthFlows + In string + Name string + OpenIDConnectURL string + Scheme string + Type string + func (s *SecurityScheme) MarshalJSON() ([]byte, error) + type Server struct + Description string + Extensions map[string]any + URL string + Variables map[string]*ServerVariable + func (s *Server) MarshalJSON() ([]byte, error) + type ServerVariable struct + Default string + Description string + Enum []string + Extensions map[string]any + func (v *ServerVariable) MarshalJSON() ([]byte, error) + type StatusError interface + Error func() string + GetStatus func() int + func Error400BadRequest(msg string, errs ...error) StatusError + func Error401Unauthorized(msg string, errs ...error) StatusError + func Error403Forbidden(msg string, errs ...error) StatusError + func Error404NotFound(msg string, errs ...error) StatusError + func Error405MethodNotAllowed(msg string, errs ...error) StatusError + func Error406NotAcceptable(msg string, errs ...error) StatusError + func Error409Conflict(msg string, errs ...error) StatusError + func Error410Gone(msg string, errs ...error) StatusError + func Error412PreconditionFailed(msg string, errs ...error) StatusError + func Error415UnsupportedMediaType(msg string, errs ...error) StatusError + func Error422UnprocessableEntity(msg string, errs ...error) StatusError + func Error429TooManyRequests(msg string, errs ...error) StatusError + func Error500InternalServerError(msg string, errs ...error) StatusError + func Error501NotImplemented(msg string, errs ...error) StatusError + func Error502BadGateway(msg string, errs ...error) StatusError + func Error503ServiceUnavailable(msg string, errs ...error) StatusError + func Error504GatewayTimeout(msg string, errs ...error) StatusError + func Status304NotModified() StatusError + type StreamResponse struct + Body func(ctx Context) + type Tag struct + Description string + Extensions map[string]any + ExternalDocs *ExternalDocs + Name string + func (t *Tag) MarshalJSON() ([]byte, error) + type Transformer func(ctx Context, status string, v any) (any, error) + type ValidateMode int + const ModeReadFromServer + const ModeWriteToServer + type ValidateResult struct + Errors []error + func (r *ValidateResult) Add(path *PathBuffer, v any, msg string) + func (r *ValidateResult) Addf(path *PathBuffer, v any, format string, args ...any) + func (r *ValidateResult) Reset()