| 182 | } |
| 183 | |
| 184 | func BenchmarkFullRequest_Complex(b *testing.B) { |
| 185 | _, api := humatest.New(b, huma.DefaultConfig("Test API", "1.0.0")) |
| 186 | |
| 187 | huma.Register(api, huma.Operation{ |
| 188 | Method: http.MethodPost, |
| 189 | Path: "/complex/{id}", |
| 190 | }, func(ctx context.Context, input *ComplexInput) (*ComplexOutput, error) { |
| 191 | resp := &ComplexOutput{} |
| 192 | resp.Status = 201 |
| 193 | resp.Body.ID = input.ID |
| 194 | resp.Body.Result = input.Body |
| 195 | resp.Body.Message = "Created" |
| 196 | return resp, nil |
| 197 | }) |
| 198 | |
| 199 | reqBody := `{"string": "Benchmark", "int": 100, "float": 0.1, "bool": true, "time": "2023-01-01T00:00:00Z", "slice": ["a"], "sub": {"id": 1, "name": "SubItem"}, "sub_slice": [{"id": 1, "name": "Item"}], "map": {"k": {"id": 1, "name": "val"}}}` |
| 200 | |
| 201 | b.ResetTimer() |
| 202 | b.ReportAllocs() |
| 203 | for i := 0; i < b.N; i++ { |
| 204 | r := httptest.NewRequest(http.MethodPost, "/complex/123?search=test&page=2", strings.NewReader(reqBody)) |
| 205 | r.Header.Set("Content-Type", "application/json") |
| 206 | w := httptest.NewRecorder() |
| 207 | api.Adapter().ServeHTTP(w, r) |
| 208 | if w.Code != http.StatusCreated { |
| 209 | b.Fatalf("expected 201, got %d: %s", w.Code, w.Body.String()) |
| 210 | } |
| 211 | } |
| 212 | } |