jdoc 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cba6d88f3a7501c3c240ed691dee7f1f68a3b73
4
- data.tar.gz: 08d484a97ce19deac8f5a50f32dc5103e925144a
3
+ metadata.gz: 7cd0e286ca9d1efc9fd8d73dfbe5bef85e6d0da3
4
+ data.tar.gz: 12a87a0a889e7140bb80eda2b12e1ef35ca18639
5
5
  SHA512:
6
- metadata.gz: b78a21dc60b11f898b74aa700bf0cb0b90feebc8f9cbeeb2bc7604b16c2ff0fd2d08812d235bff86f5aa1869b02430fa16e7b5615d05f92a5389fb235304bc84
7
- data.tar.gz: eae3dc35b17b5c6a1cf4836e4cb6eed22ca1f10a63735ace67d9cd055d42c7fd3c6758eeb25885e55bebf23bff94f9022a53c7d75f7044f213eb00d1bd2eb5ae
6
+ metadata.gz: 023a5f58f9ceeca9f7ace02c539ac48f2ff5b96773705c2700ce1d252d8c7bd0dbea3d3b3c1eac2c52d074f500f02196e4d10c2219737dc4849e4747727b1875
7
+ data.tar.gz: 10d23acea805ea18bc88e32c4db87078e78c82d1d5abe70198c20182876a14e311ab77e53f1dd2991352e3bb8dd33ac58da2fb55d806c17645bf01341050cbe8
@@ -1,3 +1,7 @@
1
+ ## 0.1.2
2
+ * Use .schema property for request body if exists
3
+ * Improve array resource handling
4
+
1
5
  ## 0.1.1
2
6
  * Support has-one relation
3
7
 
@@ -1,10 +1,13 @@
1
1
  # Example API
2
2
  * [App](#app)
3
- * [GET /apps](#get-apps)
4
3
  * [POST /apps](#post-apps)
4
+ * [DELETE /apps/:id](#delete-appsid)
5
5
  * [GET /apps/:id](#get-appsid)
6
+ * [GET /apps](#get-apps)
6
7
  * [PATCH /apps/:id](#patch-appsid)
7
- * [DELETE /apps/:id](#delete-appsid)
8
+ * [Recipe](#recipe)
9
+ * [GET /recipes](#get-recipes)
10
+ * [User](#user)
8
11
 
9
12
  ## App
10
13
  An app is a program to be deployed.
@@ -25,52 +28,62 @@ An app is a program to be deployed.
25
28
  * deleted_at - When this resource was deleted at
26
29
  * Example: `nil`
27
30
  * Type: null
31
+ * users -
32
+ * Type: array
28
33
 
29
- ### GET /apps
30
- List existing apps.
34
+ ### POST /apps
35
+ Create a new app.
31
36
 
32
37
  ```
33
- GET /apps HTTP/1.1
38
+ POST /apps HTTP/1.1
34
39
  Content-Type: application/json
35
40
  Host: api.example.com
41
+
42
+ {
43
+ "name": "example"
44
+ }
36
45
  ```
37
46
 
38
47
  ```
39
- HTTP/1.1 200
48
+ HTTP/1.1 201
40
49
  Content-Type: application/json
41
50
 
42
51
  {
43
52
  "id": "01234567-89ab-cdef-0123-456789abcdef",
44
53
  "name": "example",
45
54
  "private": false,
46
- "deleted_at": null
55
+ "deleted_at": null,
56
+ "users": [
57
+ {
58
+ "name": "alice"
59
+ }
60
+ ]
47
61
  }
48
62
  ```
49
63
 
50
- ### POST /apps
51
- Create a new app.
64
+ ### DELETE /apps/:id
65
+ Delete an existing app.
52
66
 
53
67
  ```
54
- POST /apps HTTP/1.1
68
+ DELETE /apps/:id HTTP/1.1
55
69
  Content-Type: application/json
56
70
  Host: api.example.com
57
-
58
- {
59
- "name": "example",
60
- "private": false,
61
- "deleted_at": null
62
- }
63
71
  ```
64
72
 
65
73
  ```
66
- HTTP/1.1 201
74
+ HTTP/1.1 200
67
75
  Content-Type: application/json
68
76
 
69
77
  {
70
78
  "id": "01234567-89ab-cdef-0123-456789abcdef",
71
79
  "name": "example",
72
80
  "private": false,
73
- "deleted_at": null
81
+ "deleted_at": null,
82
+ "users": [
83
+ {
84
+ "name": "alice"
85
+ }
86
+ ]
74
87
  }
75
88
  ```
76
89
 
@@ -91,10 +104,43 @@ Content-Type: application/json
91
104
  "id": "01234567-89ab-cdef-0123-456789abcdef",
92
105
  "name": "example",
93
106
  "private": false,
94
- "deleted_at": null
107
+ "deleted_at": null,
108
+ "users": [
109
+ {
110
+ "name": "alice"
111
+ }
112
+ ]
95
113
  }
96
114
  ```
97
115
 
116
+ ### GET /apps
117
+ List existing apps.
118
+
119
+ ```
120
+ GET /apps HTTP/1.1
121
+ Content-Type: application/json
122
+ Host: api.example.com
123
+ ```
124
+
125
+ ```
126
+ HTTP/1.1 200
127
+ Content-Type: application/json
128
+
129
+ [
130
+ {
131
+ "id": "01234567-89ab-cdef-0123-456789abcdef",
132
+ "name": "example",
133
+ "private": false,
134
+ "deleted_at": null,
135
+ "users": [
136
+ {
137
+ "name": "alice"
138
+ }
139
+ ]
140
+ }
141
+ ]
142
+ ```
143
+
98
144
  ### PATCH /apps/:id
99
145
  Update an existing app.
100
146
 
@@ -104,9 +150,7 @@ Content-Type: application/json
104
150
  Host: api.example.com
105
151
 
106
152
  {
107
- "name": "example",
108
- "private": false,
109
- "deleted_at": null
153
+ "name": "example"
110
154
  }
111
155
  ```
112
156
 
@@ -118,15 +162,30 @@ Content-Type: application/json
118
162
  "id": "01234567-89ab-cdef-0123-456789abcdef",
119
163
  "name": "example",
120
164
  "private": false,
121
- "deleted_at": null
165
+ "deleted_at": null,
166
+ "users": [
167
+ {
168
+ "name": "alice"
169
+ }
170
+ ]
122
171
  }
123
172
  ```
124
173
 
125
- ### DELETE /apps/:id
126
- Delete an existing app.
174
+ ## Recipe
175
+
176
+
177
+ ### Properties
178
+ * name -
179
+ * Example: `"Sushi"`
180
+ * Type: string
181
+ * user -
182
+ * Type: object
183
+
184
+ ### GET /recipes
185
+ List recipes
127
186
 
128
187
  ```
129
- DELETE /apps/:id HTTP/1.1
188
+ GET /recipes HTTP/1.1
130
189
  Content-Type: application/json
131
190
  Host: api.example.com
132
191
  ```
@@ -135,11 +194,21 @@ Host: api.example.com
135
194
  HTTP/1.1 200
136
195
  Content-Type: application/json
137
196
 
138
- {
139
- "id": "01234567-89ab-cdef-0123-456789abcdef",
140
- "name": "example",
141
- "private": false,
142
- "deleted_at": null
143
- }
197
+ [
198
+ {
199
+ "name": "Sushi",
200
+ "user": {
201
+ "name": "alice"
202
+ }
203
+ }
204
+ ]
144
205
  ```
145
206
 
207
+ ## User
208
+
209
+
210
+ ### Properties
211
+ * name -
212
+ * Example: `"alice"`
213
+ * Type: string
214
+
@@ -64,7 +64,7 @@ module Jdoc
64
64
 
65
65
  # @return [String, nil] Example request body in JSON format
66
66
  def request_body
67
- JSON.pretty_generate(RequestGenerator.call(schema.properties)) + "\n"
67
+ JSON.pretty_generate(RequestGenerator.call(request_schema.properties)) + "\n"
68
68
  end
69
69
 
70
70
  # @return [true, false] True if this endpoint must have request body
@@ -74,7 +74,8 @@ module Jdoc
74
74
 
75
75
  # @return [String] JSON response body generated from example properties
76
76
  def response_body
77
- JSON.pretty_generate(response_hash)
77
+ object = has_list_data? ? [response_hash] : response_hash
78
+ JSON.pretty_generate(object)
78
79
  end
79
80
 
80
81
  # @return [Fixnum] Preferred respone status code for this endpoint
@@ -82,23 +83,33 @@ module Jdoc
82
83
  method == "POST" ? 201 : 200
83
84
  end
84
85
 
85
- # @return [JsonSchema::Schema] Schema for this link, specified by targetSchema or parent schema
86
- def schema
86
+ # @return [JsonSchema::Schema] Response schema for this link
87
+ def response_schema
87
88
  @raw_link.target_schema || @raw_link.parent
88
89
  end
89
90
 
91
+ # @return [JsonSchema::Schema] Request schema for this link
92
+ def request_schema
93
+ @raw_link.schema || @raw_link.parent
94
+ end
95
+
90
96
  # @return [Json::Link::Resource]
91
97
  # @note Resource means each property of top-level properties in this context
92
98
  def resource
93
- @resource ||= Resource.new(schema)
99
+ @resource ||= Resource.new(response_schema)
94
100
  end
95
101
 
96
102
  private
97
103
 
104
+ # @return [true, false] True if response is intended to be list data
105
+ def has_list_data?
106
+ @raw_link.rel == "instances"
107
+ end
108
+
98
109
  # @return [Hash]
99
110
  # @raise [Rack::Spec::Mock::ExampleNotFound]
100
111
  def response_hash
101
- ResponseGenerator.call(schema.properties)
112
+ ResponseGenerator.call(response_schema.properties)
102
113
  end
103
114
 
104
115
  # @return [Fixnum] Order score, used to sort links by preferred method order
@@ -148,7 +159,7 @@ module Jdoc
148
159
  when value.type.include?("null")
149
160
  nil
150
161
  when value.type.include?("array")
151
- call(value.items.properties)
162
+ [call(value.items.properties)]
152
163
  else
153
164
  raise ExampleNotFound, "No example found for #{schema.pointer}/#{key}"
154
165
  end
@@ -1,3 +1,3 @@
1
1
  module Jdoc
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -17,218 +17,7 @@ describe Jdoc::Generator do
17
17
  end
18
18
 
19
19
  it "returns a String of API documentation in Markdown from given JSON Schema" do
20
- should == <<-EOS.strip_heredoc
21
- # Example API
22
- * [App](#app)
23
- * [POST /apps](#post-apps)
24
- * [DELETE /apps/:id](#delete-appsid)
25
- * [GET /apps/:id](#get-appsid)
26
- * [GET /apps](#get-apps)
27
- * [PATCH /apps/:id](#patch-appsid)
28
- * [Recipe](#recipe)
29
- * [GET /recipes](#get-recipes)
30
- * [User](#user)
31
-
32
- ## App
33
- An app is a program to be deployed.
34
-
35
- ### Properties
36
- * id - unique identifier of app
37
- * Example: `"01234567-89ab-cdef-0123-456789abcdef"`
38
- * Type: string
39
- * Format: uuid
40
- * ReadOnly: true
41
- * name - unique name of app
42
- * Example: `"example"`
43
- * Type: string
44
- * Patern: `(?-mix:^[a-z][a-z0-9-]{3,50}$)`
45
- * private - true if this resource is private use
46
- * Example: `false`
47
- * Type: boolean
48
- * deleted_at - When this resource was deleted at
49
- * Example: `nil`
50
- * Type: null
51
- * users -
52
- * Type: array
53
-
54
- ### POST /apps
55
- Create a new app.
56
-
57
- ```
58
- POST /apps HTTP/1.1
59
- Content-Type: application/json
60
- Host: api.example.com
61
-
62
- {
63
- "name": "example",
64
- "private": false,
65
- "deleted_at": null,
66
- "users": {
67
- "name": "alice"
68
- }
69
- }
70
- ```
71
-
72
- ```
73
- HTTP/1.1 201
74
- Content-Type: application/json
75
-
76
- {
77
- "id": "01234567-89ab-cdef-0123-456789abcdef",
78
- "name": "example",
79
- "private": false,
80
- "deleted_at": null,
81
- "users": {
82
- "name": "alice"
83
- }
84
- }
85
- ```
86
-
87
- ### DELETE /apps/:id
88
- Delete an existing app.
89
-
90
- ```
91
- DELETE /apps/:id HTTP/1.1
92
- Content-Type: application/json
93
- Host: api.example.com
94
- ```
95
-
96
- ```
97
- HTTP/1.1 200
98
- Content-Type: application/json
99
-
100
- {
101
- "id": "01234567-89ab-cdef-0123-456789abcdef",
102
- "name": "example",
103
- "private": false,
104
- "deleted_at": null,
105
- "users": {
106
- "name": "alice"
107
- }
108
- }
109
- ```
110
-
111
- ### GET /apps/:id
112
- Info for existing app.
113
-
114
- ```
115
- GET /apps/:id HTTP/1.1
116
- Content-Type: application/json
117
- Host: api.example.com
118
- ```
119
-
120
- ```
121
- HTTP/1.1 200
122
- Content-Type: application/json
123
-
124
- {
125
- "id": "01234567-89ab-cdef-0123-456789abcdef",
126
- "name": "example",
127
- "private": false,
128
- "deleted_at": null,
129
- "users": {
130
- "name": "alice"
131
- }
132
- }
133
- ```
134
-
135
- ### GET /apps
136
- List existing apps.
137
-
138
- ```
139
- GET /apps HTTP/1.1
140
- Content-Type: application/json
141
- Host: api.example.com
142
- ```
143
-
144
- ```
145
- HTTP/1.1 200
146
- Content-Type: application/json
147
-
148
- {
149
- "id": "01234567-89ab-cdef-0123-456789abcdef",
150
- "name": "example",
151
- "private": false,
152
- "deleted_at": null,
153
- "users": {
154
- "name": "alice"
155
- }
156
- }
157
- ```
158
-
159
- ### PATCH /apps/:id
160
- Update an existing app.
161
-
162
- ```
163
- PATCH /apps/:id HTTP/1.1
164
- Content-Type: application/json
165
- Host: api.example.com
166
-
167
- {
168
- "name": "example",
169
- "private": false,
170
- "deleted_at": null,
171
- "users": {
172
- "name": "alice"
173
- }
174
- }
175
- ```
176
-
177
- ```
178
- HTTP/1.1 200
179
- Content-Type: application/json
180
-
181
- {
182
- "id": "01234567-89ab-cdef-0123-456789abcdef",
183
- "name": "example",
184
- "private": false,
185
- "deleted_at": null,
186
- "users": {
187
- "name": "alice"
188
- }
189
- }
190
- ```
191
-
192
- ## Recipe
193
-
194
-
195
- ### Properties
196
- * name -
197
- * Example: `"Sushi"`
198
- * Type: string
199
- * user -
200
- * Type: object
201
-
202
- ### GET /recipes
203
- List recipes
204
-
205
- ```
206
- GET /recipes HTTP/1.1
207
- Content-Type: application/json
208
- Host: api.example.com
209
- ```
210
-
211
- ```
212
- HTTP/1.1 200
213
- Content-Type: application/json
214
-
215
- {
216
- "name": "Sushi",
217
- "user": {
218
- "name": "alice"
219
- }
220
- }
221
- ```
222
-
223
- ## User
224
-
225
-
226
- ### Properties
227
- * name -
228
- * Example: `"alice"`
229
- * Type: string
230
-
231
- EOS
20
+ should == File.read(File.expand_path("../../../example-api-documentation.md", __FILE__))
232
21
  end
233
22
  end
234
23
  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.1.1
4
+ version: 0.1.2
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-06-17 00:00:00.000000000 Z
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis