jdoc 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/example-api-documentation.md +5 -27
- data/lib/jdoc/link.rb +35 -2
- data/lib/jdoc/version.rb +1 -1
- data/template.md.erb +3 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 882fb1ca942392f3f55bac3f59a40cb5b5fe6305
|
4
|
+
data.tar.gz: 273cefe1904b0e628430ff94716ccd8a7642ff0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c3bf5c1527a6a9e9c88e2fd16cc0c9c6c1d6504c920fb6346d783489b1ee89750e77ec8168ba93a9c38a74f87a9dcca5de7d00f3e347127bc1312c5d51e583a
|
7
|
+
data.tar.gz: c377a2e9e92a1252d338b671161c7cb8be598dd849920972262e6dea7685470db14e0cbf3478e90353c92699996f01c28dfa7a89d8cd34cf52b03c2d1362bea7
|
data/CHANGELOG.md
CHANGED
@@ -56,7 +56,6 @@ Host: api.example.com
|
|
56
56
|
```
|
57
57
|
HTTP/1.1 201
|
58
58
|
Content-Type: application/json
|
59
|
-
|
60
59
|
{
|
61
60
|
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
62
61
|
"name": "example",
|
@@ -77,42 +76,25 @@ Content-Type: application/json
|
|
77
76
|
Delete an existing app.
|
78
77
|
|
79
78
|
```
|
80
|
-
DELETE /apps
|
79
|
+
DELETE /apps/01234567-89ab-cdef-0123-456789abcdef HTTP/1.1
|
81
80
|
Host: api.example.com
|
82
81
|
```
|
83
82
|
|
84
83
|
```
|
85
|
-
HTTP/1.1
|
86
|
-
Content-Type: application/json
|
87
|
-
|
88
|
-
{
|
89
|
-
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
90
|
-
"name": "example",
|
91
|
-
"private": false,
|
92
|
-
"deleted_at": null,
|
93
|
-
"user_ids": [
|
94
|
-
1
|
95
|
-
],
|
96
|
-
"users": [
|
97
|
-
{
|
98
|
-
"name": "alice"
|
99
|
-
}
|
100
|
-
]
|
101
|
-
}
|
84
|
+
HTTP/1.1 204
|
102
85
|
```
|
103
86
|
|
104
87
|
### GET /apps/:id
|
105
88
|
Info for existing app.
|
106
89
|
|
107
90
|
```
|
108
|
-
GET /apps
|
91
|
+
GET /apps/01234567-89ab-cdef-0123-456789abcdef HTTP/1.1
|
109
92
|
Host: api.example.com
|
110
93
|
```
|
111
94
|
|
112
95
|
```
|
113
96
|
HTTP/1.1 200
|
114
97
|
Content-Type: application/json
|
115
|
-
|
116
98
|
{
|
117
99
|
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
118
100
|
"name": "example",
|
@@ -140,7 +122,6 @@ Host: api.example.com
|
|
140
122
|
```
|
141
123
|
HTTP/1.1 200
|
142
124
|
Content-Type: application/json
|
143
|
-
|
144
125
|
[
|
145
126
|
{
|
146
127
|
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
@@ -163,7 +144,7 @@ Content-Type: application/json
|
|
163
144
|
Update an existing app.
|
164
145
|
|
165
146
|
```
|
166
|
-
PATCH /apps
|
147
|
+
PATCH /apps/01234567-89ab-cdef-0123-456789abcdef HTTP/1.1
|
167
148
|
Content-Type: application/json
|
168
149
|
Host: api.example.com
|
169
150
|
|
@@ -175,7 +156,6 @@ Host: api.example.com
|
|
175
156
|
```
|
176
157
|
HTTP/1.1 200
|
177
158
|
Content-Type: application/json
|
178
|
-
|
179
159
|
{
|
180
160
|
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
181
161
|
"name": "example",
|
@@ -196,7 +176,7 @@ Content-Type: application/json
|
|
196
176
|
Upload an attachment file for an app
|
197
177
|
|
198
178
|
```
|
199
|
-
POST /apps
|
179
|
+
POST /apps/01234567-89ab-cdef-0123-456789abcdef/files HTTP/1.1
|
200
180
|
Content-Type: multipart/form-data; boundary=---BoundaryX
|
201
181
|
Host: api.example.com
|
202
182
|
|
@@ -210,7 +190,6 @@ Content-Disposition: form-data; name="[file]"
|
|
210
190
|
```
|
211
191
|
HTTP/1.1 201
|
212
192
|
Content-Type: application/json
|
213
|
-
|
214
193
|
{
|
215
194
|
"id": "01234567-89ab-cdef-0123-456789abcdef",
|
216
195
|
"name": "example",
|
@@ -247,7 +226,6 @@ Host: api.example.com
|
|
247
226
|
```
|
248
227
|
HTTP/1.1 200
|
249
228
|
Content-Type: application/json
|
250
|
-
|
251
229
|
[
|
252
230
|
{
|
253
231
|
"name": "Sushi",
|
data/lib/jdoc/link.rb
CHANGED
@@ -57,11 +57,20 @@ module Jdoc
|
|
57
57
|
# @example
|
58
58
|
# link.path #=> "GET /apps/:id"
|
59
59
|
def path
|
60
|
-
@path ||= @raw_link.href.gsub(/{(.+?)}/) do
|
60
|
+
@path ||= @raw_link.href.gsub(/{(.+?)}/) do
|
61
61
|
":" + CGI.unescape($1).gsub(/[()\s]/, "").split("/").last
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
# @returns [String] Path with embedded example variable
|
66
|
+
# @example
|
67
|
+
# link.example_path #=> "GET /apps/1"
|
68
|
+
def example_path
|
69
|
+
@example_path ||= @raw_link.href.gsub(/{\((.+?)\)}/) do
|
70
|
+
JsonPointer.evaluate(root_schema.data, CGI.unescape($1))["example"]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
65
74
|
# @return [String] request content type
|
66
75
|
# @note default value is "application/json"
|
67
76
|
def content_type
|
@@ -119,6 +128,12 @@ module Jdoc
|
|
119
128
|
["PATCH", "POST", "PUT"].include?(method)
|
120
129
|
end
|
121
130
|
|
131
|
+
# We have a policy that we should not return response body to PUT and DELETE requests.
|
132
|
+
# @return [true, false] True if this endpoint must have response body
|
133
|
+
def has_response_body?
|
134
|
+
!["PUT", "DELETE"].include?(method)
|
135
|
+
end
|
136
|
+
|
122
137
|
# @return [String] JSON response body generated from example properties
|
123
138
|
def response_body
|
124
139
|
object = has_list_data? ? [response_hash] : response_hash
|
@@ -127,7 +142,14 @@ module Jdoc
|
|
127
142
|
|
128
143
|
# @return [Fixnum] Preferred respone status code for this endpoint
|
129
144
|
def response_status
|
130
|
-
method
|
145
|
+
case method
|
146
|
+
when "POST"
|
147
|
+
201
|
148
|
+
when "PUT", "DELETE"
|
149
|
+
204
|
150
|
+
else
|
151
|
+
200
|
152
|
+
end
|
131
153
|
end
|
132
154
|
|
133
155
|
# @return [JsonSchema::Schema] Response schema for this link
|
@@ -148,6 +170,17 @@ module Jdoc
|
|
148
170
|
|
149
171
|
private
|
150
172
|
|
173
|
+
# @return [JsonSchema::Schema] Root schema object this link is associated to
|
174
|
+
def root_schema
|
175
|
+
@root ||= begin
|
176
|
+
schema = @raw_link
|
177
|
+
while schema.parent
|
178
|
+
schema = schema.parent
|
179
|
+
end
|
180
|
+
schema
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
151
184
|
# @return [true, false] True if a given link has a schema property
|
152
185
|
def has_schema_in_link?
|
153
186
|
!!@raw_link.schema
|
data/lib/jdoc/version.rb
CHANGED
data/template.md.erb
CHANGED
@@ -27,7 +27,7 @@
|
|
27
27
|
<%= link.description %>
|
28
28
|
|
29
29
|
```
|
30
|
-
<%= link.method %> <%= link.
|
30
|
+
<%= link.method %> <%= link.example_path %><%= link.query_string %> HTTP/1.1
|
31
31
|
<%= "Content-Type: #{link.content_type}\n" if link.has_request_body? -%>
|
32
32
|
Host: <%= schema.host_with_port %>
|
33
33
|
<%= "\n" + link.request_body if link.has_request_body? -%>
|
@@ -35,9 +35,8 @@ Host: <%= schema.host_with_port %>
|
|
35
35
|
|
36
36
|
```
|
37
37
|
HTTP/1.1 <%= link.response_status %>
|
38
|
-
Content-Type: application/json
|
39
|
-
|
40
|
-
<%= link.response_body %>
|
38
|
+
<%= "Content-Type: application/json" if link.has_response_body? -%>
|
39
|
+
<%= "\n#{link.response_body}\n" if link.has_response_body? -%>
|
41
40
|
```
|
42
41
|
|
43
42
|
<% end %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jdoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|