Documentation
¶
Index ¶
- func Delete[I, O any](api API, path string, handler func(context.Context, *I) (*O, error), ...)
- func Get[I, O any](api API, path string, handler func(context.Context, *I) (*O, error), ...)
- func Head[I, O any](api API, path string, handler func(context.Context, *I) (*O, error), ...)
- func Options[I, O any](api API, path string, handler func(context.Context, *I) (*O, error), ...)
- func Patch[I, O any](api API, path string, handler func(context.Context, *I) (*O, error), ...)
- func Post[I, O any](api API, path string, handler func(context.Context, *I) (*O, error), ...)
- func Put[I, O any](api API, path string, handler func(context.Context, *I) (*O, error), ...)
- func Register[I, O any](api API, operation huma.Operation, ...)
- type API
- type APIGen
- func (a APIGen) AddBasePath(basePath string) APIGen
- func (a APIGen) AddBubblingRegMiddleware(regMiddlewares ...RegMiddleware) APIGen
- func (a APIGen) AddExtraHumaAPI(api huma.API, bubblingRegMiddlewares ...RegMiddleware) APIGen
- func (a APIGen) AddMiddlewares(middlewares ...func(huma.Context, func(huma.Context))) APIGen
- func (a APIGen) AddMultiBasePaths(explicitOpIDBuilder func(*huma.Operation) string, basePaths ...string) APIGen
- func (a APIGen) AddOpHandler(handlers ...op_handler.OperationHandler) APIGen
- func (a APIGen) AddOwnOpenAPI(apiConfig huma.Config, bubblingRegMiddlewares ...RegMiddleware) (APIGen, *huma.OpenAPI)
- func (a APIGen) AddRegMiddleware(regMiddlewares ...RegMiddleware) APIGen
- func (a APIGen) AddTransformers(transformers ...huma.Transformer) APIGen
- func (a APIGen) GetBubblingRegMiddlewares() RegMiddlewares
- func (a APIGen) GetExtraHumaAPIs() []ExtraHumaApiInstance
- func (a APIGen) GetHumaAPI() huma.API
- func (a APIGen) GetRegMiddlewares() RegMiddlewares
- func (a APIGen) GetTransformers() []huma.Transformer
- func (a APIGen) ReplaceHumaAPI(humaApi huma.API) APIGen
- type ExtraHumaApiInstance
- type RegMiddleware
- type RegMiddlewares
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete[I, O any]( api API, path string, handler func( context.Context, *I, ) (*O, error), operationHandlers ...func(o *huma.Operation))
Delete is a shortcut for Register method that implicitly generates Operation object metadata.KeyIsExplicitOperationID, metadata.KeyIsExplicitSummary keys will not be set.
func Get ¶
func Get[I, O any]( api API, path string, handler func(context.Context, *I) (*O, error), operationHandlers ...func(o *huma.Operation), )
Get is a shortcut for Register method that implicitly generates Operation object metadata.KeyIsExplicitOperationID, metadata.KeyIsExplicitSummary keys will not be set.
func Head ¶
func Head[I, O any]( api API, path string, handler func( context.Context, *I, ) (*O, error), operationHandlers ...func(o *huma.Operation))
Head is a shortcut for Register method that implicitly generates Operation object metadata.KeyIsExplicitOperationID, metadata.KeyIsExplicitSummary keys will not be set.
func Options ¶
func Options[I, O any]( api API, path string, handler func( context.Context, *I, ) (*O, error), operationHandlers ...func(o *huma.Operation))
Options is a shortcut for Register method that implicitly generates Operation object metadata.KeyIsExplicitOperationID, metadata.KeyIsExplicitSummary keys will not be set.
func Patch ¶
func Patch[I, O any]( api API, path string, handler func(context.Context, *I) (*O, error), operationHandlers ...func(o *huma.Operation), )
Patch is a shortcut for Register method that implicitly generates Operation object metadata.KeyIsExplicitOperationID, metadata.KeyIsExplicitSummary keys will not be set.
func Post ¶
func Post[I, O any]( api API, path string, handler func(context.Context, *I) (*O, error), operationHandlers ...func(o *huma.Operation), )
Post is a shortcut for Register method that implicitly generates Operation object metadata.KeyIsExplicitOperationID, metadata.KeyIsExplicitSummary keys will not be set.
func Put ¶
func Put[I, O any]( api API, path string, handler func(context.Context, *I) (*O, error), operationHandlers ...func(o *huma.Operation), )
Put is a shortcut for Register method that implicitly generates Operation object metadata.KeyIsExplicitOperationID, metadata.KeyIsExplicitSummary keys will not be set.
func Register ¶
func Register[I, O any]( api API, operation huma.Operation, handler func(context.Context, *I) (*O, error), operationHandlers ...func(o *huma.Operation), )
Register registers a handler for an explicitly provided operation. It will apply all RegMiddlewares stored in API to the operation and passed operationHandlers after that. Depending on RegMiddlewares, an operation can be modified, registered multiple times with different base paths or not registered at all. Before passing an operation to the RegMiddlewares, it will be initialized with the metadata keys required for the library functionality. metadata.KeyIsExplicitOperationID, metadata.KeyIsExplicitSummary keys will be set to `true` See other keys in metadata package for details.
Types ¶
type API ¶
type API interface {
GetHumaAPI() huma.API
GetExtraHumaAPIs() []ExtraHumaApiInstance
GetRegMiddlewares() RegMiddlewares
GetBubblingRegMiddlewares() RegMiddlewares
GetTransformers() []huma.Transformer
}
API is wrapper of huma.API that stores RegMiddlewares that should be applied to operations before registration in Huma.
type APIGen ¶
type APIGen struct {
// contains filtered or unexported fields
}
APIGen is a core type of the library that wraps huma.API and stores RegMiddlewares that should be applied to operations before registration in Huma. It provides a fluent API to create derived APIGen instances with own set of actions/changes to an operation before its registration.
func (APIGen) AddBasePath ¶
AddBasePath returns a new APIGen instance that will add the given basePath segment to an operation`s Path. It will append `basePath` to the previously added base paths if any. Adding a base path also re-generates the OperationID and Summary fields of an operation if it wasn't explicitly set. It's an alternative to Route, Group methods of go routes.
func (APIGen) AddBubblingRegMiddleware ¶ added in v1.0.0
func (a APIGen) AddBubblingRegMiddleware(regMiddlewares ...RegMiddleware) APIGen
AddBubblingRegMiddleware returns a new APIGen instance with the given RegMiddlewares added to the stored bubbling RegMiddlewares. Bubbling RegMiddlewares will be applied to the operation in the opposite order after normal RegMiddlewares are done allowing you to observe changes made by all previous RegMiddlewares.
func (APIGen) AddExtraHumaAPI ¶ added in v1.0.0
func (a APIGen) AddExtraHumaAPI(api huma.API, bubblingRegMiddlewares ...RegMiddleware) APIGen
AddExtraHumaAPI returns a new APIGen instance with the given huma.API added to the extraHumaAPIs. All operations registered with this APIGen instance or derived instances will be passed to the given `api` additionally to the main huma.API. Optional bubbling RegMiddlewares will be applied to the operations before the registration in the `api`.
func (APIGen) AddMiddlewares ¶
AddMiddlewares returns a new APIGen instance that will add the given middlewares to the operation.
func (APIGen) AddMultiBasePaths ¶
func (a APIGen) AddMultiBasePaths( explicitOpIDBuilder func(*huma.Operation) string, basePaths ...string, ) APIGen
AddMultiBasePaths returns a new APIGen instance that will register the same operation with multiple base paths. It respects base paths added before and after this method call. Since it leads to multiple registrations of the same operation, it requires OperationID to be updated to avoid registration of multiple operations with the same OperationID. If an operation has generated OperationID, it will be re-generated by default Huma operation ID builder. The same is true for the Summary field. For the case of explicitly set OperationID, you can provide a custom `explicitOpIDBuilder` builder. It will receive an operation with modified Path and metadata.KeyBasePath and should return a new OperationID. If `explicitOpIDBuilder` is nil, the built-in approach will be used. It will take metadata.KeyBasePath as a prefix for the OperationID, turning it into kebab-case and will append it to the metadata.KeyInitOperationID (that stores the initial user-provided OperationID).
func (APIGen) AddOpHandler ¶
func (a APIGen) AddOpHandler(handlers ...op_handler.OperationHandler) APIGen
AddOpHandler returns a new APIGen instance with the given OperationHandlers added to it.
func (APIGen) AddOwnOpenAPI ¶ added in v1.0.0
func (a APIGen) AddOwnOpenAPI(apiConfig huma.Config, bubblingRegMiddlewares ...RegMiddleware) (APIGen, *huma.OpenAPI)
AddOwnOpenAPI is a shortcut function to create a new APIGen instance and a OpenAPI object instance together. All operations registered with this APIGen instance or derived instances will be added to the OpenAPI object. `bubbleRegMiddlewares` will be additionally applied to the operations before the registration in the OpenAPI object. It allows you to have separate OpenAPI spec that contains only operations registered with this APIGen instance or derived instances. Use it in combination with `pkg/huma/oapi_handlers` package to serve the created OpenAPI spec.
func (APIGen) AddRegMiddleware ¶
func (a APIGen) AddRegMiddleware(regMiddlewares ...RegMiddleware) APIGen
AddRegMiddleware returns a new APIGen instance with the given RegMiddlewares added to the stored RegMiddlewares.
func (APIGen) AddTransformers ¶
func (a APIGen) AddTransformers(transformers ...huma.Transformer) APIGen
AddTransformers returns a new APIGen instance with the given transformers that will be applied to the responses of the handlers registered by this APIGen.
func (APIGen) GetBubblingRegMiddlewares ¶ added in v1.0.0
func (a APIGen) GetBubblingRegMiddlewares() RegMiddlewares
GetBubblingRegMiddlewares returns the stored bubbling RegMiddlewares.
func (APIGen) GetExtraHumaAPIs ¶ added in v1.0.0
func (a APIGen) GetExtraHumaAPIs() []ExtraHumaApiInstance
GetExtraHumaAPIs returns the stored extraHumaAPIs.
func (APIGen) GetHumaAPI ¶
GetHumaAPI returns the wrapped huma.API.
func (APIGen) GetRegMiddlewares ¶
func (a APIGen) GetRegMiddlewares() RegMiddlewares
GetRegMiddlewares returns the stored RegMiddlewares.
func (APIGen) GetTransformers ¶
func (a APIGen) GetTransformers() []huma.Transformer
GetTransformers returns the stored transformers that will be applied to the responses of the handlers registered by this APIGen.
func (APIGen) ReplaceHumaAPI ¶ added in v1.0.2
ReplaceHumaAPI returns a new APIGen instance with replaced huma.API pointer. Can be useful for some tricky cases when you create huma.API instance based on another adapter but with the same config (and OpenAPI object pointer) to utilize router-specific middlewares for a group.
type ExtraHumaApiInstance ¶ added in v1.0.1
type ExtraHumaApiInstance struct {
// contains filtered or unexported fields
}
type RegMiddleware ¶
RegMiddleware is core concept of the library that provides flexibility in setting up the registration pipeline: using route groups, pre-specified middlewares and other properties of operations for an instance of API RegMiddlewares are functions that are called in chain (similar to normal HTTP middlewares) during the operation registration (before the operation will be registered in Huma). RegMiddleware can produce side effects or modify the operation and pass it to the next RegMiddleware in the chain. - Calling `next` more than one time will lead to multiple registrations of the same operation, see RegMiddlewares.FanOut method - By not calling `next` at all you can prevent the operation from being registered
func NewRegMiddleware ¶
func NewRegMiddleware(opHandlers ...op_handler.OperationHandler) RegMiddleware
NewRegMiddleware creates a new RegMiddleware that applies the given OperationHandlers to the operation.
type RegMiddlewares ¶
type RegMiddlewares []RegMiddleware
func (RegMiddlewares) Chain ¶
func (hs RegMiddlewares) Chain() RegMiddleware
Chain creates a new RegMiddleware that chains RegMiddlewares together returning a single RegMiddleware.
func (RegMiddlewares) FanOut ¶
func (hs RegMiddlewares) FanOut() RegMiddleware
FanOut creates a new RegMiddleware that calls all RegMiddlewares one by one passing the same `next` function to them and a copy of the received operation. It leads to "multiplication" of the registration pipeline, creating multiple branches of registration pipeline after this RegMiddleware. It can be used to register multiple operations in Huma out of one registration call. Normally you are not supposed to use it in your own registration pipelines since:
- it requires a special handling of OperationID in order not to get multiple operations with the same OperationID
- it uses internal operation cloning that is sufficient for the library-provided operation handlers but may not be sufficient for your custom operation handlers that modify the nested structures of the operation.
It's used to create multiple alternative base paths for the same operation.
