mirror of
https://github.com/rancher/rke.git
synced 2025-09-26 07:25:09 +00:00
Update vendor
This commit is contained in:
192
vendor/k8s.io/kube-openapi/pkg/common/common.go
generated
vendored
Normal file
192
vendor/k8s.io/kube-openapi/pkg/common/common.go
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
"github.com/go-openapi/spec"
|
||||
)
|
||||
|
||||
const (
|
||||
// TODO: Make this configurable.
|
||||
ExtensionPrefix = "x-kubernetes-"
|
||||
ExtensionV2Schema = ExtensionPrefix + "v2-schema"
|
||||
)
|
||||
|
||||
// OpenAPIDefinition describes single type. Normally these definitions are auto-generated using gen-openapi.
|
||||
type OpenAPIDefinition struct {
|
||||
Schema spec.Schema
|
||||
Dependencies []string
|
||||
}
|
||||
|
||||
type ReferenceCallback func(path string) spec.Ref
|
||||
|
||||
// GetOpenAPIDefinitions is collection of all definitions.
|
||||
type GetOpenAPIDefinitions func(ReferenceCallback) map[string]OpenAPIDefinition
|
||||
|
||||
// OpenAPIDefinitionGetter gets openAPI definitions for a given type. If a type implements this interface,
|
||||
// the definition returned by it will be used, otherwise the auto-generated definitions will be used. See
|
||||
// GetOpenAPITypeFormat for more information about trade-offs of using this interface or GetOpenAPITypeFormat method when
|
||||
// possible.
|
||||
type OpenAPIDefinitionGetter interface {
|
||||
OpenAPIDefinition() *OpenAPIDefinition
|
||||
}
|
||||
|
||||
type OpenAPIV3DefinitionGetter interface {
|
||||
OpenAPIV3Definition() *OpenAPIDefinition
|
||||
}
|
||||
|
||||
type PathHandler interface {
|
||||
Handle(path string, handler http.Handler)
|
||||
}
|
||||
|
||||
// Config is set of configuration for openAPI spec generation.
|
||||
type Config struct {
|
||||
// List of supported protocols such as https, http, etc.
|
||||
ProtocolList []string
|
||||
|
||||
// Info is general information about the API.
|
||||
Info *spec.Info
|
||||
|
||||
// DefaultResponse will be used if an operation does not have any responses listed. It
|
||||
// will show up as ... "responses" : {"default" : $DefaultResponse} in the spec.
|
||||
DefaultResponse *spec.Response
|
||||
|
||||
// ResponseDefinitions will be added to "responses" under the top-level swagger object. This is an object
|
||||
// that holds responses definitions that can be used across operations. This property does not define
|
||||
// global responses for all operations. For more info please refer:
|
||||
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields
|
||||
ResponseDefinitions map[string]spec.Response
|
||||
|
||||
// CommonResponses will be added as a response to all operation specs. This is a good place to add common
|
||||
// responses such as authorization failed.
|
||||
CommonResponses map[int]spec.Response
|
||||
|
||||
// List of webservice's path prefixes to ignore
|
||||
IgnorePrefixes []string
|
||||
|
||||
// OpenAPIDefinitions should provide definition for all models used by routes. Failure to provide this map
|
||||
// or any of the models will result in spec generation failure.
|
||||
GetDefinitions GetOpenAPIDefinitions
|
||||
|
||||
// GetOperationIDAndTags returns operation id and tags for a restful route. It is an optional function to customize operation IDs.
|
||||
GetOperationIDAndTags func(r *restful.Route) (string, []string, error)
|
||||
|
||||
// GetDefinitionName returns a friendly name for a definition base on the serving path. parameter `name` is the full name of the definition.
|
||||
// It is an optional function to customize model names.
|
||||
GetDefinitionName func(name string) (string, spec.Extensions)
|
||||
|
||||
// PostProcessSpec runs after the spec is ready to serve. It allows a final modification to the spec before serving.
|
||||
PostProcessSpec func(*spec.Swagger) (*spec.Swagger, error)
|
||||
|
||||
// SecurityDefinitions is list of all security definitions for OpenAPI service. If this is not nil, the user of config
|
||||
// is responsible to provide DefaultSecurity and (maybe) add unauthorized response to CommonResponses.
|
||||
SecurityDefinitions *spec.SecurityDefinitions
|
||||
|
||||
// DefaultSecurity for all operations. This will pass as spec.SwaggerProps.Security to OpenAPI.
|
||||
// For most cases, this will be list of acceptable definitions in SecurityDefinitions.
|
||||
DefaultSecurity []map[string][]string
|
||||
}
|
||||
|
||||
var schemaTypeFormatMap = map[string][]string{
|
||||
"uint": {"integer", "int32"},
|
||||
"uint8": {"integer", "byte"},
|
||||
"uint16": {"integer", "int32"},
|
||||
"uint32": {"integer", "int64"},
|
||||
"uint64": {"integer", "int64"},
|
||||
"int": {"integer", "int32"},
|
||||
"int8": {"integer", "byte"},
|
||||
"int16": {"integer", "int32"},
|
||||
"int32": {"integer", "int32"},
|
||||
"int64": {"integer", "int64"},
|
||||
"byte": {"integer", "byte"},
|
||||
"float64": {"number", "double"},
|
||||
"float32": {"number", "float"},
|
||||
"bool": {"boolean", ""},
|
||||
"time.Time": {"string", "date-time"},
|
||||
"string": {"string", ""},
|
||||
"integer": {"integer", ""},
|
||||
"number": {"number", ""},
|
||||
"boolean": {"boolean", ""},
|
||||
"[]byte": {"string", "byte"}, // base64 encoded characters
|
||||
"interface{}": {"object", ""},
|
||||
}
|
||||
|
||||
// This function is a reference for converting go (or any custom type) to a simple open API type,format pair. There are
|
||||
// two ways to customize spec for a type. If you add it here, a type will be converted to a simple type and the type
|
||||
// comment (the comment that is added before type definition) will be lost. The spec will still have the property
|
||||
// comment. The second way is to implement OpenAPIDefinitionGetter interface. That function can customize the spec (so
|
||||
// the spec does not need to be simple type,format) or can even return a simple type,format (e.g. IntOrString). For simple
|
||||
// type formats, the benefit of adding OpenAPIDefinitionGetter interface is to keep both type and property documentation.
|
||||
// Example:
|
||||
// type Sample struct {
|
||||
// ...
|
||||
// // port of the server
|
||||
// port IntOrString
|
||||
// ...
|
||||
// }
|
||||
// // IntOrString documentation...
|
||||
// type IntOrString { ... }
|
||||
//
|
||||
// Adding IntOrString to this function:
|
||||
// "port" : {
|
||||
// format: "string",
|
||||
// type: "int-or-string",
|
||||
// Description: "port of the server"
|
||||
// }
|
||||
//
|
||||
// Implement OpenAPIDefinitionGetter for IntOrString:
|
||||
//
|
||||
// "port" : {
|
||||
// $Ref: "#/definitions/IntOrString"
|
||||
// Description: "port of the server"
|
||||
// }
|
||||
// ...
|
||||
// definitions:
|
||||
// {
|
||||
// "IntOrString": {
|
||||
// format: "string",
|
||||
// type: "int-or-string",
|
||||
// Description: "IntOrString documentation..." // new
|
||||
// }
|
||||
// }
|
||||
//
|
||||
func GetOpenAPITypeFormat(typeName string) (string, string) {
|
||||
mapped, ok := schemaTypeFormatMap[typeName]
|
||||
if !ok {
|
||||
return "", ""
|
||||
}
|
||||
return mapped[0], mapped[1]
|
||||
}
|
||||
|
||||
func EscapeJsonPointer(p string) string {
|
||||
// Escaping reference name using rfc6901
|
||||
p = strings.Replace(p, "~", "~0", -1)
|
||||
p = strings.Replace(p, "/", "~1", -1)
|
||||
return p
|
||||
}
|
||||
|
||||
func EmbedOpenAPIDefinitionIntoV2Extension(main OpenAPIDefinition, embedded OpenAPIDefinition) OpenAPIDefinition {
|
||||
if main.Schema.Extensions == nil {
|
||||
main.Schema.Extensions = make(map[string]interface{})
|
||||
}
|
||||
main.Schema.Extensions[ExtensionV2Schema] = embedded.Schema
|
||||
return main
|
||||
}
|
19
vendor/k8s.io/kube-openapi/pkg/common/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kube-openapi/pkg/common/doc.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// package common holds shared code and types between open API code
|
||||
// generator and spec generator.
|
||||
package common
|
79
vendor/k8s.io/kube-openapi/pkg/util/proto/validation/errors.go
generated
vendored
Normal file
79
vendor/k8s.io/kube-openapi/pkg/util/proto/validation/errors.go
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type errors struct {
|
||||
errors []error
|
||||
}
|
||||
|
||||
func (e *errors) Errors() []error {
|
||||
return e.errors
|
||||
}
|
||||
|
||||
func (e *errors) AppendErrors(err ...error) {
|
||||
e.errors = append(e.errors, err...)
|
||||
}
|
||||
|
||||
type ValidationError struct {
|
||||
Path string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e ValidationError) Error() string {
|
||||
return fmt.Sprintf("ValidationError(%s): %v", e.Path, e.Err)
|
||||
}
|
||||
|
||||
type InvalidTypeError struct {
|
||||
Path string
|
||||
Expected string
|
||||
Actual string
|
||||
}
|
||||
|
||||
func (e InvalidTypeError) Error() string {
|
||||
return fmt.Sprintf("invalid type for %s: got %q, expected %q", e.Path, e.Actual, e.Expected)
|
||||
}
|
||||
|
||||
type MissingRequiredFieldError struct {
|
||||
Path string
|
||||
Field string
|
||||
}
|
||||
|
||||
func (e MissingRequiredFieldError) Error() string {
|
||||
return fmt.Sprintf("missing required field %q in %s", e.Field, e.Path)
|
||||
}
|
||||
|
||||
type UnknownFieldError struct {
|
||||
Path string
|
||||
Field string
|
||||
}
|
||||
|
||||
func (e UnknownFieldError) Error() string {
|
||||
return fmt.Sprintf("unknown field %q in %s", e.Field, e.Path)
|
||||
}
|
||||
|
||||
type InvalidObjectTypeError struct {
|
||||
Path string
|
||||
Type string
|
||||
}
|
||||
|
||||
func (e InvalidObjectTypeError) Error() string {
|
||||
return fmt.Sprintf("unknown object type %q in %s", e.Type, e.Path)
|
||||
}
|
299
vendor/k8s.io/kube-openapi/pkg/util/proto/validation/types.go
generated
vendored
Normal file
299
vendor/k8s.io/kube-openapi/pkg/util/proto/validation/types.go
generated
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
|
||||
"k8s.io/kube-openapi/pkg/util/proto"
|
||||
)
|
||||
|
||||
type validationItem interface {
|
||||
proto.SchemaVisitor
|
||||
|
||||
Errors() []error
|
||||
Path() *proto.Path
|
||||
}
|
||||
|
||||
type baseItem struct {
|
||||
errors errors
|
||||
path proto.Path
|
||||
}
|
||||
|
||||
// Errors returns the list of errors found for this item.
|
||||
func (item *baseItem) Errors() []error {
|
||||
return item.errors.Errors()
|
||||
}
|
||||
|
||||
// AddValidationError wraps the given error into a ValidationError and
|
||||
// attaches it to this item.
|
||||
func (item *baseItem) AddValidationError(err error) {
|
||||
item.errors.AppendErrors(ValidationError{Path: item.path.String(), Err: err})
|
||||
}
|
||||
|
||||
// AddError adds a regular (non-validation related) error to the list.
|
||||
func (item *baseItem) AddError(err error) {
|
||||
item.errors.AppendErrors(err)
|
||||
}
|
||||
|
||||
// CopyErrors adds a list of errors to this item. This is useful to copy
|
||||
// errors from subitems.
|
||||
func (item *baseItem) CopyErrors(errs []error) {
|
||||
item.errors.AppendErrors(errs...)
|
||||
}
|
||||
|
||||
// Path returns the path of this item, helps print useful errors.
|
||||
func (item *baseItem) Path() *proto.Path {
|
||||
return &item.path
|
||||
}
|
||||
|
||||
// mapItem represents a map entry in the yaml.
|
||||
type mapItem struct {
|
||||
baseItem
|
||||
|
||||
Map map[string]interface{}
|
||||
}
|
||||
|
||||
func (item *mapItem) sortedKeys() []string {
|
||||
sortedKeys := []string{}
|
||||
for key := range item.Map {
|
||||
sortedKeys = append(sortedKeys, key)
|
||||
}
|
||||
sort.Strings(sortedKeys)
|
||||
return sortedKeys
|
||||
}
|
||||
|
||||
var _ validationItem = &mapItem{}
|
||||
|
||||
func (item *mapItem) VisitPrimitive(schema *proto.Primitive) {
|
||||
item.AddValidationError(InvalidTypeError{Path: schema.GetPath().String(), Expected: schema.Type, Actual: "map"})
|
||||
}
|
||||
|
||||
func (item *mapItem) VisitArray(schema *proto.Array) {
|
||||
item.AddValidationError(InvalidTypeError{Path: schema.GetPath().String(), Expected: "array", Actual: "map"})
|
||||
}
|
||||
|
||||
func (item *mapItem) VisitMap(schema *proto.Map) {
|
||||
for _, key := range item.sortedKeys() {
|
||||
subItem, err := itemFactory(item.Path().FieldPath(key), item.Map[key])
|
||||
if err != nil {
|
||||
item.AddError(err)
|
||||
continue
|
||||
}
|
||||
schema.SubType.Accept(subItem)
|
||||
item.CopyErrors(subItem.Errors())
|
||||
}
|
||||
}
|
||||
|
||||
func (item *mapItem) VisitKind(schema *proto.Kind) {
|
||||
// Verify each sub-field.
|
||||
for _, key := range item.sortedKeys() {
|
||||
if item.Map[key] == nil {
|
||||
continue
|
||||
}
|
||||
subItem, err := itemFactory(item.Path().FieldPath(key), item.Map[key])
|
||||
if err != nil {
|
||||
item.AddError(err)
|
||||
continue
|
||||
}
|
||||
if _, ok := schema.Fields[key]; !ok {
|
||||
item.AddValidationError(UnknownFieldError{Path: schema.GetPath().String(), Field: key})
|
||||
continue
|
||||
}
|
||||
schema.Fields[key].Accept(subItem)
|
||||
item.CopyErrors(subItem.Errors())
|
||||
}
|
||||
|
||||
// Verify that all required fields are present.
|
||||
for _, required := range schema.RequiredFields {
|
||||
if v, ok := item.Map[required]; !ok || v == nil {
|
||||
item.AddValidationError(MissingRequiredFieldError{Path: schema.GetPath().String(), Field: required})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (item *mapItem) VisitArbitrary(schema *proto.Arbitrary) {
|
||||
}
|
||||
|
||||
func (item *mapItem) VisitReference(schema proto.Reference) {
|
||||
// passthrough
|
||||
schema.SubSchema().Accept(item)
|
||||
}
|
||||
|
||||
// arrayItem represents a yaml array.
|
||||
type arrayItem struct {
|
||||
baseItem
|
||||
|
||||
Array []interface{}
|
||||
}
|
||||
|
||||
var _ validationItem = &arrayItem{}
|
||||
|
||||
func (item *arrayItem) VisitPrimitive(schema *proto.Primitive) {
|
||||
item.AddValidationError(InvalidTypeError{Path: schema.GetPath().String(), Expected: schema.Type, Actual: "array"})
|
||||
}
|
||||
|
||||
func (item *arrayItem) VisitArray(schema *proto.Array) {
|
||||
for i, v := range item.Array {
|
||||
path := item.Path().ArrayPath(i)
|
||||
if v == nil {
|
||||
item.AddValidationError(InvalidObjectTypeError{Type: "nil", Path: path.String()})
|
||||
continue
|
||||
}
|
||||
subItem, err := itemFactory(path, v)
|
||||
if err != nil {
|
||||
item.AddError(err)
|
||||
continue
|
||||
}
|
||||
schema.SubType.Accept(subItem)
|
||||
item.CopyErrors(subItem.Errors())
|
||||
}
|
||||
}
|
||||
|
||||
func (item *arrayItem) VisitMap(schema *proto.Map) {
|
||||
item.AddValidationError(InvalidTypeError{Path: schema.GetPath().String(), Expected: "map", Actual: "array"})
|
||||
}
|
||||
|
||||
func (item *arrayItem) VisitKind(schema *proto.Kind) {
|
||||
item.AddValidationError(InvalidTypeError{Path: schema.GetPath().String(), Expected: "map", Actual: "array"})
|
||||
}
|
||||
|
||||
func (item *arrayItem) VisitArbitrary(schema *proto.Arbitrary) {
|
||||
}
|
||||
|
||||
func (item *arrayItem) VisitReference(schema proto.Reference) {
|
||||
// passthrough
|
||||
schema.SubSchema().Accept(item)
|
||||
}
|
||||
|
||||
// primitiveItem represents a yaml value.
|
||||
type primitiveItem struct {
|
||||
baseItem
|
||||
|
||||
Value interface{}
|
||||
Kind string
|
||||
}
|
||||
|
||||
var _ validationItem = &primitiveItem{}
|
||||
|
||||
func (item *primitiveItem) VisitPrimitive(schema *proto.Primitive) {
|
||||
// Some types of primitives can match more than one (a number
|
||||
// can be a string, but not the other way around). Return from
|
||||
// the switch if we have a valid possible type conversion
|
||||
// NOTE(apelisse): This logic is blindly copied from the
|
||||
// existing swagger logic, and I'm not sure I agree with it.
|
||||
switch schema.Type {
|
||||
case proto.Boolean:
|
||||
switch item.Kind {
|
||||
case proto.Boolean:
|
||||
return
|
||||
}
|
||||
case proto.Integer:
|
||||
switch item.Kind {
|
||||
case proto.Integer, proto.Number:
|
||||
return
|
||||
}
|
||||
case proto.Number:
|
||||
switch item.Kind {
|
||||
case proto.Number:
|
||||
return
|
||||
}
|
||||
case proto.String:
|
||||
return
|
||||
}
|
||||
// TODO(wrong): this misses "null"
|
||||
|
||||
item.AddValidationError(InvalidTypeError{Path: schema.GetPath().String(), Expected: schema.Type, Actual: item.Kind})
|
||||
}
|
||||
|
||||
func (item *primitiveItem) VisitArray(schema *proto.Array) {
|
||||
item.AddValidationError(InvalidTypeError{Path: schema.GetPath().String(), Expected: "array", Actual: item.Kind})
|
||||
}
|
||||
|
||||
func (item *primitiveItem) VisitMap(schema *proto.Map) {
|
||||
item.AddValidationError(InvalidTypeError{Path: schema.GetPath().String(), Expected: "map", Actual: item.Kind})
|
||||
}
|
||||
|
||||
func (item *primitiveItem) VisitKind(schema *proto.Kind) {
|
||||
item.AddValidationError(InvalidTypeError{Path: schema.GetPath().String(), Expected: "map", Actual: item.Kind})
|
||||
}
|
||||
|
||||
func (item *primitiveItem) VisitArbitrary(schema *proto.Arbitrary) {
|
||||
}
|
||||
|
||||
func (item *primitiveItem) VisitReference(schema proto.Reference) {
|
||||
// passthrough
|
||||
schema.SubSchema().Accept(item)
|
||||
}
|
||||
|
||||
// itemFactory creates the relevant item type/visitor based on the current yaml type.
|
||||
func itemFactory(path proto.Path, v interface{}) (validationItem, error) {
|
||||
// We need to special case for no-type fields in yaml (e.g. empty item in list)
|
||||
if v == nil {
|
||||
return nil, InvalidObjectTypeError{Type: "nil", Path: path.String()}
|
||||
}
|
||||
kind := reflect.TypeOf(v).Kind()
|
||||
switch kind {
|
||||
case reflect.Bool:
|
||||
return &primitiveItem{
|
||||
baseItem: baseItem{path: path},
|
||||
Value: v,
|
||||
Kind: proto.Boolean,
|
||||
}, nil
|
||||
case reflect.Int,
|
||||
reflect.Int8,
|
||||
reflect.Int16,
|
||||
reflect.Int32,
|
||||
reflect.Int64,
|
||||
reflect.Uint,
|
||||
reflect.Uint8,
|
||||
reflect.Uint16,
|
||||
reflect.Uint32,
|
||||
reflect.Uint64:
|
||||
return &primitiveItem{
|
||||
baseItem: baseItem{path: path},
|
||||
Value: v,
|
||||
Kind: proto.Integer,
|
||||
}, nil
|
||||
case reflect.Float32,
|
||||
reflect.Float64:
|
||||
return &primitiveItem{
|
||||
baseItem: baseItem{path: path},
|
||||
Value: v,
|
||||
Kind: proto.Number,
|
||||
}, nil
|
||||
case reflect.String:
|
||||
return &primitiveItem{
|
||||
baseItem: baseItem{path: path},
|
||||
Value: v,
|
||||
Kind: proto.String,
|
||||
}, nil
|
||||
case reflect.Array,
|
||||
reflect.Slice:
|
||||
return &arrayItem{
|
||||
baseItem: baseItem{path: path},
|
||||
Array: v.([]interface{}),
|
||||
}, nil
|
||||
case reflect.Map:
|
||||
return &mapItem{
|
||||
baseItem: baseItem{path: path},
|
||||
Map: v.(map[string]interface{}),
|
||||
}, nil
|
||||
}
|
||||
return nil, InvalidObjectTypeError{Type: kind.String(), Path: path.String()}
|
||||
}
|
30
vendor/k8s.io/kube-openapi/pkg/util/proto/validation/validation.go
generated
vendored
Normal file
30
vendor/k8s.io/kube-openapi/pkg/util/proto/validation/validation.go
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"k8s.io/kube-openapi/pkg/util/proto"
|
||||
)
|
||||
|
||||
func ValidateModel(obj interface{}, schema proto.Schema, name string) []error {
|
||||
rootValidation, err := itemFactory(proto.NewPath(name), obj)
|
||||
if err != nil {
|
||||
return []error{err}
|
||||
}
|
||||
schema.Accept(rootValidation)
|
||||
return rootValidation.Errors()
|
||||
}
|
Reference in New Issue
Block a user