feat: release configurable API response contracts
Define reusable response bodies in .api with typed code mappings, per-route overrides and matching OpenAPI schemas. Add application and callback encoders, early response policy selection, and isolated remote-consumer release verification. Release v0.8.0-preview after full race, vet, build and local MySQL workflow acceptance.
This commit is contained in:
42
openapi/codeTypes_test.go
Normal file
42
openapi/codeTypes_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user