forked from kubernetes/kube-openapi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Takes ownership of the route interfaces and removes exposing the `go-restful` dependency. Adds an adapter for the currently used version of `go-restful`. Closes kubernetes#250 (kubernetes#250)
- Loading branch information
Showing
12 changed files
with
340 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package common | ||
|
||
// RouteContainer is the entrypoint for a service, which may contain multiple | ||
// routes under a common path with a common set of 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 the 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. | ||
StatusCodeResponses() map[int]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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package restfuladapter | ||
|
||
import ( | ||
"github.com/emicklei/go-restful" | ||
"k8s.io/kube-openapi/pkg/common" | ||
) | ||
|
||
func AdaptWebServices(webServices []*restful.WebService) []common.RouteContainer { | ||
var containers []common.RouteContainer | ||
for _, ws := range webServices { | ||
containers = append(containers, &WebServiceAdapter{ws}) | ||
} | ||
return containers | ||
} | ||
|
Oops, something went wrong.