// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.

package test

import "encoding/json"
import "fmt"
import yaml "gopkg.in/yaml.v3"

type Const struct {
	// MyBoolean corresponds to the JSON schema field "myBoolean".
	MyBoolean *bool `json:"myBoolean,omitempty,omitzero" yaml:"myBoolean,omitempty" mapstructure:"myBoolean,omitempty"`

	// MyInteger corresponds to the JSON schema field "myInteger".
	MyInteger *int `json:"myInteger,omitempty,omitzero" yaml:"myInteger,omitempty" mapstructure:"myInteger,omitempty"`

	// MyNumber corresponds to the JSON schema field "myNumber".
	MyNumber *float64 `json:"myNumber,omitempty,omitzero" yaml:"myNumber,omitempty" mapstructure:"myNumber,omitempty"`

	// MyString corresponds to the JSON schema field "myString".
	MyString *string `json:"myString,omitempty,omitzero" yaml:"myString,omitempty" mapstructure:"myString,omitempty"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *Const) UnmarshalJSON(value []byte) error {
	type Plain Const
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	if plain.MyBoolean != nil && *plain.MyBoolean != true {
		return fmt.Errorf("field %s: must be equal to %t", "myBoolean", true)
	}
	if plain.MyInteger != nil && *plain.MyInteger != 42 {
		return fmt.Errorf("field %s: must be equal to %v", "myInteger", 42)
	}
	if plain.MyNumber != nil && *plain.MyNumber != 4.2 {
		return fmt.Errorf("field %s: must be equal to %v", "myNumber", 4.2)
	}
	if plain.MyString != nil && *plain.MyString != "foo" {
		return fmt.Errorf("field %s: must be equal to %s", "myString", "foo")
	}
	*j = Const(plain)
	return nil
}

// UnmarshalYAML implements yaml.Unmarshaler.
func (j *Const) UnmarshalYAML(value *yaml.Node) error {
	type Plain Const
	var plain Plain
	if err := value.Decode(&plain); err != nil {
		return err
	}
	if plain.MyBoolean != nil && *plain.MyBoolean != true {
		return fmt.Errorf("field %s: must be equal to %t", "myBoolean", true)
	}
	if plain.MyInteger != nil && *plain.MyInteger != 42 {
		return fmt.Errorf("field %s: must be equal to %v", "myInteger", 42)
	}
	if plain.MyNumber != nil && *plain.MyNumber != 4.2 {
		return fmt.Errorf("field %s: must be equal to %v", "myNumber", 4.2)
	}
	if plain.MyString != nil && *plain.MyString != "foo" {
		return fmt.Errorf("field %s: must be equal to %s", "myString", "foo")
	}
	*j = Const(plain)
	return nil
}

type Required struct {
	// MyBoolean corresponds to the JSON schema field "myBoolean".
	MyBoolean bool `json:"myBoolean" yaml:"myBoolean" mapstructure:"myBoolean"`

	// MyInteger corresponds to the JSON schema field "myInteger".
	MyInteger int `json:"myInteger" yaml:"myInteger" mapstructure:"myInteger"`

	// MyNumber corresponds to the JSON schema field "myNumber".
	MyNumber float64 `json:"myNumber" yaml:"myNumber" mapstructure:"myNumber"`

	// MyString corresponds to the JSON schema field "myString".
	MyString string `json:"myString" yaml:"myString" mapstructure:"myString"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *Required) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	if _, ok := raw["myBoolean"]; raw != nil && !ok {
		return fmt.Errorf("field myBoolean in Required: required")
	}
	if _, ok := raw["myInteger"]; raw != nil && !ok {
		return fmt.Errorf("field myInteger in Required: required")
	}
	if _, ok := raw["myNumber"]; raw != nil && !ok {
		return fmt.Errorf("field myNumber in Required: required")
	}
	if _, ok := raw["myString"]; raw != nil && !ok {
		return fmt.Errorf("field myString in Required: required")
	}
	type Plain Required
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	if plain.MyBoolean != true {
		return fmt.Errorf("field %s: must be equal to %t", "myBoolean", true)
	}
	if plain.MyInteger != 42 {
		return fmt.Errorf("field %s: must be equal to %v", "myInteger", 42)
	}
	if plain.MyNumber != 4.2 {
		return fmt.Errorf("field %s: must be equal to %v", "myNumber", 4.2)
	}
	if plain.MyString != "foo" {
		return fmt.Errorf("field %s: must be equal to %s", "myString", "foo")
	}
	*j = Required(plain)
	return nil
}

// UnmarshalYAML implements yaml.Unmarshaler.
func (j *Required) UnmarshalYAML(value *yaml.Node) error {
	var raw map[string]interface{}
	if err := value.Decode(&raw); err != nil {
		return err
	}
	if _, ok := raw["myBoolean"]; raw != nil && !ok {
		return fmt.Errorf("field myBoolean in Required: required")
	}
	if _, ok := raw["myInteger"]; raw != nil && !ok {
		return fmt.Errorf("field myInteger in Required: required")
	}
	if _, ok := raw["myNumber"]; raw != nil && !ok {
		return fmt.Errorf("field myNumber in Required: required")
	}
	if _, ok := raw["myString"]; raw != nil && !ok {
		return fmt.Errorf("field myString in Required: required")
	}
	type Plain Required
	var plain Plain
	if err := value.Decode(&plain); err != nil {
		return err
	}
	if plain.MyBoolean != true {
		return fmt.Errorf("field %s: must be equal to %t", "myBoolean", true)
	}
	if plain.MyInteger != 42 {
		return fmt.Errorf("field %s: must be equal to %v", "myInteger", 42)
	}
	if plain.MyNumber != 4.2 {
		return fmt.Errorf("field %s: must be equal to %v", "myNumber", 4.2)
	}
	if plain.MyString != "foo" {
		return fmt.Errorf("field %s: must be equal to %s", "myString", "foo")
	}
	*j = Required(plain)
	return nil
}
