MCPcopy
hub / github.com/danielgtaylor/huma / New

Function New

humatest/humatest.go:319–342  ·  view source on GitHub ↗

New creates a new router and test API, making it easy to register operations and perform requests against them. Optionally takes a configuration object to customize how the API is created. If no configuration is provided then a simple default configuration supporting `application/json` is used.

(tb TB, configs ...huma.Config)

Source from the content-addressed store, hash-verified

317// to customize how the API is created. If no configuration is provided then
318// a simple default configuration supporting `application/json` is used.
319func New(tb TB, configs ...huma.Config) (http.Handler, TestAPI) {
320 for _, config := range configs {
321 if config.OpenAPI == nil {
322 panic("custom huma.Config structs must specify a value for OpenAPI")
323 }
324 }
325 if len(configs) == 0 {
326 configs = append(configs, huma.Config{
327 OpenAPI: &huma.OpenAPI{
328 Info: &huma.Info{
329 Title: "Test API",
330 Version: "1.0.0",
331 },
332 },
333 Formats: map[string]huma.Format{
334 "application/json": huma.DefaultJSONFormat,
335 "json": huma.DefaultJSONFormat,
336 },
337 DefaultFormat: "application/json",
338 })
339 }
340 r := flow.New()
341 return r, Wrap(tb, humaflow.New(r, configs[0]))
342}
343
344func dumpBody(body io.ReadCloser, buf *bytes.Buffer) (io.ReadCloser, error) {
345 if body == nil {

Callers 15

BenchmarkRegisterFunction · 0.92
TestContextValueFunction · 0.92
TestDocsRenderersFunction · 0.92
TestOpenAPIFunction · 0.92
TestContentTypeFilterFunction · 0.92
TestExhaustiveErrorsFunction · 0.92
TestCustomErrorFunction · 0.92
TestClientDisconnectFunction · 0.92
TestResolverCustomStatusFunction · 0.92

Calls 3

NewFunction · 0.92
NewFunction · 0.92
WrapFunction · 0.85

Tested by 15

BenchmarkRegisterFunction · 0.74
TestContextValueFunction · 0.74
TestDocsRenderersFunction · 0.74
TestOpenAPIFunction · 0.74
TestContentTypeFilterFunction · 0.74
TestExhaustiveErrorsFunction · 0.74
TestCustomErrorFunction · 0.74
TestClientDisconnectFunction · 0.74
TestResolverCustomStatusFunction · 0.74