Update go dependencies for kubernetes 1.16.0
This commit is contained in:
parent
280920980d
commit
d7b530cb0a
510 changed files with 107206 additions and 52551 deletions
18
vendor/k8s.io/kube-openapi/pkg/common/common.go
generated
vendored
18
vendor/k8s.io/kube-openapi/pkg/common/common.go
generated
vendored
|
|
@ -24,6 +24,12 @@ import (
|
|||
"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
|
||||
|
|
@ -43,6 +49,10 @@ type OpenAPIDefinitionGetter interface {
|
|||
OpenAPIDefinition() *OpenAPIDefinition
|
||||
}
|
||||
|
||||
type OpenAPIV3DefinitionGetter interface {
|
||||
OpenAPIV3Definition() *OpenAPIDefinition
|
||||
}
|
||||
|
||||
type PathHandler interface {
|
||||
Handle(path string, handler http.Handler)
|
||||
}
|
||||
|
|
@ -172,3 +182,11 @@ func EscapeJsonPointer(p string) string {
|
|||
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
|
||||
}
|
||||
|
|
|
|||
1
vendor/k8s.io/kube-openapi/pkg/generators/api_linter.go
generated
vendored
1
vendor/k8s.io/kube-openapi/pkg/generators/api_linter.go
generated
vendored
|
|
@ -139,6 +139,7 @@ func newAPILinter() *apiLinter {
|
|||
rules: []APIRule{
|
||||
&rules.NamesMatch{},
|
||||
&rules.OmitEmptyMatchCase{},
|
||||
&rules.ListTypeMissing{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
86
vendor/k8s.io/kube-openapi/pkg/generators/openapi.go
generated
vendored
86
vendor/k8s.io/kube-openapi/pkg/generators/openapi.go
generated
vendored
|
|
@ -242,6 +242,16 @@ func methodReturnsValue(mt *types.Type, pkg, name string) bool {
|
|||
return r.Name.Name == name && r.Name.Package == pkg
|
||||
}
|
||||
|
||||
func hasOpenAPIV3DefinitionMethod(t *types.Type) bool {
|
||||
for mn, mt := range t.Methods {
|
||||
if mn != "OpenAPIV3Definition" {
|
||||
continue
|
||||
}
|
||||
return methodReturnsValue(mt, openAPICommonPackagePath, "OpenAPIDefinition")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func hasOpenAPIDefinitionMethod(t *types.Type) bool {
|
||||
for mn, mt := range t.Methods {
|
||||
if mn != "OpenAPIDefinition" {
|
||||
|
|
@ -304,9 +314,21 @@ func (g openAPITypeWriter) generateCall(t *types.Type) error {
|
|||
case types.Struct:
|
||||
args := argsFromType(t)
|
||||
g.Do("\"$.$\": ", t.Name)
|
||||
if hasOpenAPIDefinitionMethod(t) {
|
||||
|
||||
hasV2Definition := hasOpenAPIDefinitionMethod(t)
|
||||
hasV2DefinitionTypeAndFormat := hasOpenAPIDefinitionMethods(t)
|
||||
hasV3Definition := hasOpenAPIV3DefinitionMethod(t)
|
||||
|
||||
switch {
|
||||
case hasV2DefinitionTypeAndFormat:
|
||||
g.Do(nameTmpl+"(ref),\n", args)
|
||||
case hasV2Definition && hasV3Definition:
|
||||
g.Do("common.EmbedOpenAPIDefinitionIntoV2Extension($.type|raw${}.OpenAPIV3Definition(), $.type|raw${}.OpenAPIDefinition()),\n", args)
|
||||
case hasV2Definition:
|
||||
g.Do("$.type|raw${}.OpenAPIDefinition(),\n", args)
|
||||
} else {
|
||||
case hasV3Definition:
|
||||
g.Do("$.type|raw${}.OpenAPIV3Definition(),\n", args)
|
||||
default:
|
||||
g.Do(nameTmpl+"(ref),\n", args)
|
||||
}
|
||||
}
|
||||
|
|
@ -317,14 +339,30 @@ func (g openAPITypeWriter) generate(t *types.Type) error {
|
|||
// Only generate for struct type and ignore the rest
|
||||
switch t.Kind {
|
||||
case types.Struct:
|
||||
if hasOpenAPIDefinitionMethod(t) {
|
||||
hasV2Definition := hasOpenAPIDefinitionMethod(t)
|
||||
hasV2DefinitionTypeAndFormat := hasOpenAPIDefinitionMethods(t)
|
||||
hasV3Definition := hasOpenAPIV3DefinitionMethod(t)
|
||||
|
||||
if hasV2Definition || (hasV3Definition && !hasV2DefinitionTypeAndFormat) {
|
||||
// already invoked directly
|
||||
return nil
|
||||
}
|
||||
|
||||
args := argsFromType(t)
|
||||
g.Do("func "+nameTmpl+"(ref $.ReferenceCallback|raw$) $.OpenAPIDefinition|raw$ {\n", args)
|
||||
if hasOpenAPIDefinitionMethods(t) {
|
||||
switch {
|
||||
case hasV2DefinitionTypeAndFormat && hasV3Definition:
|
||||
g.Do("return common.EmbedOpenAPIDefinitionIntoV2Extension($.type|raw${}.OpenAPIV3Definition(), $.OpenAPIDefinition|raw${\n"+
|
||||
"Schema: spec.Schema{\n"+
|
||||
"SchemaProps: spec.SchemaProps{\n", args)
|
||||
g.generateDescription(t.CommentLines)
|
||||
g.Do("Type:$.type|raw${}.OpenAPISchemaType(),\n"+
|
||||
"Format:$.type|raw${}.OpenAPISchemaFormat(),\n"+
|
||||
"},\n"+
|
||||
"},\n"+
|
||||
"})\n}\n\n", args)
|
||||
return nil
|
||||
case hasV2DefinitionTypeAndFormat:
|
||||
g.Do("return $.OpenAPIDefinition|raw${\n"+
|
||||
"Schema: spec.Schema{\n"+
|
||||
"SchemaProps: spec.SchemaProps{\n", args)
|
||||
|
|
@ -397,11 +435,18 @@ func (g openAPITypeWriter) generateStructExtensions(t *types.Type) error {
|
|||
// Initially, we will only log struct extension errors.
|
||||
if len(errors) > 0 {
|
||||
for _, e := range errors {
|
||||
klog.V(2).Infof("[%s]: %s\n", t.String(), e)
|
||||
klog.Errorf("[%s]: %s\n", t.String(), e)
|
||||
}
|
||||
}
|
||||
unions, errors := parseUnions(t)
|
||||
if len(errors) > 0 {
|
||||
for _, e := range errors {
|
||||
klog.Errorf("[%s]: %s\n", t.String(), e)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(seans3): Validate struct extensions here.
|
||||
g.emitExtensions(extensions)
|
||||
g.emitExtensions(extensions, unions)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -416,13 +461,13 @@ func (g openAPITypeWriter) generateMemberExtensions(m *types.Member, parent *typ
|
|||
klog.V(2).Infof("%s %s\n", errorPrefix, e)
|
||||
}
|
||||
}
|
||||
g.emitExtensions(extensions)
|
||||
g.emitExtensions(extensions, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g openAPITypeWriter) emitExtensions(extensions []extension) {
|
||||
func (g openAPITypeWriter) emitExtensions(extensions []extension, unions []union) {
|
||||
// If any extensions exist, then emit code to create them.
|
||||
if len(extensions) == 0 {
|
||||
if len(extensions) == 0 && len(unions) == 0 {
|
||||
return
|
||||
}
|
||||
g.Do("VendorExtensible: spec.VendorExtensible{\nExtensions: spec.Extensions{\n", nil)
|
||||
|
|
@ -438,6 +483,13 @@ func (g openAPITypeWriter) emitExtensions(extensions []extension) {
|
|||
g.Do("},\n", nil)
|
||||
}
|
||||
}
|
||||
if len(unions) > 0 {
|
||||
g.Do("\"x-kubernetes-unions\": []interface{}{\n", nil)
|
||||
for _, u := range unions {
|
||||
u.emit(g)
|
||||
}
|
||||
g.Do("},\n", nil)
|
||||
}
|
||||
g.Do("},\n},\n", nil)
|
||||
}
|
||||
|
||||
|
|
@ -595,7 +647,13 @@ func (g openAPITypeWriter) generateMapProperty(t *types.Type) error {
|
|||
case types.Struct:
|
||||
g.generateReferenceProperty(elemType)
|
||||
case types.Slice, types.Array:
|
||||
g.generateSliceProperty(elemType)
|
||||
if err := g.generateSliceProperty(elemType); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.Map:
|
||||
if err := g.generateMapProperty(elemType); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("map Element kind %v is not supported in %v", elemType.Kind, t.Name)
|
||||
}
|
||||
|
|
@ -619,7 +677,13 @@ func (g openAPITypeWriter) generateSliceProperty(t *types.Type) error {
|
|||
case types.Struct:
|
||||
g.generateReferenceProperty(elemType)
|
||||
case types.Slice, types.Array:
|
||||
g.generateSliceProperty(elemType)
|
||||
if err := g.generateSliceProperty(elemType); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.Map:
|
||||
if err := g.generateMapProperty(elemType); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("slice Element kind %v is not supported in %v", elemType.Kind, t)
|
||||
}
|
||||
|
|
|
|||
36
vendor/k8s.io/kube-openapi/pkg/generators/rules/idl_tag.go
generated
vendored
Normal file
36
vendor/k8s.io/kube-openapi/pkg/generators/rules/idl_tag.go
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package rules
|
||||
|
||||
import (
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
const ListTypeIDLTag = "listType"
|
||||
|
||||
// ListTypeMissing implements APIRule interface.
|
||||
// A list type is required for inlined list.
|
||||
type ListTypeMissing struct{}
|
||||
|
||||
// Name returns the name of APIRule
|
||||
func (l *ListTypeMissing) Name() string {
|
||||
return "list_type_missing"
|
||||
}
|
||||
|
||||
// Validate evaluates API rule on type t and returns a list of field names in
|
||||
// the type that violate the rule. Empty field name [""] implies the entire
|
||||
// type violates the rule.
|
||||
func (l *ListTypeMissing) Validate(t *types.Type) ([]string, error) {
|
||||
fields := make([]string, 0)
|
||||
|
||||
switch t.Kind {
|
||||
case types.Struct:
|
||||
for _, m := range t.Members {
|
||||
if m.Type.Kind == types.Slice && types.ExtractCommentTags("+", m.CommentLines)[ListTypeIDLTag] == nil {
|
||||
fields = append(fields, m.Name)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fields, nil
|
||||
|
||||
}
|
||||
207
vendor/k8s.io/kube-openapi/pkg/generators/union.go
generated
vendored
Normal file
207
vendor/k8s.io/kube-openapi/pkg/generators/union.go
generated
vendored
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
const tagUnionMember = "union"
|
||||
const tagUnionDeprecated = "unionDeprecated"
|
||||
const tagUnionDiscriminator = "unionDiscriminator"
|
||||
|
||||
type union struct {
|
||||
discriminator string
|
||||
fieldsToDiscriminated map[string]string
|
||||
}
|
||||
|
||||
// emit prints the union, can be called on a nil union (emits nothing)
|
||||
func (u *union) emit(g openAPITypeWriter) {
|
||||
if u == nil {
|
||||
return
|
||||
}
|
||||
g.Do("map[string]interface{}{\n", nil)
|
||||
if u.discriminator != "" {
|
||||
g.Do("\"discriminator\": \"$.$\",\n", u.discriminator)
|
||||
}
|
||||
g.Do("\"fields-to-discriminateBy\": map[string]interface{}{\n", nil)
|
||||
keys := []string{}
|
||||
for field := range u.fieldsToDiscriminated {
|
||||
keys = append(keys, field)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, field := range keys {
|
||||
g.Do("\"$.$\": ", field)
|
||||
g.Do("\"$.$\",\n", u.fieldsToDiscriminated[field])
|
||||
}
|
||||
g.Do("},\n", nil)
|
||||
g.Do("},\n", nil)
|
||||
}
|
||||
|
||||
// Sets the discriminator if it's not set yet, otherwise return an error
|
||||
func (u *union) setDiscriminator(value string) []error {
|
||||
errors := []error{}
|
||||
if u.discriminator != "" {
|
||||
errors = append(errors, fmt.Errorf("at least two discriminators found: %v and %v", value, u.discriminator))
|
||||
}
|
||||
u.discriminator = value
|
||||
return errors
|
||||
}
|
||||
|
||||
// Add a new member to the union
|
||||
func (u *union) addMember(jsonName, variableName string) {
|
||||
if _, ok := u.fieldsToDiscriminated[jsonName]; ok {
|
||||
panic(fmt.Errorf("same field (%v) found multiple times", jsonName))
|
||||
}
|
||||
u.fieldsToDiscriminated[jsonName] = variableName
|
||||
}
|
||||
|
||||
// Makes sure that the union is valid, specifically looking for re-used discriminated
|
||||
func (u *union) isValid() []error {
|
||||
errors := []error{}
|
||||
// Case 1: discriminator but no fields
|
||||
if u.discriminator != "" && len(u.fieldsToDiscriminated) == 0 {
|
||||
errors = append(errors, fmt.Errorf("discriminator set with no fields in union"))
|
||||
}
|
||||
// Case 2: two fields have the same discriminated value
|
||||
discriminated := map[string]struct{}{}
|
||||
for _, d := range u.fieldsToDiscriminated {
|
||||
if _, ok := discriminated[d]; ok {
|
||||
errors = append(errors, fmt.Errorf("discriminated value is used twice: %v", d))
|
||||
}
|
||||
discriminated[d] = struct{}{}
|
||||
}
|
||||
// Case 3: a field is both discriminator AND part of the union
|
||||
if u.discriminator != "" {
|
||||
if _, ok := u.fieldsToDiscriminated[u.discriminator]; ok {
|
||||
errors = append(errors, fmt.Errorf("%v can't be both discriminator and part of the union", u.discriminator))
|
||||
}
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
// Find unions either directly on the members (or inlined members, not
|
||||
// going across types) or on the type itself, or on embedded types.
|
||||
func parseUnions(t *types.Type) ([]union, []error) {
|
||||
errors := []error{}
|
||||
unions := []union{}
|
||||
su, err := parseUnionStruct(t)
|
||||
if su != nil {
|
||||
unions = append(unions, *su)
|
||||
}
|
||||
errors = append(errors, err...)
|
||||
eu, err := parseEmbeddedUnion(t)
|
||||
unions = append(unions, eu...)
|
||||
errors = append(errors, err...)
|
||||
mu, err := parseUnionMembers(t)
|
||||
if mu != nil {
|
||||
unions = append(unions, *mu)
|
||||
}
|
||||
errors = append(errors, err...)
|
||||
return unions, errors
|
||||
}
|
||||
|
||||
// Find unions in embedded types, unions shouldn't go across types.
|
||||
func parseEmbeddedUnion(t *types.Type) ([]union, []error) {
|
||||
errors := []error{}
|
||||
unions := []union{}
|
||||
for _, m := range t.Members {
|
||||
if hasOpenAPITagValue(m.CommentLines, tagValueFalse) {
|
||||
continue
|
||||
}
|
||||
if !shouldInlineMembers(&m) {
|
||||
continue
|
||||
}
|
||||
u, err := parseUnions(m.Type)
|
||||
unions = append(unions, u...)
|
||||
errors = append(errors, err...)
|
||||
}
|
||||
return unions, errors
|
||||
}
|
||||
|
||||
// Look for union tag on a struct, and then include all the fields
|
||||
// (except the discriminator if there is one). The struct shouldn't have
|
||||
// embedded types.
|
||||
func parseUnionStruct(t *types.Type) (*union, []error) {
|
||||
errors := []error{}
|
||||
if types.ExtractCommentTags("+", t.CommentLines)[tagUnionMember] == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
u := &union{fieldsToDiscriminated: map[string]string{}}
|
||||
|
||||
for _, m := range t.Members {
|
||||
jsonName := getReferableName(&m)
|
||||
if jsonName == "" {
|
||||
continue
|
||||
}
|
||||
if shouldInlineMembers(&m) {
|
||||
errors = append(errors, fmt.Errorf("union structures can't have embedded fields: %v.%v", t.Name, m.Name))
|
||||
continue
|
||||
}
|
||||
if types.ExtractCommentTags("+", m.CommentLines)[tagUnionDeprecated] != nil {
|
||||
errors = append(errors, fmt.Errorf("union struct can't have unionDeprecated members: %v.%v", t.Name, m.Name))
|
||||
continue
|
||||
}
|
||||
if types.ExtractCommentTags("+", m.CommentLines)[tagUnionDiscriminator] != nil {
|
||||
errors = append(errors, u.setDiscriminator(jsonName)...)
|
||||
} else {
|
||||
if !hasOptionalTag(&m) {
|
||||
errors = append(errors, fmt.Errorf("union members must be optional: %v.%v", t.Name, m.Name))
|
||||
}
|
||||
u.addMember(jsonName, m.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return u, errors
|
||||
}
|
||||
|
||||
// Find unions specifically on members.
|
||||
func parseUnionMembers(t *types.Type) (*union, []error) {
|
||||
errors := []error{}
|
||||
u := &union{fieldsToDiscriminated: map[string]string{}}
|
||||
|
||||
for _, m := range t.Members {
|
||||
jsonName := getReferableName(&m)
|
||||
if jsonName == "" {
|
||||
continue
|
||||
}
|
||||
if shouldInlineMembers(&m) {
|
||||
continue
|
||||
}
|
||||
if types.ExtractCommentTags("+", m.CommentLines)[tagUnionDiscriminator] != nil {
|
||||
errors = append(errors, u.setDiscriminator(jsonName)...)
|
||||
}
|
||||
if types.ExtractCommentTags("+", m.CommentLines)[tagUnionMember] != nil {
|
||||
errors = append(errors, fmt.Errorf("union tag is not accepted on struct members: %v.%v", t.Name, m.Name))
|
||||
continue
|
||||
}
|
||||
if types.ExtractCommentTags("+", m.CommentLines)[tagUnionDeprecated] != nil {
|
||||
if !hasOptionalTag(&m) {
|
||||
errors = append(errors, fmt.Errorf("union members must be optional: %v.%v", t.Name, m.Name))
|
||||
}
|
||||
u.addMember(jsonName, m.Name)
|
||||
}
|
||||
}
|
||||
if len(u.fieldsToDiscriminated) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return u, append(errors, u.isValid()...)
|
||||
}
|
||||
2
vendor/k8s.io/kube-openapi/pkg/util/proto/OWNERS
generated
vendored
Normal file
2
vendor/k8s.io/kube-openapi/pkg/util/proto/OWNERS
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
approvers:
|
||||
- apelisse
|
||||
17
vendor/k8s.io/kube-openapi/pkg/util/proto/document.go
generated
vendored
17
vendor/k8s.io/kube-openapi/pkg/util/proto/document.go
generated
vendored
|
|
@ -92,13 +92,16 @@ func NewOpenAPIData(doc *openapi_v2.Document) (Models, error) {
|
|||
// We believe the schema is a reference, verify that and returns a new
|
||||
// Schema
|
||||
func (d *Definitions) parseReference(s *openapi_v2.Schema, path *Path) (Schema, error) {
|
||||
// TODO(wrong): a schema with a $ref can have properties. We can ignore them (would be incomplete), but we cannot return an error.
|
||||
if len(s.GetProperties().GetAdditionalProperties()) > 0 {
|
||||
return nil, newSchemaError(path, "unallowed embedded type definition")
|
||||
}
|
||||
// TODO(wrong): a schema with a $ref can have a type. We can ignore it (would be incomplete), but we cannot return an error.
|
||||
if len(s.GetType().GetValue()) > 0 {
|
||||
return nil, newSchemaError(path, "definition reference can't have a type")
|
||||
}
|
||||
|
||||
// TODO(wrong): $refs outside of the definitions are completely valid. We can ignore them (would be incomplete), but we cannot return an error.
|
||||
if !strings.HasPrefix(s.GetXRef(), "#/definitions/") {
|
||||
return nil, newSchemaError(path, "unallowed reference to non-definition %q", s.GetXRef())
|
||||
}
|
||||
|
|
@ -127,6 +130,7 @@ func (d *Definitions) parseMap(s *openapi_v2.Schema, path *Path) (Schema, error)
|
|||
return nil, newSchemaError(path, "invalid object type")
|
||||
}
|
||||
var sub Schema
|
||||
// TODO(incomplete): this misses the boolean case as AdditionalProperties is a bool+schema sum type.
|
||||
if s.GetAdditionalProperties().GetSchema() == nil {
|
||||
sub = &Arbitrary{
|
||||
BaseSchema: d.parseBaseSchema(s, path),
|
||||
|
|
@ -157,6 +161,7 @@ func (d *Definitions) parsePrimitive(s *openapi_v2.Schema, path *Path) (Schema,
|
|||
case Number: // do nothing
|
||||
case Integer: // do nothing
|
||||
case Boolean: // do nothing
|
||||
// TODO(wrong): this misses "null". Would skip the null case (would be incomplete), but we cannot return an error.
|
||||
default:
|
||||
return nil, newSchemaError(path, "Unknown primitive type: %q", t)
|
||||
}
|
||||
|
|
@ -175,6 +180,8 @@ func (d *Definitions) parseArray(s *openapi_v2.Schema, path *Path) (Schema, erro
|
|||
return nil, newSchemaError(path, `array should have type "array"`)
|
||||
}
|
||||
if len(s.GetItems().GetSchema()) != 1 {
|
||||
// TODO(wrong): Items can have multiple elements. We can ignore Items then (would be incomplete), but we cannot return an error.
|
||||
// TODO(wrong): "type: array" witohut any items at all is completely valid.
|
||||
return nil, newSchemaError(path, "array should have exactly one sub-item")
|
||||
}
|
||||
sub, err := d.ParseSchema(s.GetItems().GetSchema()[0], path)
|
||||
|
|
@ -227,6 +234,8 @@ func (d *Definitions) parseArbitrary(s *openapi_v2.Schema, path *Path) (Schema,
|
|||
// this function is public, it doesn't leak through the interface.
|
||||
func (d *Definitions) ParseSchema(s *openapi_v2.Schema, path *Path) (Schema, error) {
|
||||
if s.GetXRef() != "" {
|
||||
// TODO(incomplete): ignoring the rest of s is wrong. As long as there are no conflict, everything from s must be considered
|
||||
// Reference: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#path-item-object
|
||||
return d.parseReference(s, path)
|
||||
}
|
||||
objectTypes := s.GetType().GetValue()
|
||||
|
|
@ -234,11 +243,15 @@ func (d *Definitions) ParseSchema(s *openapi_v2.Schema, path *Path) (Schema, err
|
|||
case 0:
|
||||
// in the OpenAPI schema served by older k8s versions, object definitions created from structs did not include
|
||||
// the type:object property (they only included the "properties" property), so we need to handle this case
|
||||
// TODO: validate that we ever published empty, non-nil properties. JSON roundtripping nils them.
|
||||
if s.GetProperties() != nil {
|
||||
// TODO(wrong): when verifying a non-object later against this, it will be rejected as invalid type.
|
||||
// TODO(CRD validation schema publishing): we have to filter properties (empty or not) if type=object is not given
|
||||
return d.parseKind(s, path)
|
||||
} else {
|
||||
// Definition has no type and no properties. Treat it as an arbitrary value
|
||||
// TODO: what if it has additionalProperties or patternProperties?
|
||||
// TODO(incomplete): what if it has additionalProperties=false or patternProperties?
|
||||
// ANSWER: parseArbitrary is less strict than it has to be with patternProperties (which is ignored). So this is correct (of course not complete).
|
||||
return d.parseArbitrary(s, path)
|
||||
}
|
||||
case 1:
|
||||
|
|
@ -256,6 +269,8 @@ func (d *Definitions) ParseSchema(s *openapi_v2.Schema, path *Path) (Schema, err
|
|||
return d.parsePrimitive(s, path)
|
||||
default:
|
||||
// the OpenAPI generator never generates (nor it ever did in the past) OpenAPI type definitions with multiple types
|
||||
// TODO(wrong): this is rejecting a completely valid OpenAPI spec
|
||||
// TODO(CRD validation schema publishing): filter these out
|
||||
return nil, newSchemaError(path, "definitions with multiple types aren't supported")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue