Add JSON schema support

This commit is contained in:
世界
2026-07-24 18:15:14 +08:00
parent 0b54f57725
commit 58affa1c6d
87 changed files with 19320 additions and 305 deletions
+13 -1
View File
@@ -1,6 +1,9 @@
package option
import (
"reflect"
"github.com/sagernet/sing-box/schema"
"github.com/sagernet/sing/common/json"
"github.com/sagernet/sing/common/json/badoption"
)
@@ -8,7 +11,7 @@ import (
type APIServiceOptions struct {
ListenOptions
Secret string `json:"secret,omitempty"`
AccessControlAllowOrigin badoption.Listable[string] `json:"access_control_allow_origin,omitempty"`
AccessControlAllowOrigin badoption.Listable[string] `json:"access_control_allow_origin,omitempty" examples:"http://sing-box-dashboard.sagernet.org/,https://sing-box-dashboard.sagernet.org/"`
AccessControlAllowPrivateNetwork bool `json:"access_control_allow_private_network,omitempty"`
Dashboard *APIDashboardOptions `json:"dashboard,omitempty"`
InboundTLSOptionsContainer
@@ -48,3 +51,12 @@ func (o *APIDashboardOptions) UnmarshalJSON(bytes []byte) error {
}
return json.UnmarshalDisallowUnknownFields(bytes, (*_APIDashboardOptions)(o))
}
func (o APIDashboardOptions) DescribeSchema(builder schema.Builder) (*schema.Node, error) {
objectForm := schema.StrictObject()
err := builder.FlattenStruct(objectForm, reflect.TypeFor[APIDashboardOptions]())
if err != nil {
return nil, err
}
return schema.AnyOf(schema.BooleanNode(), schema.StringNode(), objectForm), nil
}