// Code generated by internal/schemagen. DO NOT EDIT.

package schema

import (
	"encoding/json"
	"fmt"
)

// marshalWith marshals v and injects a key-value pair.
func marshalWith(v interface{}, key, value string) ([]byte, error) {
	b, err := json.Marshal(v)
	if err != nil {
		return nil, err
	}
	return injectField(b, key, value)
}

// injectField injects a key-value pair into a JSON object byte slice.
func injectField(data []byte, key, value string) ([]byte, error) {
	var obj map[string]json.RawMessage
	if err := json.Unmarshal(data, &obj); err != nil {
		return nil, err
	}
	v, _ := json.Marshal(value)
	obj[key] = v
	return json.Marshal(obj)
}

// errMissingField creates a descriptive error for a missing JSON field.
func errMissingField(field, typeName string) error {
	return fmt.Errorf("missing required field %q in %s", field, typeName)
}
