bouncer/internal/schema/extend.go
William Petit 449fb69c02
Some checks are pending
Cadoles/bouncer/pipeline/pr-develop Build started...
Cadoles/bouncer/pipeline/head This commit looks good
feat: add layer definition api
2024-05-17 15:44:28 +02:00

37 lines
731 B
Go

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)
}
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
}