github.com/giantswarm/apiextensions/v2@v2.6.2/pkg/serialization/float.go (about)

     1  package serialization
     2  
     3  import (
     4  	"encoding/json"
     5  )
     6  
     7  // +kubebuilder:validation:Type=number
     8  // +kubebuilder:validation:Format=double
     9  // +k8s:openapi-gen=true
    10  type Float struct {
    11  	Value float64 `json:"-"`
    12  }
    13  
    14  // NewFloat returns a new Float object holding the given value.
    15  func NewFloat(value float64) Float {
    16  	return Float{
    17  		Value: value,
    18  	}
    19  }
    20  
    21  // UnmarshalJSON implements the json.Unmarshaller interface.
    22  func (f *Float) UnmarshalJSON(value []byte) error {
    23  	return json.Unmarshal(value, &f.Value)
    24  }
    25  
    26  // MarshalJSON implements the json.Marshaller interface.
    27  func (f Float) MarshalJSON() ([]byte, error) {
    28  	return json.Marshal(f.Value)
    29  }
    30  
    31  // OpenAPISchemaType is used by the kube-openapi generator when constructing
    32  // the OpenAPI spec of this type.
    33  //
    34  // See: https://github.com/kubernetes/kube-openapi/tree/master/pkg/generators
    35  func (Float) OpenAPISchemaType() []string { return []string{"number"} }
    36  
    37  // OpenAPISchemaFormat is used by the kube-openapi generator when constructing
    38  // the OpenAPI spec of this type.
    39  func (Float) OpenAPISchemaFormat() string { return "double" }