forked from aws/aws-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.go
81 lines (71 loc) · 1.81 KB
/
load.go
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
package api
import (
"encoding/json"
"fmt"
"os"
)
// Load takes a set of files for each filetype and returns an API pointer.
// The API will be initialized once all files have been loaded and parsed.
//
// Will panic if any failure opening the definition JSON files, or there
// are unrecognized exported names.
func Load(api, docs, paginators, waiters string) *API {
a := API{}
a.Attach(api)
a.Attach(docs)
a.Attach(paginators)
a.Attach(waiters)
return &a
}
// Attach opens a file by name, and unmarshal its JSON data.
// Will proceed to setup the API if not already done so.
func (a *API) Attach(filename string) {
f, err := os.Open(filename)
defer f.Close()
if err != nil {
panic(err)
}
json.NewDecoder(f).Decode(a)
if !a.initialized {
a.Setup()
}
}
// AttachString will unmarshal a raw JSON string, and setup the
// API if not already done so.
func (a *API) AttachString(str string) {
json.Unmarshal([]byte(str), a)
if !a.initialized {
a.Setup()
}
}
// Setup initializes the API.
func (a *API) Setup() {
a.unrecognizedNames = map[string]string{}
a.writeShapeNames()
a.resolveReferences()
a.fixStutterNames()
a.renameExportable()
a.renameToplevelShapes()
a.updateTopLevelShapeReferences()
a.createInputOutputShapes()
a.customizationPasses()
if !a.NoRemoveUnusedShapes {
a.removeUnusedShapes()
}
if len(a.unrecognizedNames) > 0 {
msg := []string{
"Unrecognized inflections for the following export names:",
"(Add these to inflections.csv with any inflections added after the ':')",
}
fmt.Fprintf(os.Stderr, "%s\n%s\n\n", msg[0], msg[1])
for n, m := range a.unrecognizedNames {
if n == m {
m = ""
}
fmt.Fprintf(os.Stderr, "%s:%s\n", n, m)
}
os.Stderr.WriteString("\n\n")
panic("Found unrecognized exported names in API " + a.PackageName())
}
a.initialized = true
}