Commit 6ba271b9 authored by mbohlool's avatar mbohlool

Customize OpenAPI definition types

customize intstr, unversioned.time, and quantity OpenAPI definitions.
parent 54fee8c2
...@@ -27,7 +27,9 @@ import ( ...@@ -27,7 +27,9 @@ import (
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
"github.com/go-openapi/spec"
inf "gopkg.in/inf.v0" inf "gopkg.in/inf.v0"
"k8s.io/kubernetes/cmd/libs/go2idl/openapi-gen/generators/common"
) )
// Quantity is a fixed-point representation of a number. // Quantity is a fixed-point representation of a number.
...@@ -395,6 +397,18 @@ func (q Quantity) DeepCopy() Quantity { ...@@ -395,6 +397,18 @@ func (q Quantity) DeepCopy() Quantity {
return q return q
} }
// OpenAPIDefinition returns openAPI definition for this type.
func (_ Quantity) OpenAPIDefinition() common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "",
},
},
}
}
// CanonicalizeBytes returns the canonical form of q and its suffix (see comment on Quantity). // CanonicalizeBytes returns the canonical form of q and its suffix (see comment on Quantity).
// //
// Note about BinarySI: // Note about BinarySI:
......
...@@ -20,6 +20,9 @@ import ( ...@@ -20,6 +20,9 @@ import (
"encoding/json" "encoding/json"
"time" "time"
"k8s.io/kubernetes/cmd/libs/go2idl/openapi-gen/generators/common"
"github.com/go-openapi/spec"
"github.com/google/gofuzz" "github.com/google/gofuzz"
) )
...@@ -142,6 +145,17 @@ func (t Time) MarshalJSON() ([]byte, error) { ...@@ -142,6 +145,17 @@ func (t Time) MarshalJSON() ([]byte, error) {
return json.Marshal(t.UTC().Format(time.RFC3339)) return json.Marshal(t.UTC().Format(time.RFC3339))
} }
func (_ Time) OpenAPIDefinition() common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "date-time",
},
},
}
}
// MarshalQueryParameter converts to a URL query parameter value // MarshalQueryParameter converts to a URL query parameter value
func (t Time) MarshalQueryParameter() (string, error) { func (t Time) MarshalQueryParameter() (string, error) {
if t.IsZero() { if t.IsZero() {
......
...@@ -23,6 +23,9 @@ import ( ...@@ -23,6 +23,9 @@ import (
"strconv" "strconv"
"strings" "strings"
"k8s.io/kubernetes/cmd/libs/go2idl/openapi-gen/generators/common"
"github.com/go-openapi/spec"
"github.com/google/gofuzz" "github.com/google/gofuzz"
) )
...@@ -34,6 +37,7 @@ import ( ...@@ -34,6 +37,7 @@ import (
// //
// +protobuf=true // +protobuf=true
// +protobuf.options.(gogoproto.goproto_stringer)=false // +protobuf.options.(gogoproto.goproto_stringer)=false
// +k8s:openapi-gen=true
type IntOrString struct { type IntOrString struct {
Type Type `protobuf:"varint,1,opt,name=type,casttype=Type"` Type Type `protobuf:"varint,1,opt,name=type,casttype=Type"`
IntVal int32 `protobuf:"varint,2,opt,name=intVal"` IntVal int32 `protobuf:"varint,2,opt,name=intVal"`
...@@ -101,6 +105,17 @@ func (intstr IntOrString) MarshalJSON() ([]byte, error) { ...@@ -101,6 +105,17 @@ func (intstr IntOrString) MarshalJSON() ([]byte, error) {
} }
} }
func (_ IntOrString) OpenAPIDefinition() common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "int-or-string",
},
},
}
}
func (intstr *IntOrString) Fuzz(c fuzz.Continue) { func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
if intstr == nil { if intstr == nil {
return return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment