jsonschema: copy wrapf into jsonschema/util.go (#254)
jsonschema depends on wrapf in mcp/util.go, copy this into jsonschema for the code move.
This commit is contained in:
parent
b392875dc5
commit
5bd02a3c04
3 changed files with 10 additions and 7 deletions
|
|
@ -26,8 +26,6 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/modelcontextprotocol/go-sdk/internal/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -71,7 +69,7 @@ func parseJSONPointer(ptr string) (segments []string, err error) {
|
||||||
// This implementation suffices for JSON Schema: pointers are applied only to Schemas,
|
// This implementation suffices for JSON Schema: pointers are applied only to Schemas,
|
||||||
// and refer only to Schemas.
|
// and refer only to Schemas.
|
||||||
func dereferenceJSONPointer(s *Schema, sptr string) (_ *Schema, err error) {
|
func dereferenceJSONPointer(s *Schema, sptr string) (_ *Schema, err error) {
|
||||||
defer util.Wrapf(&err, "JSON Pointer %q", sptr)
|
defer wrapf(&err, "JSON Pointer %q", sptr)
|
||||||
|
|
||||||
segments, err := parseJSONPointer(sptr)
|
segments, err := parseJSONPointer(sptr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -454,3 +454,10 @@ func fieldJSONInfo(f reflect.StructField) jsonInfo {
|
||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wrapf wraps *errp with the given formatted message if *errp is not nil.
|
||||||
|
func wrapf(errp *error, format string, args ...any) {
|
||||||
|
if *errp != nil {
|
||||||
|
*errp = fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), *errp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/modelcontextprotocol/go-sdk/internal/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The value of the "$schema" keyword for the version that we can validate.
|
// The value of the "$schema" keyword for the version that we can validate.
|
||||||
|
|
@ -74,7 +72,7 @@ type state struct {
|
||||||
|
|
||||||
// validate validates the reflected value of the instance.
|
// validate validates the reflected value of the instance.
|
||||||
func (st *state) validate(instance reflect.Value, schema *Schema, callerAnns *annotations) (err error) {
|
func (st *state) validate(instance reflect.Value, schema *Schema, callerAnns *annotations) (err error) {
|
||||||
defer util.Wrapf(&err, "validating %s", st.rs.schemaString(schema))
|
defer wrapf(&err, "validating %s", st.rs.schemaString(schema))
|
||||||
|
|
||||||
// Maintain a stack for dynamic schema resolution.
|
// Maintain a stack for dynamic schema resolution.
|
||||||
st.stack = append(st.stack, schema) // push
|
st.stack = append(st.stack, schema) // push
|
||||||
|
|
@ -613,7 +611,7 @@ func (rs *Resolved) ApplyDefaults(instancep any) error {
|
||||||
// Leave this as a potentially recursive helper function, because we'll surely want
|
// Leave this as a potentially recursive helper function, because we'll surely want
|
||||||
// to apply defaults on sub-schemas someday.
|
// to apply defaults on sub-schemas someday.
|
||||||
func (st *state) applyDefaults(instancep reflect.Value, schema *Schema) (err error) {
|
func (st *state) applyDefaults(instancep reflect.Value, schema *Schema) (err error) {
|
||||||
defer util.Wrapf(&err, "applyDefaults: schema %s, instance %v", st.rs.schemaString(schema), instancep)
|
defer wrapf(&err, "applyDefaults: schema %s, instance %v", st.rs.schemaString(schema), instancep)
|
||||||
|
|
||||||
schemaInfo := st.rs.resolvedInfos[schema]
|
schemaInfo := st.rs.resolvedInfos[schema]
|
||||||
instance := instancep.Elem()
|
instance := instancep.Elem()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue