1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-07 10:10:06 +00:00

Add intOrString and dnsLabel types

This commit is contained in:
Darren Shepherd
2017-12-29 15:06:36 -07:00
parent 6c007d23ef
commit 162f6088af
4 changed files with 14 additions and 1 deletions

View File

@@ -74,6 +74,10 @@ func getTypeString(nullable bool, typeName string, schema *types.Schema, schemas
return "string" return "string"
case "enum": case "enum":
return "string" return "string"
case "intOrString":
return "intstr.IntOrString"
case "dnsLabel":
return "string"
default: default:
if schema != nil && schemas != nil { if schema != nil && schemas != nil {
otherSchema := schemas.Schema(&schema.Version, typeName) otherSchema := schemas.Schema(&schema.Version, typeName)

View File

@@ -5,6 +5,7 @@ var typeTemplate = `package client
{{- if .schema | hasGet }} {{- if .schema | hasGet }}
import ( import (
"github.com/rancher/norman/types" "github.com/rancher/norman/types"
"k8s.io/apimachinery/pkg/util/intstr"
) )
{{- end}} {{- end}}

View File

@@ -239,6 +239,14 @@ func (b *Builder) convert(fieldType string, value interface{}, op Operation) (in
return convert.ToString(value), nil return convert.ToString(value), nil
case "string": case "string":
return convert.ToString(value), nil return convert.ToString(value), nil
case "dnsLabel":
return convert.ToString(value), nil
case "intOrString":
num, err := convert.ToNumber(value)
if err == nil {
return num, nil
}
return convert.ToString(value), nil
case "base64": case "base64":
return convert.ToString(value), nil return convert.ToString(value), nil
case "reference": case "reference":

View File

@@ -423,7 +423,7 @@ func (s *Schemas) determineSchemaType(version *APIVersion, t reflect.Type) (stri
return "date", nil return "date", nil
} }
if t.Name() == "IntOrString" { if t.Name() == "IntOrString" {
return "string", nil return "intOrString", nil
} }
if t.Name() == "Quantity" { if t.Name() == "Quantity" {
return "string", nil return "string", nil