Upgrade k8s package verison (#5358)
* upgrade k8s package version Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> * Script upgrade and code formatting. Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
116
vendor/k8s.io/kube-openapi/pkg/common/common.go
generated
vendored
116
vendor/k8s.io/kube-openapi/pkg/common/common.go
generated
vendored
@@ -20,8 +20,11 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
"github.com/go-openapi/spec"
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
|
||||
"k8s.io/kube-openapi/pkg/openapiconv"
|
||||
"k8s.io/kube-openapi/pkg/spec3"
|
||||
"k8s.io/kube-openapi/pkg/validation/spec"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -57,6 +60,11 @@ type PathHandler interface {
|
||||
Handle(path string, handler http.Handler)
|
||||
}
|
||||
|
||||
type PathHandlerByGroupVersion interface {
|
||||
Handle(path string, handler http.Handler)
|
||||
HandlePrefix(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.
|
||||
@@ -86,9 +94,19 @@ type Config struct {
|
||||
// or any of the models will result in spec generation failure.
|
||||
GetDefinitions GetOpenAPIDefinitions
|
||||
|
||||
// Provides the definition for all models used by routes. One of GetDefinitions or Definitions must be defined to generate a spec.
|
||||
// This takes precedent over the GetDefinitions function
|
||||
Definitions map[string]OpenAPIDefinition
|
||||
|
||||
// GetOperationIDAndTags returns operation id and tags for a restful route. It is an optional function to customize operation IDs.
|
||||
//
|
||||
// Deprecated: GetOperationIDAndTagsFromRoute should be used instead. This cannot be specified if using the new Route
|
||||
// interface set of funcs.
|
||||
GetOperationIDAndTags func(r *restful.Route) (string, []string, error)
|
||||
|
||||
// GetOperationIDAndTagsFromRoute returns operation id and tags for a Route. It is an optional function to customize operation IDs.
|
||||
GetOperationIDAndTagsFromRoute func(r 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)
|
||||
@@ -105,6 +123,92 @@ type Config struct {
|
||||
DefaultSecurity []map[string][]string
|
||||
}
|
||||
|
||||
// OpenAPIV3Config is set of configuration for OpenAPI V3 spec generation.
|
||||
type OpenAPIV3Config struct {
|
||||
// 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 *spec3.Response
|
||||
|
||||
// ResponseDefinitions will be added to responses component. This is an object
|
||||
// that holds responses that can be used across operations.
|
||||
ResponseDefinitions map[string]*spec3.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]*spec3.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.
|
||||
// One of GetDefinitions or Definitions must be defined to generate a spec.
|
||||
GetDefinitions GetOpenAPIDefinitions
|
||||
|
||||
// Provides the definition for all models used by routes. One of GetDefinitions or Definitions must be defined to generate a spec.
|
||||
// This takes precedent over the GetDefinitions function
|
||||
Definitions map[string]OpenAPIDefinition
|
||||
|
||||
// GetOperationIDAndTags returns operation id and tags for a restful route. It is an optional function to customize operation IDs.
|
||||
//
|
||||
// Deprecated: GetOperationIDAndTagsFromRoute should be used instead. This cannot be specified if using the new Route
|
||||
// interface set of funcs.
|
||||
GetOperationIDAndTags func(r *restful.Route) (string, []string, error)
|
||||
|
||||
// GetOperationIDAndTagsFromRoute returns operation id and tags for a Route. It is an optional function to customize operation IDs.
|
||||
GetOperationIDAndTagsFromRoute func(r 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)
|
||||
|
||||
// SecuritySchemes is list of all security schemes for OpenAPI service.
|
||||
SecuritySchemes spec3.SecuritySchemes
|
||||
|
||||
// DefaultSecurity for all operations.
|
||||
DefaultSecurity []map[string][]string
|
||||
}
|
||||
|
||||
// ConvertConfigToV3 converts a Config object to an OpenAPIV3Config object
|
||||
func ConvertConfigToV3(config *Config) *OpenAPIV3Config {
|
||||
if config == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
v3Config := &OpenAPIV3Config{
|
||||
Info: config.Info,
|
||||
IgnorePrefixes: config.IgnorePrefixes,
|
||||
GetDefinitions: config.GetDefinitions,
|
||||
GetOperationIDAndTags: config.GetOperationIDAndTags,
|
||||
GetOperationIDAndTagsFromRoute: config.GetOperationIDAndTagsFromRoute,
|
||||
GetDefinitionName: config.GetDefinitionName,
|
||||
Definitions: config.Definitions,
|
||||
SecuritySchemes: make(spec3.SecuritySchemes),
|
||||
DefaultSecurity: config.DefaultSecurity,
|
||||
DefaultResponse: openapiconv.ConvertResponse(config.DefaultResponse, []string{"application/json"}),
|
||||
|
||||
CommonResponses: make(map[int]*spec3.Response),
|
||||
ResponseDefinitions: make(map[string]*spec3.Response),
|
||||
}
|
||||
|
||||
if config.SecurityDefinitions != nil {
|
||||
for s, securityScheme := range *config.SecurityDefinitions {
|
||||
v3Config.SecuritySchemes[s] = openapiconv.ConvertSecurityScheme(securityScheme)
|
||||
}
|
||||
}
|
||||
for k, commonResponse := range config.CommonResponses {
|
||||
v3Config.CommonResponses[k] = openapiconv.ConvertResponse(&commonResponse, []string{"application/json"})
|
||||
}
|
||||
|
||||
for k, responseDefinition := range config.ResponseDefinitions {
|
||||
v3Config.ResponseDefinitions[k] = openapiconv.ConvertResponse(&responseDefinition, []string{"application/json"})
|
||||
}
|
||||
return v3Config
|
||||
}
|
||||
|
||||
type typeInfo struct {
|
||||
name string
|
||||
format string
|
||||
@@ -206,3 +310,11 @@ func EmbedOpenAPIDefinitionIntoV2Extension(main OpenAPIDefinition, embedded Open
|
||||
main.Schema.Extensions[ExtensionV2Schema] = embedded.Schema
|
||||
return main
|
||||
}
|
||||
|
||||
// GenerateOpenAPIV3OneOfSchema generate the set of schemas that MUST be assigned to SchemaProps.OneOf
|
||||
func GenerateOpenAPIV3OneOfSchema(types []string) (oneOf []spec.Schema) {
|
||||
for _, t := range types {
|
||||
oneOf = append(oneOf, spec.Schema{SchemaProps: spec.SchemaProps{Type: []string{t}}})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user