-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
88 lines (82 loc) · 1.89 KB
/
example_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
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
package openapi_test
import (
"testing"
"github.com/MarkRosemaker/openapi"
)
func TestExample_JSON(t *testing.T) {
t.Parallel()
// In a request body:
testJSON(t, []byte(`{
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Address"
},
"examples": {
"foo": {
"summary": "A foo example",
"value": {
"foo": "bar"
}
},
"bar": {
"summary": "A bar example",
"value": {
"bar": "baz"
}
}
}
},
"application/xml": {
"examples": {
"xmlExample": {
"summary": "This is an example in XML",
"externalValue": "https://example.org/examples/address-example.xml"
}
}
},
"text/plain": {
"examples": {
"textExample": {
"summary": "This is a text example",
"externalValue": "https://foo.bar/examples/address-example.txt"
}
}
}
}
}`), &openapi.RequestBody{})
// In a parameter:
testJSON(t, []byte(`[
{
"name": "zipCode",
"in": "query",
"schema": {
"type": "string",
"format": "zip-code"
},
"examples": {
"zip-example": {
"$ref": "#/components/examples/zip-example"
}
}
}
]`), &openapi.ParameterList{})
// In a response:
testJSON(t, []byte(`{
"200": {
"description": "your car appointment has been booked",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SuccessResponse"
},
"examples": {
"confirmation-success": {
"$ref": "#/components/examples/confirmation-success"
}
}
}
}
}
}`), &openapi.OperationResponses{})
}