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:
2026-09-23 20:42:38 +08:00
parent bef7ea2641
commit 7670b222ac
47 changed files with 2689 additions and 120 deletions

View File

@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"git.yuntuo.hk/k2safe/go-omni/httpx"
"git.yuntuo.hk/k2safe/go-omni/response"
"net/http"
"reflect"
"regexp"
@@ -36,6 +37,7 @@ type Schema struct {
Enum []any `json:"enum,omitempty"`
Default any `json:"default,omitempty"`
Not *Schema `json:"not,omitempty"`
AnyOf []*Schema `json:"anyOf,omitempty"`
}
type Parameter struct {
Name string `json:"name"`
@@ -181,7 +183,8 @@ func (a *API) Handler() httpx.Handler {
}
}
func Envelope(data *Schema) *Schema {
return &Schema{Type: "object", Required: []string{"code", "message"}, Properties: map[string]*Schema{"code": {Type: "string"}, "message": {Type: "string"}, "requestId": {Type: "string"}, "data": data}}
schema, _ := EnvelopeWith(data, response.Config{})
return schema
}
func SchemaOf[T any]() (*Schema, error) {
return schema(reflect.TypeOf((*T)(nil)).Elem(), map[reflect.Type]bool{}, 0)