-
Notifications
You must be signed in to change notification settings - Fork 3
/
swag-validator_test.go
58 lines (49 loc) · 2.05 KB
/
swag-validator_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
package swagvalidator_test
import (
"bytes"
"encoding/json"
"log"
"net/http"
)
var testUUID = "00000000-0000-0000-0000-000000000000"
type pathCase struct {
description string
pathParam string
expectedStatus int
expectedResponse map[string]interface{}
}
type nested struct {
Foo string `json:"foo,omitempty" binding:"required"`
}
type payload struct {
FormatString string `json:"format_str,omitempty" format:"uuid"`
FormatStringArr []string `json:"format_str_arr,omitempty" format:"uuid"`
MinLenString string `json:"min_len_str,omitempty" min_length:"5"`
MinLenStringArr []string `json:"min_len_str_arr,omitempty" min_length:"5"`
MaxLenString string `json:"max_len_str,omitempty" max_length:"7"`
MaxLenStringArr []string `json:"max_len_str_arr,omitempty" max_length:"7"`
EnumString string `json:"enum_str,omitempty" enum:"Foo,Bar"`
EnumStringArr []string `json:"enum_str_arr,omitempty" enum:"Foo,Bar"`
PatternString string `json:"pattern_str,omitempty" pattern:"^test$"`
Minimum int `json:"minimum,omitempty" minimum:"5"`
Maximum int `json:"maximum,omitempty" maximum:"1"`
ExclMinimum int `json:"excl_minimum,omitempty" minimum:"5" exclusive_minimum:"true"`
ExclMaximum int `json:"excl_maximum,omitempty" maximum:"1" exclusive_maximum:"true"`
Nested *nested `json:"nested,omitempty"`
MaxItemsArr []string `json:"max_items_arr,omitempty" max_items:"3"`
MinItemsArr []string `json:"min_items_arr,omitempty" min_items:"2"`
UniqueItemsAarr []string `json:"unique_items_arr,omitempty" unique_items:"true"`
NonNullElems map[string]string `json:"non_null_elems,omitempty"`
NullableElems map[string]*string `json:"nullable_elems,omitempty"`
}
func preparePostRequest(url string, body interface{}) *http.Request {
buff, err := json.Marshal(body)
if err != nil {
log.Fatalf("Failed to marshal the body: %s", err)
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(buff))
if err != nil {
log.Fatalf("Error preparing request: %s", err)
}
return req
}