-
-
Notifications
You must be signed in to change notification settings - Fork 410
/
openapi2_test.go
53 lines (45 loc) · 1.08 KB
/
openapi2_test.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
package openapi2_test
import (
"encoding/json"
"fmt"
"io/ioutil"
"reflect"
"github.com/invopop/yaml"
"github.com/getkin/kin-openapi/openapi2"
)
func Example() {
input, err := ioutil.ReadFile("testdata/swagger.json")
if err != nil {
panic(err)
}
var doc openapi2.T
if err = json.Unmarshal(input, &doc); err != nil {
panic(err)
}
if doc.ExternalDocs.Description != "Find out more about Swagger" {
panic(`doc.ExternalDocs was parsed incorrectly!`)
}
outputJSON, err := json.Marshal(doc)
if err != nil {
panic(err)
}
var docAgainFromJSON openapi2.T
if err = json.Unmarshal(outputJSON, &docAgainFromJSON); err != nil {
panic(err)
}
if !reflect.DeepEqual(doc, docAgainFromJSON) {
fmt.Println("objects doc & docAgainFromJSON should be the same")
}
outputYAML, err := yaml.Marshal(doc)
if err != nil {
panic(err)
}
var docAgainFromYAML openapi2.T
if err = yaml.Unmarshal(outputYAML, &docAgainFromYAML); err != nil {
panic(err)
}
if !reflect.DeepEqual(doc, docAgainFromYAML) {
fmt.Println("objects doc & docAgainFromYAML should be the same")
}
// Output:
}