// 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 Bar struct {
	// RefToFoo corresponds to the JSON schema field "refToFoo".
	RefToFoo *Foo `json:"refToFoo,omitempty,omitzero" yaml:"refToFoo,omitempty" mapstructure:"refToFoo,omitempty"`
}

type CyclicAndRequired1 struct {
	// A corresponds to the JSON schema field "a".
	A *Foo `json:"a,omitempty,omitzero" yaml:"a,omitempty" mapstructure:"a,omitempty"`
}

type Foo struct {
	// RefToBar corresponds to the JSON schema field "refToBar".
	RefToBar Bar `json:"refToBar" yaml:"refToBar" mapstructure:"refToBar"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *Foo) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	if _, ok := raw["refToBar"]; raw != nil && !ok {
		return fmt.Errorf("field refToBar in Foo: required")
	}
	type Plain Foo
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	*j = Foo(plain)
	return nil
}

// UnmarshalYAML implements yaml.Unmarshaler.
func (j *Foo) UnmarshalYAML(value *yaml.Node) error {
	var raw map[string]interface{}
	if err := value.Decode(&raw); err != nil {
		return err
	}
	if _, ok := raw["refToBar"]; raw != nil && !ok {
		return fmt.Errorf("field refToBar in Foo: required")
	}
	type Plain Foo
	var plain Plain
	if err := value.Decode(&plain); err != nil {
		return err
	}
	*j = Foo(plain)
	return nil
}
