-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtypes.go
More file actions
102 lines (77 loc) · 3.52 KB
/
types.go
File metadata and controls
102 lines (77 loc) · 3.52 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package spec
import (
specopenapi "github.com/oaswrap/spec/openapi"
"github.com/oaswrap/spec/option"
"github.com/swaggest/openapi-go"
)
// Generator defines an interface for building and exporting OpenAPI specifications.
type Generator interface {
Router
// Config returns the OpenAPI configuration used by the Generator.
Config() *specopenapi.Config
// GenerateSchema generates the OpenAPI schema in the specified format.
// By default, it generates YAML. Pass "json" to generate JSON instead.
GenerateSchema(formats ...string) ([]byte, error)
// MarshalYAML returns the OpenAPI specification marshaled as YAML.
MarshalYAML() ([]byte, error)
// MarshalJSON returns the OpenAPI specification marshaled as JSON.
MarshalJSON() ([]byte, error)
// Validate checks whether the OpenAPI specification is valid.
Validate() error
// WriteSchemaTo writes the OpenAPI schema to a file.
// The format is inferred from the file extension: ".yaml" for YAML, ".json" for JSON.
WriteSchemaTo(path string) error
}
// Router defines methods for registering API routes and operations
// in an OpenAPI specification. It lets you describe HTTP methods, paths, and options.
type Router interface {
// Get registers a GET operation for the given path and options.
Get(path string, opts ...option.OperationOption) Route
// Post registers a POST operation for the given path and options.
Post(path string, opts ...option.OperationOption) Route
// Put registers a PUT operation for the given path and options.
Put(path string, opts ...option.OperationOption) Route
// Delete registers a DELETE operation for the given path and options.
Delete(path string, opts ...option.OperationOption) Route
// Patch registers a PATCH operation for the given path and options.
Patch(path string, opts ...option.OperationOption) Route
// Options registers an OPTIONS operation for the given path and options.
Options(path string, opts ...option.OperationOption) Route
// Head registers a HEAD operation for the given path and options.
Head(path string, opts ...option.OperationOption) Route
// Trace registers a TRACE operation for the given path and options.
Trace(path string, opts ...option.OperationOption) Route
// Add registers an operation for the given HTTP method, path, and options.
Add(method, path string, opts ...option.OperationOption) Route
// NewRoute creates a new route with the given options.
NewRoute(opts ...option.OperationOption) Route
// Route registers a nested route under the given pattern.
// The provided function receives a Router to define sub-routes.
Route(pattern string, fn func(router Router), opts ...option.GroupOption) Router
// Group creates a new sub-router with the given path prefix and group options.
Group(pattern string, opts ...option.GroupOption) Router
// With applies one or more group options to the router.
With(opts ...option.GroupOption) Router
}
// Route represents a single API route in the OpenAPI specification.
type Route interface {
// Method sets the HTTP method for the route.
Method(method string) Route
// Path sets the HTTP path for the route.
Path(path string) Route
// With applies additional operation options to the route.
With(opts ...option.OperationOption) Route
}
type reflector interface {
Add(method, path string, opts ...option.OperationOption)
Spec() spec
Validate() error
}
type spec interface {
MarshalYAML() ([]byte, error)
MarshalJSON() ([]byte, error)
}
type operationContext interface {
With(opts ...option.OperationOption) operationContext
build() openapi.OperationContext
}