bunnyshell.com/sdk@v0.16.0/model_template_item_variables_schema_inner.go (about)

     1  /*
     2  API Bunnyshell Environments
     3  
     4  Interact with Bunnyshell Platform
     5  
     6  API version: 1.1.0
     7  Contact: osi+support@bunnyshell.com
     8  */
     9  
    10  // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
    11  
    12  package sdk
    13  
    14  import (
    15  	"encoding/json"
    16  	"fmt"
    17  )
    18  
    19  // TemplateItemVariablesSchemaInner - struct for TemplateItemVariablesSchemaInner
    20  type TemplateItemVariablesSchemaInner struct {
    21  	BooleanTypeItem *BooleanTypeItem
    22  	EnumTypeItem    *EnumTypeItem
    23  	FloatTypeItem   *FloatTypeItem
    24  	IntegerTypeItem *IntegerTypeItem
    25  	StringTypeItem  *StringTypeItem
    26  }
    27  
    28  // BooleanTypeItemAsTemplateItemVariablesSchemaInner is a convenience function that returns BooleanTypeItem wrapped in TemplateItemVariablesSchemaInner
    29  func BooleanTypeItemAsTemplateItemVariablesSchemaInner(v *BooleanTypeItem) TemplateItemVariablesSchemaInner {
    30  	return TemplateItemVariablesSchemaInner{
    31  		BooleanTypeItem: v,
    32  	}
    33  }
    34  
    35  // EnumTypeItemAsTemplateItemVariablesSchemaInner is a convenience function that returns EnumTypeItem wrapped in TemplateItemVariablesSchemaInner
    36  func EnumTypeItemAsTemplateItemVariablesSchemaInner(v *EnumTypeItem) TemplateItemVariablesSchemaInner {
    37  	return TemplateItemVariablesSchemaInner{
    38  		EnumTypeItem: v,
    39  	}
    40  }
    41  
    42  // FloatTypeItemAsTemplateItemVariablesSchemaInner is a convenience function that returns FloatTypeItem wrapped in TemplateItemVariablesSchemaInner
    43  func FloatTypeItemAsTemplateItemVariablesSchemaInner(v *FloatTypeItem) TemplateItemVariablesSchemaInner {
    44  	return TemplateItemVariablesSchemaInner{
    45  		FloatTypeItem: v,
    46  	}
    47  }
    48  
    49  // IntegerTypeItemAsTemplateItemVariablesSchemaInner is a convenience function that returns IntegerTypeItem wrapped in TemplateItemVariablesSchemaInner
    50  func IntegerTypeItemAsTemplateItemVariablesSchemaInner(v *IntegerTypeItem) TemplateItemVariablesSchemaInner {
    51  	return TemplateItemVariablesSchemaInner{
    52  		IntegerTypeItem: v,
    53  	}
    54  }
    55  
    56  // StringTypeItemAsTemplateItemVariablesSchemaInner is a convenience function that returns StringTypeItem wrapped in TemplateItemVariablesSchemaInner
    57  func StringTypeItemAsTemplateItemVariablesSchemaInner(v *StringTypeItem) TemplateItemVariablesSchemaInner {
    58  	return TemplateItemVariablesSchemaInner{
    59  		StringTypeItem: v,
    60  	}
    61  }
    62  
    63  // Unmarshal JSON data into one of the pointers in the struct
    64  func (dst *TemplateItemVariablesSchemaInner) UnmarshalJSON(data []byte) error {
    65  	var err error
    66  	// use discriminator value to speed up the lookup
    67  	var jsonDict map[string]interface{}
    68  	err = newStrictDecoder(data).Decode(&jsonDict)
    69  	if err != nil {
    70  		return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup")
    71  	}
    72  
    73  	// check if the discriminator value is 'BooleanType-item'
    74  	if jsonDict["type"] == "BooleanType-item" {
    75  		// try to unmarshal JSON data into BooleanTypeItem
    76  		err = json.Unmarshal(data, &dst.BooleanTypeItem)
    77  		if err == nil {
    78  			return nil // data stored in dst.BooleanTypeItem, return on the first match
    79  		} else {
    80  			dst.BooleanTypeItem = nil
    81  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as BooleanTypeItem: %s", err.Error())
    82  		}
    83  	}
    84  
    85  	// check if the discriminator value is 'EnumType-item'
    86  	if jsonDict["type"] == "EnumType-item" {
    87  		// try to unmarshal JSON data into EnumTypeItem
    88  		err = json.Unmarshal(data, &dst.EnumTypeItem)
    89  		if err == nil {
    90  			return nil // data stored in dst.EnumTypeItem, return on the first match
    91  		} else {
    92  			dst.EnumTypeItem = nil
    93  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as EnumTypeItem: %s", err.Error())
    94  		}
    95  	}
    96  
    97  	// check if the discriminator value is 'FloatType-item'
    98  	if jsonDict["type"] == "FloatType-item" {
    99  		// try to unmarshal JSON data into FloatTypeItem
   100  		err = json.Unmarshal(data, &dst.FloatTypeItem)
   101  		if err == nil {
   102  			return nil // data stored in dst.FloatTypeItem, return on the first match
   103  		} else {
   104  			dst.FloatTypeItem = nil
   105  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as FloatTypeItem: %s", err.Error())
   106  		}
   107  	}
   108  
   109  	// check if the discriminator value is 'IntegerType-item'
   110  	if jsonDict["type"] == "IntegerType-item" {
   111  		// try to unmarshal JSON data into IntegerTypeItem
   112  		err = json.Unmarshal(data, &dst.IntegerTypeItem)
   113  		if err == nil {
   114  			return nil // data stored in dst.IntegerTypeItem, return on the first match
   115  		} else {
   116  			dst.IntegerTypeItem = nil
   117  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as IntegerTypeItem: %s", err.Error())
   118  		}
   119  	}
   120  
   121  	// check if the discriminator value is 'StringType-item'
   122  	if jsonDict["type"] == "StringType-item" {
   123  		// try to unmarshal JSON data into StringTypeItem
   124  		err = json.Unmarshal(data, &dst.StringTypeItem)
   125  		if err == nil {
   126  			return nil // data stored in dst.StringTypeItem, return on the first match
   127  		} else {
   128  			dst.StringTypeItem = nil
   129  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as StringTypeItem: %s", err.Error())
   130  		}
   131  	}
   132  
   133  	// check if the discriminator value is 'bool'
   134  	if jsonDict["type"] == "bool" {
   135  		// try to unmarshal JSON data into BooleanTypeItem
   136  		err = json.Unmarshal(data, &dst.BooleanTypeItem)
   137  		if err == nil {
   138  			return nil // data stored in dst.BooleanTypeItem, return on the first match
   139  		} else {
   140  			dst.BooleanTypeItem = nil
   141  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as BooleanTypeItem: %s", err.Error())
   142  		}
   143  	}
   144  
   145  	// check if the discriminator value is 'enum'
   146  	if jsonDict["type"] == "enum" {
   147  		// try to unmarshal JSON data into EnumTypeItem
   148  		err = json.Unmarshal(data, &dst.EnumTypeItem)
   149  		if err == nil {
   150  			return nil // data stored in dst.EnumTypeItem, return on the first match
   151  		} else {
   152  			dst.EnumTypeItem = nil
   153  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as EnumTypeItem: %s", err.Error())
   154  		}
   155  	}
   156  
   157  	// check if the discriminator value is 'float'
   158  	if jsonDict["type"] == "float" {
   159  		// try to unmarshal JSON data into FloatTypeItem
   160  		err = json.Unmarshal(data, &dst.FloatTypeItem)
   161  		if err == nil {
   162  			return nil // data stored in dst.FloatTypeItem, return on the first match
   163  		} else {
   164  			dst.FloatTypeItem = nil
   165  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as FloatTypeItem: %s", err.Error())
   166  		}
   167  	}
   168  
   169  	// check if the discriminator value is 'int'
   170  	if jsonDict["type"] == "int" {
   171  		// try to unmarshal JSON data into IntegerTypeItem
   172  		err = json.Unmarshal(data, &dst.IntegerTypeItem)
   173  		if err == nil {
   174  			return nil // data stored in dst.IntegerTypeItem, return on the first match
   175  		} else {
   176  			dst.IntegerTypeItem = nil
   177  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as IntegerTypeItem: %s", err.Error())
   178  		}
   179  	}
   180  
   181  	// check if the discriminator value is 'string'
   182  	if jsonDict["type"] == "string" {
   183  		// try to unmarshal JSON data into StringTypeItem
   184  		err = json.Unmarshal(data, &dst.StringTypeItem)
   185  		if err == nil {
   186  			return nil // data stored in dst.StringTypeItem, return on the first match
   187  		} else {
   188  			dst.StringTypeItem = nil
   189  			return fmt.Errorf("failed to unmarshal TemplateItemVariablesSchemaInner as StringTypeItem: %s", err.Error())
   190  		}
   191  	}
   192  
   193  	return nil
   194  }
   195  
   196  // Marshal data from the first non-nil pointers in the struct to JSON
   197  func (src TemplateItemVariablesSchemaInner) MarshalJSON() ([]byte, error) {
   198  	if src.BooleanTypeItem != nil {
   199  		return json.Marshal(&src.BooleanTypeItem)
   200  	}
   201  
   202  	if src.EnumTypeItem != nil {
   203  		return json.Marshal(&src.EnumTypeItem)
   204  	}
   205  
   206  	if src.FloatTypeItem != nil {
   207  		return json.Marshal(&src.FloatTypeItem)
   208  	}
   209  
   210  	if src.IntegerTypeItem != nil {
   211  		return json.Marshal(&src.IntegerTypeItem)
   212  	}
   213  
   214  	if src.StringTypeItem != nil {
   215  		return json.Marshal(&src.StringTypeItem)
   216  	}
   217  
   218  	return nil, nil // no data in oneOf schemas
   219  }
   220  
   221  // Get the actual instance
   222  func (obj *TemplateItemVariablesSchemaInner) GetActualInstance() interface{} {
   223  	if obj == nil {
   224  		return nil
   225  	}
   226  	if obj.BooleanTypeItem != nil {
   227  		return obj.BooleanTypeItem
   228  	}
   229  
   230  	if obj.EnumTypeItem != nil {
   231  		return obj.EnumTypeItem
   232  	}
   233  
   234  	if obj.FloatTypeItem != nil {
   235  		return obj.FloatTypeItem
   236  	}
   237  
   238  	if obj.IntegerTypeItem != nil {
   239  		return obj.IntegerTypeItem
   240  	}
   241  
   242  	if obj.StringTypeItem != nil {
   243  		return obj.StringTypeItem
   244  	}
   245  
   246  	// all schemas are nil
   247  	return nil
   248  }
   249  
   250  type NullableTemplateItemVariablesSchemaInner struct {
   251  	value *TemplateItemVariablesSchemaInner
   252  	isSet bool
   253  }
   254  
   255  func (v NullableTemplateItemVariablesSchemaInner) Get() *TemplateItemVariablesSchemaInner {
   256  	return v.value
   257  }
   258  
   259  func (v *NullableTemplateItemVariablesSchemaInner) Set(val *TemplateItemVariablesSchemaInner) {
   260  	v.value = val
   261  	v.isSet = true
   262  }
   263  
   264  func (v NullableTemplateItemVariablesSchemaInner) IsSet() bool {
   265  	return v.isSet
   266  }
   267  
   268  func (v *NullableTemplateItemVariablesSchemaInner) Unset() {
   269  	v.value = nil
   270  	v.isSet = false
   271  }
   272  
   273  func NewNullableTemplateItemVariablesSchemaInner(val *TemplateItemVariablesSchemaInner) *NullableTemplateItemVariablesSchemaInner {
   274  	return &NullableTemplateItemVariablesSchemaInner{value: val, isSet: true}
   275  }
   276  
   277  func (v NullableTemplateItemVariablesSchemaInner) MarshalJSON() ([]byte, error) {
   278  	return json.Marshal(v.value)
   279  }
   280  
   281  func (v *NullableTemplateItemVariablesSchemaInner) UnmarshalJSON(src []byte) error {
   282  	v.isSet = true
   283  	return json.Unmarshal(src, &v.value)
   284  }