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)
| 317 | // to customize how the API is created. If no configuration is provided then |
| 318 | // a simple default configuration supporting `application/json` is used. |
| 319 | func 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 | |
| 344 | func dumpBody(body io.ReadCloser, buf *bytes.Buffer) (io.ReadCloser, error) { |
| 345 | if body == nil { |