// 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 ReadOnly struct {
	// MyReadOnlyString corresponds to the JSON schema field "myReadOnlyString".
	MyReadOnlyString *string `json:"myReadOnlyString,omitempty,omitzero" yaml:"myReadOnlyString,omitempty" mapstructure:"myReadOnlyString,omitempty"`

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

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

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