package openapi_test import ( "testing" "git.yuntuo.hk/k2safe/go-omni/openapi" "git.yuntuo.hk/k2safe/go-omni/response" ) func TestResponseCodeSchemaUsesGoWidths(t *testing.T) { for _, kind := range []string{"string", "int32", "int64", "integer"} { cfg := response.Config{CodeType: kind} wantType, wantFormat := "string", "" if kind != "string" { cfg.SuccessCode = 200 cfg.ErrorCode = 9999 wantType = "integer" } if kind == "int32" || kind == "int64" { wantFormat = kind } for _, nested := range []bool{false, true} { if nested { cfg.Body = map[string]any{"result": map[string]any{"code": "${code}"}} cfg.ErrorBody = cfg.Body } for _, data := range []*openapi.Schema{nil, {Type: "object"}} { schema, err := openapi.EnvelopeWith(data, cfg) if err != nil { t.Fatal(err) } if nested { schema = schema.Properties["result"] } code := schema.Properties["code"] if code.Type != wantType || code.Format != wantFormat { t.Fatalf("%s: %+v", kind, code) } } } } }