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
|
||||
}
|
||||
|
||||
88
vendor/k8s.io/kube-openapi/pkg/common/interfaces.go
generated
vendored
Normal file
88
vendor/k8s.io/kube-openapi/pkg/common/interfaces.go
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
package common
|
||||
|
||||
// RouteContainer is the entrypoint for a service, which may contain multiple
|
||||
// routes under a common path with a common set of path parameters.
|
||||
type RouteContainer interface {
|
||||
// RootPath is the path that all contained routes are nested under.
|
||||
RootPath() string
|
||||
// PathParameters are common parameters defined in the root path.
|
||||
PathParameters() []Parameter
|
||||
// Routes are all routes exposed under the root path.
|
||||
Routes() []Route
|
||||
}
|
||||
|
||||
// Route is a logical endpoint of a service.
|
||||
type Route interface {
|
||||
// Method defines the HTTP Method.
|
||||
Method() string
|
||||
// Path defines the route's endpoint.
|
||||
Path() string
|
||||
// OperationName defines a machine-readable ID for the route.
|
||||
OperationName() string
|
||||
// Parameters defines the list of accepted parameters.
|
||||
Parameters() []Parameter
|
||||
// Description is a human-readable route description.
|
||||
Description() string
|
||||
// Consumes defines the consumed content-types.
|
||||
Consumes() []string
|
||||
// Produces defines the produced content-types.
|
||||
Produces() []string
|
||||
// Metadata allows adding extensions to the generated spec.
|
||||
Metadata() map[string]interface{}
|
||||
// RequestPayloadSample defines an example request payload. Can return nil.
|
||||
RequestPayloadSample() interface{}
|
||||
// ResponsePayloadSample defines an example response payload. Can return nil.
|
||||
ResponsePayloadSample() interface{}
|
||||
// StatusCodeResponses defines a mapping of HTTP Status Codes to the specific response(s).
|
||||
// Multiple responses with the same HTTP Status Code are acceptable.
|
||||
StatusCodeResponses() []StatusCodeResponse
|
||||
}
|
||||
|
||||
// StatusCodeResponse is an explicit response type with an HTTP Status Code.
|
||||
type StatusCodeResponse interface {
|
||||
// Code defines the HTTP Status Code.
|
||||
Code() int
|
||||
// Message returns the human-readable message.
|
||||
Message() string
|
||||
// Model defines an example payload for this response.
|
||||
Model() interface{}
|
||||
}
|
||||
|
||||
// Parameter is a Route parameter.
|
||||
type Parameter interface {
|
||||
// Name defines the unique-per-route identifier.
|
||||
Name() string
|
||||
// Description is the human-readable description of the param.
|
||||
Description() string
|
||||
// Required defines if this parameter must be provided.
|
||||
Required() bool
|
||||
// Kind defines the type of the parameter itself.
|
||||
Kind() ParameterKind
|
||||
// DataType defines the type of data the parameter carries.
|
||||
DataType() string
|
||||
// AllowMultiple defines if more than one value can be supplied for the parameter.
|
||||
AllowMultiple() bool
|
||||
}
|
||||
|
||||
// ParameterKind is an enum of route parameter types.
|
||||
type ParameterKind int
|
||||
|
||||
const (
|
||||
// PathParameterKind indicates the request parameter type is "path".
|
||||
PathParameterKind = ParameterKind(iota)
|
||||
|
||||
// QueryParameterKind indicates the request parameter type is "query".
|
||||
QueryParameterKind
|
||||
|
||||
// BodyParameterKind indicates the request parameter type is "body".
|
||||
BodyParameterKind
|
||||
|
||||
// HeaderParameterKind indicates the request parameter type is "header".
|
||||
HeaderParameterKind
|
||||
|
||||
// FormParameterKind indicates the request parameter type is "form".
|
||||
FormParameterKind
|
||||
|
||||
// UnknownParameterKind indicates the request parameter type has not been specified.
|
||||
UnknownParameterKind
|
||||
)
|
||||
16
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/adapter.go
generated
vendored
Normal file
16
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/adapter.go
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
package restfuladapter
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
)
|
||||
|
||||
// AdaptWebServices adapts a slice of restful.WebService into the common interfaces.
|
||||
func AdaptWebServices(webServices []*restful.WebService) []common.RouteContainer {
|
||||
var containers []common.RouteContainer
|
||||
for _, ws := range webServices {
|
||||
containers = append(containers, &WebServiceAdapter{ws})
|
||||
}
|
||||
return containers
|
||||
}
|
||||
|
||||
54
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/param_adapter.go
generated
vendored
Normal file
54
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/param_adapter.go
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
package restfuladapter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
)
|
||||
|
||||
var _ common.Parameter = &ParamAdapter{}
|
||||
|
||||
type ParamAdapter struct {
|
||||
Param *restful.Parameter
|
||||
}
|
||||
|
||||
func (r *ParamAdapter) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(r.Param)
|
||||
}
|
||||
|
||||
func (r *ParamAdapter) Name() string {
|
||||
return r.Param.Data().Name
|
||||
}
|
||||
|
||||
func (r *ParamAdapter) Description() string {
|
||||
return r.Param.Data().Description
|
||||
}
|
||||
|
||||
func (r *ParamAdapter) Required() bool {
|
||||
return r.Param.Data().Required
|
||||
}
|
||||
|
||||
func (r *ParamAdapter) Kind() common.ParameterKind {
|
||||
switch r.Param.Kind() {
|
||||
case restful.PathParameterKind:
|
||||
return common.PathParameterKind
|
||||
case restful.QueryParameterKind:
|
||||
return common.QueryParameterKind
|
||||
case restful.BodyParameterKind:
|
||||
return common.BodyParameterKind
|
||||
case restful.HeaderParameterKind:
|
||||
return common.HeaderParameterKind
|
||||
case restful.FormParameterKind:
|
||||
return common.FormParameterKind
|
||||
default:
|
||||
return common.UnknownParameterKind
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ParamAdapter) DataType() string {
|
||||
return r.Param.Data().DataType
|
||||
}
|
||||
|
||||
func (r *ParamAdapter) AllowMultiple() bool {
|
||||
return r.Param.Data().AllowMultiple
|
||||
}
|
||||
25
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/response_error_adapter.go
generated
vendored
Normal file
25
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/response_error_adapter.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
package restfuladapter
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
)
|
||||
|
||||
var _ common.StatusCodeResponse = &ResponseErrorAdapter{}
|
||||
|
||||
// ResponseErrorAdapter adapts a restful.ResponseError to common.StatusCodeResponse.
|
||||
type ResponseErrorAdapter struct {
|
||||
Err *restful.ResponseError
|
||||
}
|
||||
|
||||
func (r *ResponseErrorAdapter) Message() string {
|
||||
return r.Err.Message
|
||||
}
|
||||
|
||||
func (r *ResponseErrorAdapter) Model() interface{} {
|
||||
return r.Err.Model
|
||||
}
|
||||
|
||||
func (r *ResponseErrorAdapter) Code() int {
|
||||
return r.Err.Code
|
||||
}
|
||||
68
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/route_adapter.go
generated
vendored
Normal file
68
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/route_adapter.go
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
package restfuladapter
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
)
|
||||
|
||||
var _ common.Route = &RouteAdapter{}
|
||||
|
||||
// RouteAdapter adapts a restful.Route to common.Route.
|
||||
type RouteAdapter struct {
|
||||
Route *restful.Route
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) StatusCodeResponses() []common.StatusCodeResponse {
|
||||
// go-restful uses the ResponseErrors field to contain both error and regular responses.
|
||||
var responses []common.StatusCodeResponse
|
||||
for _, res := range r.Route.ResponseErrors {
|
||||
localRes := res
|
||||
responses = append(responses, &ResponseErrorAdapter{&localRes})
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) OperationName() string {
|
||||
return r.Route.Operation
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) Method() string {
|
||||
return r.Route.Method
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) Path() string {
|
||||
return r.Route.Path
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) Parameters() []common.Parameter {
|
||||
var params []common.Parameter
|
||||
for _, rParam := range r.Route.ParameterDocs {
|
||||
params = append(params, &ParamAdapter{rParam})
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) Description() string {
|
||||
return r.Route.Doc
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) Consumes() []string {
|
||||
return r.Route.Consumes
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) Produces() []string {
|
||||
return r.Route.Produces
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) Metadata() map[string]interface{} {
|
||||
return r.Route.Metadata
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) RequestPayloadSample() interface{} {
|
||||
return r.Route.ReadSample
|
||||
}
|
||||
|
||||
func (r *RouteAdapter) ResponsePayloadSample() interface{} {
|
||||
return r.Route.WriteSample
|
||||
}
|
||||
34
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/webservice_adapter.go
generated
vendored
Normal file
34
vendor/k8s.io/kube-openapi/pkg/common/restfuladapter/webservice_adapter.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
package restfuladapter
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
)
|
||||
|
||||
var _ common.RouteContainer = &WebServiceAdapter{}
|
||||
|
||||
// WebServiceAdapter adapts a restful.WebService to common.RouteContainer.
|
||||
type WebServiceAdapter struct {
|
||||
WebService *restful.WebService
|
||||
}
|
||||
|
||||
func (r *WebServiceAdapter) RootPath() string {
|
||||
return r.WebService.RootPath()
|
||||
}
|
||||
|
||||
func (r *WebServiceAdapter) PathParameters() []common.Parameter {
|
||||
var params []common.Parameter
|
||||
for _, rParam := range r.WebService.PathParameters() {
|
||||
params = append(params, &ParamAdapter{rParam})
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func (r *WebServiceAdapter) Routes() []common.Route {
|
||||
var routes []common.Route
|
||||
for _, rRoute := range r.WebService.Routes() {
|
||||
localRoute := rRoute
|
||||
routes = append(routes, &RouteAdapter{&localRoute})
|
||||
}
|
||||
return routes
|
||||
}
|
||||
Reference in New Issue
Block a user