Skip to content

Commit c7bae45

Browse files
committed
reorganizes fundamental structure of an api-blueprint doc and all of its components
1 parent 0496b3e commit c7bae45

28 files changed

+177
-847
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ _cgo_export.*
2525
*.exe
2626
*.test
2727
*.prof
28+
29+
# Images
30+
*.jpg
31+

apiary.apib

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ HOST: http://gist.github.com
44
# Github Gists
55
The best place to host your code snippits!
66

7-
# Group Gists
7+
# ResourceGroup Gists
88
A Gist is a simple way to share snippets and pastes with others. All gists are Git repositories, so they are automatically versioned, forkable and usable from Git.
99

1010
+ Request
@@ -76,7 +76,7 @@ A Gist is a simple way to share snippets and pastes with others. All gists are G
7676
}
7777
]
7878

79-
# Group Repos
79+
# ResourceGroup Repos
8080
A Repo is an on-disk data structure which stores metadata for a set of files and/or directory structure.
8181

8282
+ Request

blueprint/main.go renamed to blueprint/_main.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ func main() {
3232
Description: "A specific weather-foo.com account-holder",
3333
Parameters: []*Parameter{
3434
&Parameter{
35-
Name: "id",
36-
ExampleValue: "1",
37-
Type: Number,
38-
IsRequired: true,
39-
Description: "user account identifier",
35+
Name: "id",
36+
Value: "1",
37+
Type: Number,
38+
IsRequired: true,
39+
Description: "user account identifier",
4040
},
4141
},
4242
Actions: []*Action{

blueprint/action.go

+6-95
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,14 @@
11
package blueprint
22

3-
import (
4-
"bytes"
5-
"io"
6-
"io/ioutil"
7-
"net/http"
8-
"net/http/httptest"
9-
"net/url"
10-
)
11-
123
type Action struct {
13-
HTTPMethod string
14-
URI *url.URL
15-
Parameters []*Parameter
16-
Requests []*Request
17-
18-
// Todo:
19-
// - Relation
20-
// - Attributes
21-
// - Schema
22-
}
23-
24-
func NewAction(uri *url.URL, httpMethod string) *Action {
25-
return &Action{
26-
HTTPMethod: httpMethod,
27-
URI: uri,
28-
}
29-
}
30-
31-
type httpIO struct {
324
Name string
335
Description string
34-
Header http.Header
35-
ContentType string
36-
Body *bytes.Buffer
6+
Parameters []*api.Parameter
7+
Requests []*api.Request
8+
Responses []*api.Response
379

3810
// Todo:
39-
// - Schema
40-
// - Attributes
41-
}
42-
43-
type Request struct {
44-
httpIO
45-
Responses []*Response
46-
}
47-
48-
func NewRequest(name, description string, req *http.Request) (breq *Request, err error) {
49-
var body *bytes.Buffer
50-
51-
body, err = copyBody(req.Body)
52-
if err != nil {
53-
return
54-
}
55-
56-
return &Request{
57-
httpIO{
58-
Name: name,
59-
Description: description,
60-
Header: req.Header,
61-
ContentType: req.Header.Get("Content-Type"),
62-
Body: body,
63-
},
64-
nil,
65-
}, nil
66-
}
67-
68-
type Response struct {
69-
StatusCode int
70-
httpIO
71-
}
72-
73-
func NewResponse(name, description string, w httptest.ResponseRecorder) (resp *Response, err error) {
74-
var body *bytes.Buffer
75-
76-
body, err = copyBody(w.Body)
77-
if err != nil {
78-
return
79-
}
80-
81-
return &Response{
82-
w.Code,
83-
httpIO{
84-
Name: name,
85-
Description: description,
86-
Header: w.Header(),
87-
ContentType: w.Header().Get("Content-Type"),
88-
Body: body,
89-
},
90-
}, nil
91-
}
92-
93-
func copyBody(r io.Reader) (buf *bytes.Buffer, err error) {
94-
body, err := ioutil.ReadAll(r)
95-
if err != nil {
96-
return buf, err
97-
}
98-
99-
buf = bytes.NewBuffer(body)
100-
r = bytes.NewBuffer(body)
101-
102-
return
11+
// Relation
12+
// Attributes
13+
// Schema
10314
}

blueprint/api/parameter.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package blueprint
2+
3+
type ParameterType int
4+
5+
const (
6+
Number ParameterType = iota
7+
String
8+
Boolean
9+
)
10+
11+
type Parameter struct {
12+
Name string
13+
Description string
14+
Value string
15+
Type ParameterType
16+
IsRequired bool
17+
18+
// Todo:
19+
// DefaultValue
20+
}

blueprint/api/request.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package blueprint
2+
3+
import (
4+
"bytes"
5+
"net/http"
6+
)
7+
8+
type Request struct {
9+
Name string
10+
Description string
11+
Headers http.Header
12+
Body *bytes.Buffer
13+
14+
// Todo:
15+
// Attributes
16+
// Schema
17+
}
18+
19+
func NewRequest(name, description string, req *http.Request) (breq *Request, err error) {
20+
var body *bytes.Buffer
21+
22+
body, err = copyBody(req.Body)
23+
if err != nil {
24+
return
25+
}
26+
27+
return &Request{
28+
httpIO{
29+
Name: name,
30+
Description: description,
31+
Header: req.Header,
32+
ContentType: req.Header.Get("Content-Type"),
33+
Body: body,
34+
},
35+
nil,
36+
}, nil
37+
}

blueprint/api/response.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package blueprint
2+
3+
import (
4+
"bytes"
5+
"net/http"
6+
"net/http/httptest"
7+
)
8+
9+
type Response struct {
10+
StatusCode int
11+
Description string
12+
Headers http.Header
13+
Body *bytes.Buffer
14+
15+
// Todo:
16+
// Attributes
17+
// Schema
18+
}
19+
20+
func NewResponse(name, description string, w httptest.ResponseRecorder) (resp *Response, err error) {
21+
var body *bytes.Buffer
22+
23+
body, err = copyBody(w.Body)
24+
if err != nil {
25+
return
26+
}
27+
28+
return &Response{
29+
w.Code,
30+
httpIO{
31+
Name: name,
32+
Description: description,
33+
Header: w.Header(),
34+
ContentType: w.Header().Get("Content-Type"),
35+
Body: body,
36+
},
37+
}, nil
38+
}

blueprint/api/uri.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package blueprint
2+
3+
type URI struct {
4+
Raw string
5+
Tmpl string
6+
Parameters []*Parameter
7+
}
8+
9+
// type ParamMatcherFn func(str string) []*Parameter
10+
11+
// var ParamMatcher = defaultParamMatcherFn
12+
13+
// // paramRegexp is for gorilla/mux-like uri parameters
14+
// // eg. "/articles/{category}/{id:[0-9]+}"
15+
// var defaultParamRegexp = regexp.MustCompile(`\{[^\:\}]+(\:[^\}]+)?\}`)
16+
17+
// func defaultParamMatcherFn(str string) []*Parameter {
18+
19+
// }

blueprint/api/util.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package blueprint
2+
3+
import (
4+
"bytes"
5+
"io"
6+
"io/ioutil"
7+
)
8+
9+
func copyBody(r io.Reader) (buf *bytes.Buffer, err error) {
10+
body, err := ioutil.ReadAll(r)
11+
if err != nil {
12+
return buf, err
13+
}
14+
15+
buf = bytes.NewBuffer(body)
16+
r = bytes.NewBuffer(body)
17+
18+
return
19+
}

blueprint/blueprint.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package blueprint
2+
3+
const (
4+
FORMAT = "1A"
5+
)
6+
7+
type APIBlueprint struct {
8+
Name string
9+
Description string
10+
Metadata *Metadata
11+
ResourceGroups []*ResourceGroup
12+
13+
// Todo:
14+
// DataStructures
15+
}
16+
17+
type Metadata struct {
18+
Format string
19+
Host string
20+
}

blueprint/doc.go

-36
This file was deleted.

blueprint/parameter.go

-29
This file was deleted.

0 commit comments

Comments
 (0)