...

Source file src/github.com/sigstore/rekor/pkg/generated/models/intoto.go

Documentation: github.com/sigstore/rekor/pkg/generated/models

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  //
     4  // Copyright 2021 The Sigstore Authors.
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  //
    18  
    19  package models
    20  
    21  // This file was generated by the swagger tool.
    22  // Editing this file might prove futile when you re-run the swagger generate command
    23  
    24  import (
    25  	"bytes"
    26  	"context"
    27  	"encoding/json"
    28  
    29  	"github.com/go-openapi/errors"
    30  	"github.com/go-openapi/strfmt"
    31  	"github.com/go-openapi/swag"
    32  	"github.com/go-openapi/validate"
    33  )
    34  
    35  // Intoto Intoto object
    36  //
    37  // swagger:model intoto
    38  type Intoto struct {
    39  
    40  	// api version
    41  	// Required: true
    42  	// Pattern: ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
    43  	APIVersion *string `json:"apiVersion"`
    44  
    45  	// spec
    46  	// Required: true
    47  	Spec IntotoSchema `json:"spec"`
    48  }
    49  
    50  // Kind gets the kind of this subtype
    51  func (m *Intoto) Kind() string {
    52  	return "intoto"
    53  }
    54  
    55  // SetKind sets the kind of this subtype
    56  func (m *Intoto) SetKind(val string) {
    57  }
    58  
    59  // UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure
    60  func (m *Intoto) UnmarshalJSON(raw []byte) error {
    61  	var data struct {
    62  
    63  		// api version
    64  		// Required: true
    65  		// Pattern: ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
    66  		APIVersion *string `json:"apiVersion"`
    67  
    68  		// spec
    69  		// Required: true
    70  		Spec IntotoSchema `json:"spec"`
    71  	}
    72  	buf := bytes.NewBuffer(raw)
    73  	dec := json.NewDecoder(buf)
    74  	dec.UseNumber()
    75  
    76  	if err := dec.Decode(&data); err != nil {
    77  		return err
    78  	}
    79  
    80  	var base struct {
    81  		/* Just the base type fields. Used for unmashalling polymorphic types.*/
    82  
    83  		Kind string `json:"kind"`
    84  	}
    85  	buf = bytes.NewBuffer(raw)
    86  	dec = json.NewDecoder(buf)
    87  	dec.UseNumber()
    88  
    89  	if err := dec.Decode(&base); err != nil {
    90  		return err
    91  	}
    92  
    93  	var result Intoto
    94  
    95  	if base.Kind != result.Kind() {
    96  		/* Not the type we're looking for. */
    97  		return errors.New(422, "invalid kind value: %q", base.Kind)
    98  	}
    99  
   100  	result.APIVersion = data.APIVersion
   101  	result.Spec = data.Spec
   102  
   103  	*m = result
   104  
   105  	return nil
   106  }
   107  
   108  // MarshalJSON marshals this object with a polymorphic type to a JSON structure
   109  func (m Intoto) MarshalJSON() ([]byte, error) {
   110  	var b1, b2, b3 []byte
   111  	var err error
   112  	b1, err = json.Marshal(struct {
   113  
   114  		// api version
   115  		// Required: true
   116  		// Pattern: ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
   117  		APIVersion *string `json:"apiVersion"`
   118  
   119  		// spec
   120  		// Required: true
   121  		Spec IntotoSchema `json:"spec"`
   122  	}{
   123  
   124  		APIVersion: m.APIVersion,
   125  
   126  		Spec: m.Spec,
   127  	})
   128  	if err != nil {
   129  		return nil, err
   130  	}
   131  	b2, err = json.Marshal(struct {
   132  		Kind string `json:"kind"`
   133  	}{
   134  
   135  		Kind: m.Kind(),
   136  	})
   137  	if err != nil {
   138  		return nil, err
   139  	}
   140  
   141  	return swag.ConcatJSON(b1, b2, b3), nil
   142  }
   143  
   144  // Validate validates this intoto
   145  func (m *Intoto) Validate(formats strfmt.Registry) error {
   146  	var res []error
   147  
   148  	if err := m.validateAPIVersion(formats); err != nil {
   149  		res = append(res, err)
   150  	}
   151  
   152  	if err := m.validateSpec(formats); err != nil {
   153  		res = append(res, err)
   154  	}
   155  
   156  	if len(res) > 0 {
   157  		return errors.CompositeValidationError(res...)
   158  	}
   159  	return nil
   160  }
   161  
   162  func (m *Intoto) validateAPIVersion(formats strfmt.Registry) error {
   163  
   164  	if err := validate.Required("apiVersion", "body", m.APIVersion); err != nil {
   165  		return err
   166  	}
   167  
   168  	if err := validate.Pattern("apiVersion", "body", *m.APIVersion, `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`); err != nil {
   169  		return err
   170  	}
   171  
   172  	return nil
   173  }
   174  
   175  func (m *Intoto) validateSpec(formats strfmt.Registry) error {
   176  
   177  	if m.Spec == nil {
   178  		return errors.Required("spec", "body", nil)
   179  	}
   180  
   181  	return nil
   182  }
   183  
   184  // ContextValidate validate this intoto based on the context it is used
   185  func (m *Intoto) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   186  	var res []error
   187  
   188  	if len(res) > 0 {
   189  		return errors.CompositeValidationError(res...)
   190  	}
   191  	return nil
   192  }
   193  
   194  // MarshalBinary interface implementation
   195  func (m *Intoto) MarshalBinary() ([]byte, error) {
   196  	if m == nil {
   197  		return nil, nil
   198  	}
   199  	return swag.WriteJSON(m)
   200  }
   201  
   202  // UnmarshalBinary interface implementation
   203  func (m *Intoto) UnmarshalBinary(b []byte) error {
   204  	var res Intoto
   205  	if err := swag.ReadJSON(b, &res); err != nil {
   206  		return err
   207  	}
   208  	*m = res
   209  	return nil
   210  }
   211  

View as plain text