update vendor

Signed-off-by: Roland.Ma <rolandma@yunify.com>
This commit is contained in:
Roland.Ma
2021-08-11 07:10:14 +00:00
parent a18f72b565
commit ea8f47c73a
2901 changed files with 269317 additions and 43103 deletions

View File

@@ -21,7 +21,7 @@ import (
"sort"
"strings"
"github.com/googleapis/gnostic/OpenAPIv2"
openapi_v2 "github.com/googleapis/gnostic/openapiv2"
"gopkg.in/yaml.v2"
)
@@ -109,19 +109,39 @@ func (d *Definitions) parseReference(s *openapi_v2.Schema, path *Path) (Schema,
if _, ok := d.models[reference]; !ok {
return nil, newSchemaError(path, "unknown model in reference: %q", reference)
}
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
return &Ref{
BaseSchema: d.parseBaseSchema(s, path),
BaseSchema: base,
reference: reference,
definitions: d,
}, nil
}
func (d *Definitions) parseBaseSchema(s *openapi_v2.Schema, path *Path) BaseSchema {
func parseDefault(def *openapi_v2.Any) (interface{}, error) {
if def == nil {
return nil, nil
}
var i interface{}
if err := yaml.Unmarshal([]byte(def.Yaml), &i); err != nil {
return nil, err
}
return i, nil
}
func (d *Definitions) parseBaseSchema(s *openapi_v2.Schema, path *Path) (BaseSchema, error) {
def, err := parseDefault(s.GetDefault())
if err != nil {
return BaseSchema{}, err
}
return BaseSchema{
Description: s.GetDescription(),
Default: def,
Extensions: VendorExtensionToMap(s.GetVendorExtension()),
Path: *path,
}
}, nil
}
// We believe the schema is a map, verify and return a new schema
@@ -132,8 +152,12 @@ func (d *Definitions) parseMap(s *openapi_v2.Schema, path *Path) (Schema, error)
var sub Schema
// TODO(incomplete): this misses the boolean case as AdditionalProperties is a bool+schema sum type.
if s.GetAdditionalProperties().GetSchema() == nil {
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
sub = &Arbitrary{
BaseSchema: d.parseBaseSchema(s, path),
BaseSchema: base,
}
} else {
var err error
@@ -142,8 +166,12 @@ func (d *Definitions) parseMap(s *openapi_v2.Schema, path *Path) (Schema, error)
return nil, err
}
}
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
return &Map{
BaseSchema: d.parseBaseSchema(s, path),
BaseSchema: base,
SubType: sub,
}, nil
}
@@ -165,8 +193,12 @@ func (d *Definitions) parsePrimitive(s *openapi_v2.Schema, path *Path) (Schema,
default:
return nil, newSchemaError(path, "Unknown primitive type: %q", t)
}
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
return &Primitive{
BaseSchema: d.parseBaseSchema(s, path),
BaseSchema: base,
Type: t,
Format: s.GetFormat(),
}, nil
@@ -188,8 +220,12 @@ func (d *Definitions) parseArray(s *openapi_v2.Schema, path *Path) (Schema, erro
if err != nil {
return nil, err
}
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
return &Array{
BaseSchema: d.parseBaseSchema(s, path),
BaseSchema: base,
SubType: sub,
}, nil
}
@@ -216,8 +252,12 @@ func (d *Definitions) parseKind(s *openapi_v2.Schema, path *Path) (Schema, error
fieldOrder = append(fieldOrder, name)
}
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
return &Kind{
BaseSchema: d.parseBaseSchema(s, path),
BaseSchema: base,
RequiredFields: s.GetRequired(),
Fields: fields,
FieldOrder: fieldOrder,
@@ -225,8 +265,12 @@ func (d *Definitions) parseKind(s *openapi_v2.Schema, path *Path) (Schema, error
}
func (d *Definitions) parseArbitrary(s *openapi_v2.Schema, path *Path) (Schema, error) {
base, err := d.parseBaseSchema(s, path)
if err != nil {
return nil, err
}
return &Arbitrary{
BaseSchema: d.parseBaseSchema(s, path),
BaseSchema: base,
}, nil
}

View File

@@ -77,6 +77,8 @@ type Schema interface {
GetPath() *Path
// Describes the field.
GetDescription() string
// Default for that schema.
GetDefault() interface{}
// Returns type extensions.
GetExtensions() map[string]interface{}
}
@@ -129,6 +131,7 @@ func (p *Path) FieldPath(field string) Path {
type BaseSchema struct {
Description string
Extensions map[string]interface{}
Default interface{}
Path Path
}
@@ -141,6 +144,10 @@ func (b *BaseSchema) GetExtensions() map[string]interface{} {
return b.Extensions
}
func (b *BaseSchema) GetDefault() interface{} {
return b.Default
}
func (b *BaseSchema) GetPath() *Path {
return &b.Path
}

View File

@@ -80,6 +80,9 @@ func ToRESTFriendlyName(name string) string {
// Example for vendored Go type:
// Original full path: k8s.io/kubernetes/vendor/k8s.io/api/core/v1.Pod
// Canonical name: k8s.io/api/core/v1.Pod
//
// Original full path: vendor/k8s.io/api/core/v1.Pod
// Canonical name: k8s.io/api/core/v1.Pod
type OpenAPICanonicalTypeNamer interface {
OpenAPICanonicalTypeName() string
}
@@ -100,6 +103,8 @@ func GetCanonicalTypeName(model interface{}) string {
path := t.PkgPath()
if strings.Contains(path, "/vendor/") {
path = path[strings.Index(path, "/vendor/")+len("/vendor/"):]
} else if strings.HasPrefix(path, "vendor/") {
path = strings.TrimPrefix(path, "vendor/")
}
return path + "." + t.Name()
}