grape-dsl 2.1.0 → 2.2.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/README.md +123 -1
- data/VERSION +1 -1
- data/lib/grape-dsl/doc.rb +32 -24
- data/lib/grape-dsl/doc_mp.rb +12 -12
- data/lib/grape-dsl/dsl.rb +7 -49
- 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: 2abeb7871a3e81c5afdf0c7d2fc19fbd431be3f2
|
4
|
+
data.tar.gz: ca8b7280b2bc738d97261b1bbe5d8cd7ee8f7b41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f0ed9b649f6e167647e1520204b9934a98e9499fa17ee533161d6928ccc39f9b0562502432a7f04d707ebfd94fc694663480ec54a6a04c73914ef61bb7046d8
|
7
|
+
data.tar.gz: 0cda8d3626257d01525f2cd3f5c88a56a4f9ebd36586a3a080065a12c6827dfa90303c4306d25737bbb4d057b37f1e5575b5a698772fb9fff1f0dc8e6cdf1c65
|
data/README.md
CHANGED
@@ -141,4 +141,126 @@ here is an example for the use
|
|
141
141
|
|
142
142
|
end
|
143
143
|
|
144
|
-
```
|
144
|
+
```
|
145
|
+
|
146
|
+
### Documentation
|
147
|
+
|
148
|
+
a simple but useful documentation generation way
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
|
152
|
+
|
153
|
+
class HelloApi < Grape::API
|
154
|
+
|
155
|
+
#> api call description
|
156
|
+
description.desc= "simple api call"
|
157
|
+
|
158
|
+
#> return body for the documentation
|
159
|
+
description.body= {"String"=>"String"}
|
160
|
+
|
161
|
+
#> or type
|
162
|
+
description.content_type= 'JSON'
|
163
|
+
#> params for the call
|
164
|
+
params do
|
165
|
+
requires :something, type: String, desc: "Some string that required"
|
166
|
+
end
|
167
|
+
#> actual get route generation
|
168
|
+
get 'hello' do
|
169
|
+
{"hello"=>"world"}
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
if ARGV.include?('--generate_documentation)
|
176
|
+
|
177
|
+
Grape.create_wiki_doc path: (File.join(Dir.pwd,"README.md")),
|
178
|
+
desc_files: Dir.glob(File.join Dir.pwd,"doc","*").select{|p| !File.directory?(p) },
|
179
|
+
type: :github
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
This will produce the following content in a README.md file
|
186
|
+
-----------------------------------------------------------
|
187
|
+
|
188
|
+
|
189
|
+
## Request: /hello(.:format) call: get part
|
190
|
+
|
191
|
+
### Request description
|
192
|
+
* simple api call
|
193
|
+
|
194
|
+
### request
|
195
|
+
|
196
|
+
* *method:* GET
|
197
|
+
* *path:* /hello(.:format)
|
198
|
+
* *headers:*
|
199
|
+
* application/json
|
200
|
+
* application/text
|
201
|
+
|
202
|
+
|
203
|
+
* _*Parameters*_
|
204
|
+
* _something_
|
205
|
+
* required: true
|
206
|
+
* type: String
|
207
|
+
* desc: Some string that required
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
### response
|
212
|
+
|
213
|
+
#### *body:*
|
214
|
+
```JSON
|
215
|
+
{
|
216
|
+
"String":"String"
|
217
|
+
}
|
218
|
+
```
|
219
|
+
|
220
|
+
|
221
|
+
### response in case of failure
|
222
|
+
|
223
|
+
* *Internal Server Error:500*
|
224
|
+
|
225
|
+
----
|
226
|
+
|
227
|
+
|
228
|
+
or in plain:
|
229
|
+
|
230
|
+
## Request: /hello(.:format) call: get part
|
231
|
+
|
232
|
+
### Request description
|
233
|
+
* simple api call
|
234
|
+
|
235
|
+
### request
|
236
|
+
|
237
|
+
* *method:* GET
|
238
|
+
* *path:* /hello(.:format)
|
239
|
+
* *headers:*
|
240
|
+
* application/json
|
241
|
+
* application/text
|
242
|
+
|
243
|
+
|
244
|
+
* _*Parameters*_
|
245
|
+
* _something_
|
246
|
+
* required: true
|
247
|
+
* type: String
|
248
|
+
* desc: Some string that required
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
### response
|
253
|
+
|
254
|
+
#### *body:*
|
255
|
+
```JSON
|
256
|
+
{
|
257
|
+
"String":"String"
|
258
|
+
}
|
259
|
+
```
|
260
|
+
|
261
|
+
|
262
|
+
### response in case of failure
|
263
|
+
|
264
|
+
* *Internal Server Error:500*
|
265
|
+
|
266
|
+
----
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/lib/grape-dsl/doc.rb
CHANGED
@@ -2,10 +2,6 @@ module GrapeDSL
|
|
2
2
|
module Extend
|
3
3
|
module Doc
|
4
4
|
|
5
|
-
def syntax_highlight target,wrapper_begin,wrapper_end
|
6
|
-
return "#{wrapper_begin}#{target}#{wrapper_end}"
|
7
|
-
end
|
8
|
-
|
9
5
|
# helpers for doc generation
|
10
6
|
def wiki_body(route,wrapper_begin,wrapper_end,wrapper_close)
|
11
7
|
|
@@ -21,12 +17,12 @@ module GrapeDSL
|
|
21
17
|
# debugger
|
22
18
|
#end
|
23
19
|
|
24
|
-
case
|
20
|
+
case true
|
25
21
|
|
26
|
-
when
|
22
|
+
when route.route_description.class <= ::String
|
27
23
|
params= route.route_params
|
28
24
|
|
29
|
-
when
|
25
|
+
when route.route_description.class <= ::Hash
|
30
26
|
|
31
27
|
if !route.route_description[:content_type].nil?
|
32
28
|
content_type= route.route_description[:content_type]
|
@@ -40,7 +36,7 @@ module GrapeDSL
|
|
40
36
|
evalue= "value"
|
41
37
|
end
|
42
38
|
|
43
|
-
when
|
39
|
+
when route.route_description.class <= ::NilClass
|
44
40
|
params= route.route_params
|
45
41
|
params ||= "no return"
|
46
42
|
content_type= "TXT"
|
@@ -51,9 +47,9 @@ module GrapeDSL
|
|
51
47
|
|
52
48
|
end
|
53
49
|
|
54
|
-
case
|
50
|
+
case true
|
55
51
|
|
56
|
-
when
|
52
|
+
when params.class <= ::Hash
|
57
53
|
|
58
54
|
if params == route.route_params
|
59
55
|
tmp_hash= Hash.new
|
@@ -63,9 +59,9 @@ module GrapeDSL
|
|
63
59
|
params= tmp_hash
|
64
60
|
end
|
65
61
|
|
66
|
-
params = params.
|
62
|
+
params = params.convert_all_value_to_grape_dsl_format
|
67
63
|
|
68
|
-
when
|
64
|
+
when params.class <= ::Class
|
69
65
|
begin
|
70
66
|
if params.to_s.include? '::'
|
71
67
|
if params.to_s.downcase.include? 'boolean'
|
@@ -76,7 +72,7 @@ module GrapeDSL
|
|
76
72
|
content_type= "TXT"
|
77
73
|
end
|
78
74
|
|
79
|
-
when
|
75
|
+
when params.class <= ::String
|
80
76
|
content_type= "TXT"
|
81
77
|
|
82
78
|
else
|
@@ -93,9 +89,7 @@ module GrapeDSL
|
|
93
89
|
when "json"
|
94
90
|
begin
|
95
91
|
|
96
|
-
|
97
|
-
|
98
|
-
tmp_array.push syntax_highlight(content_type.to_s,wrapper_begin,wrapper_end)
|
92
|
+
tmp_array.push [wrapper_begin,content_type.to_s,wrapper_end].join
|
99
93
|
|
100
94
|
require "json"
|
101
95
|
|
@@ -327,22 +321,35 @@ module GrapeDSL
|
|
327
321
|
# create request description
|
328
322
|
begin
|
329
323
|
write_out_array.push("\n"+(uni_tab*1)+"#{mheader}Request description")
|
330
|
-
case
|
324
|
+
case true
|
331
325
|
|
332
|
-
when
|
326
|
+
when route.route_description.class <= String
|
333
327
|
route.route_description.each_line do |one_line|
|
334
328
|
write_out_array.push((uni_tab*2)+htsym+one_line.chomp)
|
335
329
|
end
|
336
330
|
|
337
|
-
when
|
331
|
+
when route.route_description.class <= Hash
|
338
332
|
begin
|
339
|
-
|
340
|
-
|
341
|
-
|
333
|
+
|
334
|
+
description_msg = nil
|
335
|
+
|
336
|
+
[:d,:desc,:description].each do |sym|
|
337
|
+
description_msg ||= route.route_description[sym]
|
342
338
|
end
|
343
|
-
|
339
|
+
|
340
|
+
if description_msg.class <= String
|
341
|
+
description_msg= [*description_msg.split("\n")]
|
342
|
+
end
|
343
|
+
|
344
|
+
description_msg ||= "No description available for this path"
|
345
|
+
description_msg= [*description_msg]
|
346
|
+
|
347
|
+
puts description_msg.inspect
|
348
|
+
|
349
|
+
description_msg.each do |one_line|
|
344
350
|
write_out_array.push((uni_tab*2)+htsym+one_line.chomp)
|
345
351
|
end
|
352
|
+
|
346
353
|
end
|
347
354
|
|
348
355
|
|
@@ -407,6 +414,7 @@ module GrapeDSL
|
|
407
414
|
write_out_array.push("\n#{mheader}response\n")
|
408
415
|
end
|
409
416
|
|
417
|
+
#> TODO make better implementation for others to use
|
410
418
|
#create route content_type
|
411
419
|
begin
|
412
420
|
if !Grape::Endpoint.config_obj.nil?
|
@@ -420,7 +428,7 @@ module GrapeDSL
|
|
420
428
|
write_out_array.push ""
|
421
429
|
|
422
430
|
end
|
423
|
-
end
|
431
|
+
end if Grape::Endpoint.respond_to?(:config_obj) && Grape::Endpoint.respond_to?(:header_config_obj)
|
424
432
|
|
425
433
|
# create response bodies
|
426
434
|
begin
|
data/lib/grape-dsl/doc_mp.rb
CHANGED
@@ -3,17 +3,17 @@ module GrapeDSL
|
|
3
3
|
module EXT
|
4
4
|
|
5
5
|
module ArrayMP
|
6
|
-
def
|
6
|
+
def convert_all_value_to_grape_dsl_format
|
7
7
|
|
8
8
|
self.count.times do |index|
|
9
9
|
|
10
|
-
case
|
10
|
+
case true
|
11
11
|
|
12
|
-
when
|
13
|
-
self[index].
|
12
|
+
when self[index].class <= Hash
|
13
|
+
self[index].convert_all_value_to_grape_dsl_format
|
14
14
|
|
15
|
-
when
|
16
|
-
self[index].
|
15
|
+
when self[index].class <= Array
|
16
|
+
self[index].convert_all_value_to_grape_dsl_format
|
17
17
|
|
18
18
|
else
|
19
19
|
self[index]= self[index].to_s
|
@@ -28,17 +28,17 @@ module GrapeDSL
|
|
28
28
|
end
|
29
29
|
|
30
30
|
module HashMP
|
31
|
-
def
|
31
|
+
def convert_all_value_to_grape_dsl_format
|
32
32
|
|
33
33
|
self.each do |key,value|
|
34
34
|
|
35
|
-
case
|
35
|
+
case true
|
36
36
|
|
37
|
-
when
|
38
|
-
value.
|
37
|
+
when value.class <= Hash
|
38
|
+
value.convert_all_value_to_grape_dsl_format
|
39
39
|
|
40
|
-
when
|
41
|
-
value.
|
40
|
+
when value.class <= Array
|
41
|
+
value.convert_all_value_to_grape_dsl_format
|
42
42
|
|
43
43
|
else
|
44
44
|
self[key]= value.to_s
|
data/lib/grape-dsl/dsl.rb
CHANGED
@@ -4,64 +4,22 @@ module GrapeDSL
|
|
4
4
|
|
5
5
|
module APIMNT
|
6
6
|
|
7
|
-
class Description
|
8
|
-
|
9
|
-
def initialize opts={}
|
10
|
-
raise unless opts.class <= ::Hash
|
11
|
-
opts.each{|k,v| self.__send__("#{k}=",v) }
|
12
|
-
end
|
13
|
-
|
14
|
-
def [] sym
|
15
|
-
self.__send__ sym.to_s
|
16
|
-
end
|
17
|
-
|
18
|
-
def []= sym,value
|
19
|
-
self.__send__ "#{sym.to_s}=",value
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_accessor :description,:body,:content_type
|
23
|
-
alias desc= description=
|
24
|
-
alias desc description
|
25
|
-
alias type= content_type=
|
26
|
-
alias type content_type
|
27
|
-
|
28
|
-
def value
|
29
|
-
{description: description,content_type: content_type,body: body}
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
7
|
# defaults
|
35
8
|
# desc -> description for path
|
36
9
|
# body -> return body from the call
|
37
10
|
# convent_type -> real content type
|
38
|
-
def description(
|
11
|
+
def description(opts={})
|
39
12
|
|
40
13
|
@last_description ||= {}
|
41
|
-
unless @last_description[:
|
42
|
-
|
43
|
-
var= ::GrapeDSL::Extend::APIMNT::Description.new(*args)
|
44
|
-
|
45
|
-
unless self.content_types.keys.empty?
|
46
|
-
|
47
|
-
content_type_name= nil
|
48
|
-
[:json,:xml,:txt].each do |element|
|
49
|
-
if self.content_types.keys.include? element
|
50
|
-
content_type_name ||= element.to_s.upcase
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
var.content_type= content_type_name if var.content_type.nil?
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
var.desc= desc.to_s
|
59
|
-
@last_description[:desc]= var
|
60
|
-
|
14
|
+
unless @last_description[:description].class == Hashie::Mash
|
15
|
+
@last_description[:description]= Hashie::Mash.new(opts.merge(desc: @last_description[:desc]))
|
61
16
|
end
|
17
|
+
return @last_description[:description]
|
62
18
|
|
63
|
-
|
19
|
+
end
|
64
20
|
|
21
|
+
def description= obj
|
22
|
+
self.description.desc= obj
|
65
23
|
end
|
66
24
|
|
67
25
|
# mount all the rest api classes that is subclass of the Grape::API
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mpatch
|