k8s.io/kube-openapi@v0.0.0-20240228011516-70dd3763d340/pkg/common/interfaces.go (about)

     1  package common
     2  
     3  // RouteContainer is the entrypoint for a service, which may contain multiple
     4  // routes under a common path with a common set of path parameters.
     5  type RouteContainer interface {
     6  	// RootPath is the path that all contained routes are nested under.
     7  	RootPath() string
     8  	// PathParameters are common parameters defined in the root path.
     9  	PathParameters() []Parameter
    10  	// Routes are all routes exposed under the root path.
    11  	Routes() []Route
    12  }
    13  
    14  // Route is a logical endpoint of a service.
    15  type Route interface {
    16  	// Method defines the HTTP Method.
    17  	Method() string
    18  	// Path defines the route's endpoint.
    19  	Path() string
    20  	// OperationName defines a machine-readable ID for the route.
    21  	OperationName() string
    22  	// Parameters defines the list of accepted parameters.
    23  	Parameters() []Parameter
    24  	// Description is a human-readable route description.
    25  	Description() string
    26  	// Consumes defines the consumed content-types.
    27  	Consumes() []string
    28  	// Produces defines the produced content-types.
    29  	Produces() []string
    30  	// Metadata allows adding extensions to the generated spec.
    31  	Metadata() map[string]interface{}
    32  	// RequestPayloadSample defines an example request payload. Can return nil.
    33  	RequestPayloadSample() interface{}
    34  	// ResponsePayloadSample defines an example response payload. Can return nil.
    35  	ResponsePayloadSample() interface{}
    36  	// StatusCodeResponses defines a mapping of HTTP Status Codes to the specific response(s).
    37  	// Multiple responses with the same HTTP Status Code are acceptable.
    38  	StatusCodeResponses() []StatusCodeResponse
    39  }
    40  
    41  // StatusCodeResponse is an explicit response type with an HTTP Status Code.
    42  type StatusCodeResponse interface {
    43  	// Code defines the HTTP Status Code.
    44  	Code() int
    45  	// Message returns the human-readable message.
    46  	Message() string
    47  	// Model defines an example payload for this response.
    48  	Model() interface{}
    49  }
    50  
    51  // Parameter is a Route parameter.
    52  type Parameter interface {
    53  	// Name defines the unique-per-route identifier.
    54  	Name() string
    55  	// Description is the human-readable description of the param.
    56  	Description() string
    57  	// Required defines if this parameter must be provided.
    58  	Required() bool
    59  	// Kind defines the type of the parameter itself.
    60  	Kind() ParameterKind
    61  	// DataType defines the type of data the parameter carries.
    62  	DataType() string
    63  	// AllowMultiple defines if more than one value can be supplied for the parameter.
    64  	AllowMultiple() bool
    65  }
    66  
    67  // ParameterKind is an enum of route parameter types.
    68  type ParameterKind int
    69  
    70  const (
    71  	// PathParameterKind indicates the request parameter type is "path".
    72  	PathParameterKind = ParameterKind(iota)
    73  
    74  	// QueryParameterKind indicates the request parameter type is "query".
    75  	QueryParameterKind
    76  
    77  	// BodyParameterKind indicates the request parameter type is "body".
    78  	BodyParameterKind
    79  
    80  	// HeaderParameterKind indicates the request parameter type is "header".
    81  	HeaderParameterKind
    82  
    83  	// FormParameterKind indicates the request parameter type is "form".
    84  	FormParameterKind
    85  
    86  	// UnknownParameterKind indicates the request parameter type has not been specified.
    87  	UnknownParameterKind
    88  )