model-registry/pkg/openapi/model_artifact.go

284 lines
7.3 KiB
Go

/*
Model Registry REST API
REST API for Model Registry to create and manage ML model metadata
API version: v1alpha3
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package openapi
import (
"encoding/json"
"fmt"
)
// Artifact - A metadata Artifact Entity.
type Artifact struct {
DataSet *DataSet
DocArtifact *DocArtifact
Metric *Metric
ModelArtifact *ModelArtifact
Parameter *Parameter
}
// DataSetAsArtifact is a convenience function that returns DataSet wrapped in Artifact
func DataSetAsArtifact(v *DataSet) Artifact {
return Artifact{
DataSet: v,
}
}
// DocArtifactAsArtifact is a convenience function that returns DocArtifact wrapped in Artifact
func DocArtifactAsArtifact(v *DocArtifact) Artifact {
return Artifact{
DocArtifact: v,
}
}
// MetricAsArtifact is a convenience function that returns Metric wrapped in Artifact
func MetricAsArtifact(v *Metric) Artifact {
return Artifact{
Metric: v,
}
}
// ModelArtifactAsArtifact is a convenience function that returns ModelArtifact wrapped in Artifact
func ModelArtifactAsArtifact(v *ModelArtifact) Artifact {
return Artifact{
ModelArtifact: v,
}
}
// ParameterAsArtifact is a convenience function that returns Parameter wrapped in Artifact
func ParameterAsArtifact(v *Parameter) Artifact {
return Artifact{
Parameter: v,
}
}
// Unmarshal JSON data into one of the pointers in the struct
func (dst *Artifact) UnmarshalJSON(data []byte) error {
var err error
// use discriminator value to speed up the lookup
var jsonDict map[string]interface{}
err = newStrictDecoder(data).Decode(&jsonDict)
if err != nil {
return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup")
}
// check if the discriminator value is 'DataSet'
if jsonDict["artifactType"] == "DataSet" {
// try to unmarshal JSON data into DataSet
err = json.Unmarshal(data, &dst.DataSet)
if err == nil {
return nil // data stored in dst.DataSet, return on the first match
} else {
dst.DataSet = nil
return fmt.Errorf("failed to unmarshal Artifact as DataSet: %s", err.Error())
}
}
// check if the discriminator value is 'DocArtifact'
if jsonDict["artifactType"] == "DocArtifact" {
// try to unmarshal JSON data into DocArtifact
err = json.Unmarshal(data, &dst.DocArtifact)
if err == nil {
return nil // data stored in dst.DocArtifact, return on the first match
} else {
dst.DocArtifact = nil
return fmt.Errorf("failed to unmarshal Artifact as DocArtifact: %s", err.Error())
}
}
// check if the discriminator value is 'Metric'
if jsonDict["artifactType"] == "Metric" {
// try to unmarshal JSON data into Metric
err = json.Unmarshal(data, &dst.Metric)
if err == nil {
return nil // data stored in dst.Metric, return on the first match
} else {
dst.Metric = nil
return fmt.Errorf("failed to unmarshal Artifact as Metric: %s", err.Error())
}
}
// check if the discriminator value is 'ModelArtifact'
if jsonDict["artifactType"] == "ModelArtifact" {
// try to unmarshal JSON data into ModelArtifact
err = json.Unmarshal(data, &dst.ModelArtifact)
if err == nil {
return nil // data stored in dst.ModelArtifact, return on the first match
} else {
dst.ModelArtifact = nil
return fmt.Errorf("failed to unmarshal Artifact as ModelArtifact: %s", err.Error())
}
}
// check if the discriminator value is 'Parameter'
if jsonDict["artifactType"] == "Parameter" {
// try to unmarshal JSON data into Parameter
err = json.Unmarshal(data, &dst.Parameter)
if err == nil {
return nil // data stored in dst.Parameter, return on the first match
} else {
dst.Parameter = nil
return fmt.Errorf("failed to unmarshal Artifact as Parameter: %s", err.Error())
}
}
// check if the discriminator value is 'dataset-artifact'
if jsonDict["artifactType"] == "dataset-artifact" {
// try to unmarshal JSON data into DataSet
err = json.Unmarshal(data, &dst.DataSet)
if err == nil {
return nil // data stored in dst.DataSet, return on the first match
} else {
dst.DataSet = nil
return fmt.Errorf("failed to unmarshal Artifact as DataSet: %s", err.Error())
}
}
// check if the discriminator value is 'doc-artifact'
if jsonDict["artifactType"] == "doc-artifact" {
// try to unmarshal JSON data into DocArtifact
err = json.Unmarshal(data, &dst.DocArtifact)
if err == nil {
return nil // data stored in dst.DocArtifact, return on the first match
} else {
dst.DocArtifact = nil
return fmt.Errorf("failed to unmarshal Artifact as DocArtifact: %s", err.Error())
}
}
// check if the discriminator value is 'metric'
if jsonDict["artifactType"] == "metric" {
// try to unmarshal JSON data into Metric
err = json.Unmarshal(data, &dst.Metric)
if err == nil {
return nil // data stored in dst.Metric, return on the first match
} else {
dst.Metric = nil
return fmt.Errorf("failed to unmarshal Artifact as Metric: %s", err.Error())
}
}
// check if the discriminator value is 'model-artifact'
if jsonDict["artifactType"] == "model-artifact" {
// try to unmarshal JSON data into ModelArtifact
err = json.Unmarshal(data, &dst.ModelArtifact)
if err == nil {
return nil // data stored in dst.ModelArtifact, return on the first match
} else {
dst.ModelArtifact = nil
return fmt.Errorf("failed to unmarshal Artifact as ModelArtifact: %s", err.Error())
}
}
// check if the discriminator value is 'parameter'
if jsonDict["artifactType"] == "parameter" {
// try to unmarshal JSON data into Parameter
err = json.Unmarshal(data, &dst.Parameter)
if err == nil {
return nil // data stored in dst.Parameter, return on the first match
} else {
dst.Parameter = nil
return fmt.Errorf("failed to unmarshal Artifact as Parameter: %s", err.Error())
}
}
return nil
}
// Marshal data from the first non-nil pointers in the struct to JSON
func (src Artifact) MarshalJSON() ([]byte, error) {
if src.DataSet != nil {
return json.Marshal(&src.DataSet)
}
if src.DocArtifact != nil {
return json.Marshal(&src.DocArtifact)
}
if src.Metric != nil {
return json.Marshal(&src.Metric)
}
if src.ModelArtifact != nil {
return json.Marshal(&src.ModelArtifact)
}
if src.Parameter != nil {
return json.Marshal(&src.Parameter)
}
return nil, nil // no data in oneOf schemas
}
// Get the actual instance
func (obj *Artifact) GetActualInstance() interface{} {
if obj == nil {
return nil
}
if obj.DataSet != nil {
return obj.DataSet
}
if obj.DocArtifact != nil {
return obj.DocArtifact
}
if obj.Metric != nil {
return obj.Metric
}
if obj.ModelArtifact != nil {
return obj.ModelArtifact
}
if obj.Parameter != nil {
return obj.Parameter
}
// all schemas are nil
return nil
}
type NullableArtifact struct {
value *Artifact
isSet bool
}
func (v NullableArtifact) Get() *Artifact {
return v.value
}
func (v *NullableArtifact) Set(val *Artifact) {
v.value = val
v.isSet = true
}
func (v NullableArtifact) IsSet() bool {
return v.isSet
}
func (v *NullableArtifact) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableArtifact(val *Artifact) *NullableArtifact {
return &NullableArtifact{value: val, isSet: true}
}
func (v NullableArtifact) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableArtifact) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}