| 3309 | var _ huma.Resolver = (*ExhaustiveErrorsInput)(nil) |
| 3310 | |
| 3311 | func TestExhaustiveErrors(t *testing.T) { |
| 3312 | r, app := humatest.New(t, huma.DefaultConfig("Test API", "1.0.0")) |
| 3313 | huma.Register(app, huma.Operation{ |
| 3314 | OperationID: "test", |
| 3315 | Method: http.MethodPut, |
| 3316 | Path: "/errors/{id}", |
| 3317 | }, func(ctx context.Context, input *ExhaustiveErrorsInput) (*struct{}, error) { |
| 3318 | return nil, nil |
| 3319 | }) |
| 3320 | |
| 3321 | req, _ := http.NewRequest(http.MethodPut, "/errors/15?query=3", strings.NewReader(`{"name": "12345678901", "count": -6}`)) |
| 3322 | req.Header.Set("Content-Type", "application/json") |
| 3323 | req.Header.Set("Header", "3") |
| 3324 | w := httptest.NewRecorder() |
| 3325 | r.ServeHTTP(w, req) |
| 3326 | assert.Equal(t, http.StatusUnprocessableEntity, w.Code) |
| 3327 | assert.JSONEq(t, `{ |
| 3328 | "$schema": "http://localhost/schemas/ErrorModel.json", |
| 3329 | "title": "Unprocessable Entity", |
| 3330 | "status": 422, |
| 3331 | "detail": "validation failed", |
| 3332 | "errors": [ |
| 3333 | { |
| 3334 | "message": "expected number <= 10", |
| 3335 | "location": "path.id", |
| 3336 | "value": 15 |
| 3337 | }, { |
| 3338 | "message": "expected number >= 1", |
| 3339 | "location": "body.count", |
| 3340 | "value": -6 |
| 3341 | }, { |
| 3342 | "message": "expected length <= 10", |
| 3343 | "location": "body.name", |
| 3344 | "value": "12345678901" |
| 3345 | }, { |
| 3346 | "message": "input resolver error", |
| 3347 | "location": "path.id", |
| 3348 | "value": 15 |
| 3349 | }, { |
| 3350 | "message": "Value cannot be a multiple of three", |
| 3351 | "location": "path.id", |
| 3352 | "value": 15 |
| 3353 | }, { |
| 3354 | "message": "Value cannot be a multiple of three", |
| 3355 | "location": "query.query", |
| 3356 | "value": 3 |
| 3357 | }, { |
| 3358 | "message": "Value cannot be a multiple of three", |
| 3359 | "location": "header.header", |
| 3360 | "value": 3 |
| 3361 | }, { |
| 3362 | "message": "body resolver error" |
| 3363 | }, { |
| 3364 | "message": "Value cannot be a multiple of three", |
| 3365 | "location": "body.count", |
| 3366 | "value": -6 |
| 3367 | } |
| 3368 | ] |