-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperations.go
More file actions
35 lines (28 loc) · 770 Bytes
/
operations.go
File metadata and controls
35 lines (28 loc) · 770 Bytes
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
package openapi
import (
"fmt"
"strings"
kin "github.com/getkin/kin-openapi/openapi3"
)
type operations map[string]*operation
func readOperations(doc *kin.T) operations {
ops := make(operations)
for path, item := range doc.Paths {
for method, optn := range item.Operations() {
id := optn.OperationID
body := optn.RequestBody
ops[id] = newOperation(id, method, path, body, append(item.Parameters, optn.Parameters...))
}
}
fmt.Println(ops.Template())
return ops
}
func (o operations) Template() string {
var b strings.Builder
_, _ = fmt.Fprintf(&b, "r := openapi.NewRouter(specification)\n")
for _, op := range o {
_, _ = fmt.Fprintf(&b, "%s\n", op.Template())
}
b.WriteString("http.ListenAndServe(\":3000\", r)\n")
return b.String()
}