package schema import ( "encoding/json" "github.com/pkg/errors" ) func Extend(base []byte, schema []byte) ([]byte, error) { var ( extension map[string]any extended map[string]any ) if err := json.Unmarshal(base, &extended); err != nil { return nil, errors.WithStack(err) } if err := json.Unmarshal(schema, &extension); err != nil { return nil, errors.WithStack(err) } extended["$id"] = extension["$id"] extended["title"] = extension["title"] props := extension["properties"].(map[string]any) extendedProps := extended["properties"].(map[string]any) for key, val := range props { extendedProps[key] = val } extended["properties"] = extendedProps data, err := json.MarshalIndent(extended, "", " ") if err != nil { return nil, errors.WithStack(err) } return data, nil }