grim/resticide

Parents f00539263bcc
Children a40aa34f334b
Change up the format of form-data and add a json option to make it easier to use json in a form field. closes #12
--- a/assets.go Fri Nov 13 21:36:12 2015 -0600
+++ b/assets.go Fri Nov 13 22:08:07 2015 -0600
@@ -68,7 +68,7 @@
return nil
}
-var _assetsSchemaJson = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xe4\x58\xcd\x72\x9b\x30\x10\xbe\xf3\x14\x19\x92\x23\x94\x4e\xa7\xe9\x21\xf7\x4e\x8f\xed\xa1\xb7\x0c\xd3\x51\xcc\xda\x90\x01\x41\x24\x51\xd7\xd3\xf1\xbb\x17\x16\x83\x05\xac\x30\xa6\x4a\x38\xc4\x47\xb4\xfb\xed\xaf\xbe\x5d\xf9\xaf\x73\x53\xfd\xdc\x3b\xb9\x89\x21\x63\xee\xc3\x8d\x1b\x2b\x55\x3c\x04\xc1\xb3\xcc\xb9\xdf\x7c\xfd\x90\x8b\x5d\x10\x09\xb6\x55\xfe\xc7\xcf\x41\xf3\xed\xd6\xf5\x1a\xcd\x08\xb6\x09\x4f\x54\x92\x73\x59\x69\x37\x70\x78\x10\x03\x8b\x40\xf4\x3f\xe2\x81\x3a\x14\x50\x1b\xca\x9f\x9e\x61\xa3\x4e\x38\xdd\x29\x8b\x22\x44\x63\xe9\x0f\x91\x17\x20\x54\x02\x88\xd1\xa9\x49\x25\x12\xbe\x73\x8f\x9d\xda\xf1\x8c\xe0\x3e\xe5\xd1\xc1\x6c\xf1\xa4\x4a\x6a\x6e\x73\x91\xf9\x11\x53\xcc\x96\xc3\x3d\xa9\xcb\x38\x28\x51\x4c\x23\xa0\xcc\x6f\x96\x96\x40\x66\x64\x0c\xa8\x9b\xa5\xe1\x50\x02\x78\x99\x55\x12\x8f\x2d\x92\x57\xa5\x23\x49\xc1\x0d\x69\x44\xd4\xa9\xea\xce\xca\x54\x51\x69\xd5\x7f\xc7\xd1\x57\xc2\x4d\x57\xc0\x4b\x99\x08\x88\xd0\x89\x26\xc0\xd0\xa1\x61\xf4\x9a\xfd\xf1\xf7\xfb\xbd\x8f\x95\x2b\x45\x0a\x7c\x93\x47\x88\xf1\x96\x0d\x97\x70\x26\x16\xb6\x5c\x7d\xc5\x2c\x79\xab\x44\x09\x46\x1b\x7e\x77\xb9\x5f\xd5\x14\xb6\x8c\x1d\x1b\x5b\x96\x4a\x18\x88\x5e\xb8\x1b\x68\x9e\xb3\x6c\xee\xd5\x70\xb3\xe8\x7e\xae\xa8\x8c\xd9\xa7\xfb\x2f\xd3\x4d\x31\xc8\x46\x13\x1d\x3f\x7c\xdf\xd6\x3d\x4d\xb8\xdb\x6b\xf9\xda\x97\x41\xc3\x7b\x54\x8c\x3d\xa5\x93\x57\x03\xbd\x90\xac\x8d\x00\x59\x54\x0c\x7d\x75\x7d\x2e\x25\x5d\x2a\xa6\x4a\x59\xdf\xbb\x5e\x76\x12\xae\x60\x07\x82\x4c\xa6\x69\x2e\x74\x02\x39\x07\x53\xd6\x3a\x99\x3b\x01\xb5\x88\x7b\x1b\x68\xf3\x27\x68\xa1\x69\x26\xa2\x32\x3a\x4a\x03\x2f\xd3\xd4\xa0\x1f\xce\xa2\xb2\x76\x02\x19\x5c\xc4\x63\x4a\x6f\xea\xa2\x76\x42\xcb\x53\xa3\xc3\xaf\x99\x1e\x92\x24\x2c\xc4\x87\xb8\x6f\x16\x98\x9d\x5b\xaf\x5d\x1e\xef\xd4\x38\xd7\x93\x00\x62\xfc\x6a\x41\xf4\x32\x2f\xc4\x42\xa8\x21\xa9\x5c\x41\xdb\x06\xfe\x79\x29\x41\x2a\xdb\xf4\x53\x30\x15\xcf\x25\xf1\xca\x81\x66\x50\xb7\xc2\x8f\x9d\xd1\x53\xf9\xbd\x4e\x3f\x7c\x87\xc4\x95\x81\x8a\xf3\xf1\xf6\x34\x32\xd4\xee\x88\xb4\x94\xb6\x16\x7e\xfb\xfa\x73\xec\xd0\x14\x65\xda\xce\x2a\xe2\xae\x3a\x0b\xe8\xe5\xd0\x46\x68\x0d\xf2\xaa\x4c\x6e\x7c\x30\x59\x88\xef\x0c\xbe\x66\x88\xf3\xde\x17\x16\xc2\xa5\x0d\xad\x19\x3a\xf9\x36\xb1\x10\x29\xe2\xae\x19\x98\xbe\x09\x1b\x7c\xec\x44\x16\xcd\xf9\x19\x83\x16\xc7\x96\xa7\xf9\xb2\x78\xfc\x93\x48\x0d\x37\x58\xc1\x3a\xdf\x43\x2b\x70\x74\x9f\x5b\x81\xc6\xc6\xfa\x7f\xa4\x57\x5a\x7c\x26\xfe\x06\x63\x42\xb0\xc3\x70\xf1\x49\x14\x64\x72\xb2\x45\x9b\x7d\x4a\xfb\x53\xc2\xd1\x4c\xd3\x6b\xd5\x8c\xd7\xb6\x69\xe3\x72\x67\xbc\xac\xcd\x4b\xde\x04\x5d\x5c\x88\x6f\x46\x3d\xcd\xcc\x60\x7c\x0b\x9b\x4a\xb2\xd8\x4f\x69\xcf\xd1\x5e\x19\x47\x14\xd3\xef\x5e\x2c\x8a\x77\x4e\x7c\xe8\x0c\xac\x4f\x8a\xcb\x56\x3e\x74\x8e\x8e\xf3\x2f\x00\x00\xff\xff\xf7\x73\x41\xab\x09\x16\x00\x00")
+var _assetsSchemaJson = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xe4\x58\x4d\x6f\x9c\x3c\x10\xbe\xf3\x2b\x22\x27\x47\x78\xf7\x55\xd5\xf4\x90\x7b\xd5\x63\x7b\xe8\x2d\x5a\x55\xce\x32\x2c\x44\x7c\xc5\x36\xdd\xae\xaa\xfd\xef\x05\xc3\x7a\x31\x8c\x0d\x4b\x9d\x50\xb5\x1c\xf1\xcc\x33\x5f\x9e\x67\x06\x7e\x7a\x37\xf5\x43\xee\xf8\x2e\x86\x8c\x92\x87\x1b\x12\x0b\x51\x3e\x6c\x36\xcf\xbc\xc8\x83\xf6\xed\x7f\x05\xdb\x6f\x42\x46\x23\x11\xfc\xff\x7e\xd3\xbe\xbb\x25\x7e\xab\x19\x42\x94\xe4\x89\x48\x8a\x9c\xd7\xda\x2d\x9c\x3c\x88\x81\x86\xc0\xf4\x97\xf2\x40\x1c\x4b\x68\x0c\x15\x4f\xcf\xb0\x13\x1d\x8e\x3a\xa5\x61\x28\xd1\x68\xfa\x85\x15\x25\x30\x91\x80\xc4\x50\x6a\x5c\xb0\x24\xdf\x93\x93\x52\x3b\x5d\x10\xc8\x53\x11\x1e\xcd\x16\x3b\x55\x54\x33\x2a\x58\x16\x84\x54\x50\x57\x0e\x6b\x52\xd3\x38\x52\xa2\xb4\x23\x48\x99\xef\x34\xad\xc0\x78\x2c\x45\x8a\x1c\x3e\x47\xb5\xc8\xa3\x59\xc6\x9a\x97\xe1\x73\xf2\x2d\xd6\x34\xa4\xbc\x4a\x53\x0b\xce\x16\x3d\x3a\x8d\x33\x21\x41\x9b\x2b\xe8\x26\xd0\x3b\x06\x8d\x18\xb9\xdd\xf4\xae\xab\xbc\xe2\x7f\x5c\xd0\x51\x92\x42\x4e\xb3\xbf\xac\xc2\xa3\xb7\x48\xf8\x84\xe6\x47\x5b\x50\x84\xc1\x4b\x95\x30\x08\x1b\x91\xae\x0d\xc6\xe6\x8c\x91\xe8\xea\xb2\xf6\x8b\xb5\x55\x91\x10\x04\xfd\x15\x4e\x53\x3f\x82\xc3\xe1\x10\x48\xca\xa9\x58\x0d\xb5\x2b\x42\x89\xfc\x96\x4c\x99\xe4\x94\x2d\xe4\x4a\xb4\x31\x97\x79\x2b\x58\x05\x46\x1b\x81\x9a\x4a\xaf\x6a\xaa\xa9\xa6\x23\x1b\x11\x4d\x39\x0c\x44\x27\x48\x5d\xeb\xf8\x51\xed\x90\x36\xc9\xc2\xfb\xb9\xa2\x3c\xa6\xef\xee\x3f\xd8\x2f\xc5\x20\x1b\x6d\x74\xe6\x4e\xd4\x1b\xa1\xf1\x65\x70\xe1\xb1\x0e\xd2\x95\x3a\xaf\x06\x7a\x5b\xb4\x36\x0c\x78\x59\x73\xf5\xd5\xf5\x99\x4a\x3a\x17\x54\x54\xbc\xe9\x3b\x2d\x3b\x49\x2e\x60\x0f\x0c\x4d\xa6\x69\xa1\x51\x02\x33\x48\xd9\x30\x89\xce\xd0\x86\x49\x61\x9b\x04\xd3\xbc\x8c\x70\x32\x16\xde\x79\x75\x32\xb8\x28\x8f\x31\x3d\x5b\xa3\x2a\xa1\xe5\xa9\xe9\xc3\xaf\x99\x1e\x94\x24\x1c\xc4\x27\x71\xdf\x2c\x30\x37\x5d\xdf\x6b\x1e\xbf\xbb\x38\xd7\x93\x80\xc4\xf8\x76\x06\xe9\x97\x79\x21\x96\x84\x1a\x92\xca\x15\xb4\x6d\xe0\x9f\x97\x0a\xb8\x70\x4d\x3f\x25\x15\xf1\x5c\x12\xaf\x1d\x68\x07\xf5\x59\xf8\x51\x19\xed\xca\xef\x2b\xfd\xed\x3f\x48\x5c\x19\x88\xb8\x18\x6f\x4f\x23\x43\x5d\x8a\x0c\x7b\x77\x1d\x15\xad\xd2\xa6\xd0\xe4\xd3\xc7\xaf\x63\x87\x6c\x94\xe9\x3a\xab\x12\x77\xd5\x59\x80\x2f\x87\x2e\x42\x6b\x91\x57\x65\x72\xe3\x97\xbe\x83\xf8\x2e\xe0\x6b\x86\x38\xef\xfb\xc2\x41\xb8\xb8\xa1\x35\x43\xb7\xfe\x34\xf8\xcd\x3d\x64\xd5\xc0\xfa\x9b\xb0\xc1\x47\x25\xb2\x68\xce\xcf\x18\xb4\x72\x6c\xf9\x3d\x5f\x16\x8f\x7f\x14\xa9\xe5\x06\x27\x58\x97\x3e\x74\x02\x87\xdf\x73\x27\xd0\xc8\x9f\x88\x25\x48\xaf\xb4\xf8\x58\xfe\xdf\x52\xc6\xe8\x71\xb8\xf8\x24\x02\x32\x6e\xbd\xa2\xed\x3e\xd5\xfb\x29\xe1\xf5\x4c\xe3\x6b\xd5\x8c\xaf\x6d\xd3\xc6\x45\x66\x7c\x59\x9b\x97\x3c\x0b\x5d\x4c\xc4\x37\xa3\x9e\x66\x66\x30\x7e\x0b\x9b\x4a\xb2\xd8\x4f\xee\xce\x51\xad\x8c\x23\x8a\xd1\x6f\xaf\x2c\x8a\x7f\x49\xfc\xd6\x1b\x58\xb7\x8a\xf3\xb3\xfc\xd6\x3b\x79\xde\xaf\x00\x00\x00\xff\xff\x67\x0f\x68\x1c\xc2\x18\x00\x00")
func assetsSchemaJsonBytes() ([]byte, error) {
return bindataRead(
@@ -83,7 +83,7 @@
return nil, err
}
- info := bindataFileInfo{name: "assets/schema.json", size: 5641, mode: os.FileMode(420), modTime: time.Unix(1447388249, 0)}
+ info := bindataFileInfo{name: "assets/schema.json", size: 6338, mode: os.FileMode(420), modTime: time.Unix(1447473136, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
--- a/assets/schema.json Fri Nov 13 21:36:12 2015 -0600
+++ b/assets/schema.json Fri Nov 13 22:08:07 2015 -0600
@@ -13,13 +13,35 @@
"additionalProperties": {
"type": "object",
"properties": {
- "value": {"type": "string"},
- "type": {
- "enum": ["string", "file"],
- "default": "string"
+ "value": {
+ "oneOf": [{
+ "type": "string"
+ }, {
+ "type": "null"
+ }]
+ },
+ "json": {
+ "oneOf": [{
+ "$ref": "#/definitions/json"
+ }, {
+ "type": "null"
+ }]
+ },
+ "filename": {
+ "oneOf": [{
+ "type": "string"
+ }, {
+ "type": "null"
+ }]
}
},
- "required": ["value"]
+ "anyOf": [{
+ "required": ["value"]
+ }, {
+ "required": ["json"]
+ }, {
+ "required": ["filename"]
+ }]
}
},
"x-www-form-urlencoded": {
--- a/test.go Fri Nov 13 21:36:12 2015 -0600
+++ b/test.go Fri Nov 13 22:08:07 2015 -0600
@@ -36,7 +36,8 @@
type TestFormData struct {
Value string `json:"value"`
- Type string `json:"type"`
+ Json map[string]interface{} `json:"json"`
+ Filename string `json:"filename"`
}
type TestRequest struct {
@@ -74,10 +75,18 @@
defer writer.Close()
for name, data := range req.FormData {
- if data.Type == "string" {
+ if len(data.Value) > 0 {
writer.WriteField(name, data.Value)
- } else if data.Type == "file" {
- part, _ := writer.CreateFormFile(name, filepath.Base(data.Value))
+ } else if len(data.Json) > 0 {
+ s, err := json.Marshal(data.Json)
+ if err != nil {
+ // do something better here
+ continue
+ }
+
+ writer.WriteField(name, string(s[:]))
+ } else if len(data.Filename) > 0 {
+ part, _ := writer.CreateFormFile(name, filepath.Base(data.Filename))
// this sucks and should be cleaned up...
filename := filepath.Join(dirname, data.Value)
--- a/tests/httpbin-post-form-data-emtpy.json Fri Nov 13 21:36:12 2015 -0600
+++ b/tests/httpbin-post-form-data-emtpy.json Fri Nov 13 22:08:07 2015 -0600
@@ -4,7 +4,7 @@
"path": "/post",
"method": "POST",
"form-data": {
- "foo": {"value": "bar", "type": "string"}
+ "foo": {"value": "bar"}
},
"response": {
"statuscode": 200,
--- a/tests/httpbin-post-form-data-file.json Fri Nov 13 21:36:12 2015 -0600
+++ b/tests/httpbin-post-form-data-file.json Fri Nov 13 22:08:07 2015 -0600
@@ -4,7 +4,7 @@
"path": "/post",
"method": "POST",
"form-data": {
- "foo": {"value": "banana_slap.wav", "type": "file"}
+ "foo": {"filename": "banana_slap.wav"}
},
"response": {
"statuscode": 200,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/httpbin-post-form-data-json.json Fri Nov 13 22:08:07 2015 -0600
@@ -0,0 +1,42 @@
+{
+ "name": "httpbin post form-data json",
+ "request": {
+ "path": "/post",
+ "method": "POST",
+ "form-data": {
+ "json-test": {
+ "json": {
+ "a": 123,
+ "b": true,
+ "c": [0, 1, 1, 2, 3, 5],
+ "d": {
+ "e": false,
+ "f": null
+ }
+ }
+ }
+ },
+ "response": {
+ "statuscode": 200,
+ "json-schema": {
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "type": "object",
+ "additionalProperties": true,
+ "properties": {
+ "form": {
+ "type": "object",
+ "properties": {
+ "json-test": {
+ "enum": [
+ "{\"a\":123,\"b\":true,\"c\":[0,1,1,2,3,5],\"d\":{\"e\":false,\"f\":null}}"
+ ]
+ }
+ },
+ "required": ["json-test"]
+ }
+ },
+ "required": ["form"]
+ }
+ }
+ }
+}