-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperations.go
More file actions
47 lines (37 loc) · 886 Bytes
/
operations.go
File metadata and controls
47 lines (37 loc) · 886 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
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"log"
"os"
"github.com/theapix/flowline/shared"
"gopkg.in/yaml.v3"
)
type OpenAPISpec struct {
Paths map[string]map[string]shared.Operation `yaml:"paths"`
}
func findOperations(filePath string) (map[string]shared.Operation, error) {
data, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
var spec OpenAPISpec
err = yaml.Unmarshal(data, &spec)
if err != nil {
return nil, err
}
operationsMap := make(map[string]shared.Operation)
for _, methods := range spec.Paths {
for _, operation := range methods {
if operation.OperationID != "" {
operationsMap[operation.OperationID] = operation
}
}
}
return operationsMap, nil
}
func OperationsMap(filePath string) map[string]shared.Operation {
operationsMap, err := findOperations(filePath)
if err != nil {
log.Fatalf("Error: %v", err)
}
return operationsMap
}