File: interfaces.go

package info (click to toggle)
golang-k8s-kube-openapi 0.0~git20241212.2c72e55-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,396 kB
  • sloc: sh: 50; makefile: 5
file content (88 lines) | stat: -rw-r--r-- 3,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
)