apipie-rails 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
  Changelog
3
3
  ===========
4
4
 
5
+ v0.3.3
6
+ ------
7
+
8
+ * Support for describing headers
9
+ [#341](https://github.com/Apipie/apipie-rails/pull/341) [@iliabylich][]
10
+
5
11
  v0.3.2
6
12
  ------
7
13
 
@@ -274,3 +280,4 @@ v0.0.15
274
280
  [@akenger]: https://github.com/akenger
275
281
  [@baweaver]: https://github.com/baweaver
276
282
  [@stormsilver]: https://github.com/stormsilver
283
+ [@iliabylich]: https://github.com/iliabylich
Binary file
@@ -0,0 +1,26 @@
1
+ <% unless headers.blank? %>
2
+ <%= heading(t('apipie.headers'), h_level) %>
3
+ <table class='table'>
4
+ <thead>
5
+ <tr>
6
+ <th><%= t('apipie.header_name') %></th>
7
+ <th><%= t('apipie.description') %></th>
8
+ </tr>
9
+ </thead>
10
+ <tbody>
11
+ <% headers.each do |header| %>
12
+ <tr>
13
+ <td>
14
+ <strong><%= header[:name] %> </strong><br>
15
+ <small>
16
+ <%= header[:options][:required] ? t('apipie.required') : t('apipie.optional') %>
17
+ </small>
18
+ </td>
19
+ <td>
20
+ <%= header[:description].html_safe %>
21
+ </td>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+ <% end %>
@@ -44,3 +44,5 @@
44
44
  </tbody>
45
45
  </table>
46
46
  <% end %>
47
+
48
+ <%= render(:partial => "headers", :locals => {:headers => method[:headers], :h_level => h_level }) %>
@@ -32,6 +32,8 @@
32
32
  <%= @resource[:formats].join(', ') %>
33
33
  <% end %>
34
34
 
35
+ <%= render(:partial => 'headers', :locals => { headers: @resource[:headers], h_level: 2 }) %>
36
+
35
37
  <div class='accordion' id='accordion'>
36
38
 
37
39
  <% @resource[:methods].each do |m| %>
@@ -24,4 +24,6 @@ en:
24
24
  enable_javascript_html: Please enable JavaScript to view the %{comments_href}.
25
25
  comments_powered_by_disqus: comments powered by %{disqus}
26
26
  api_documentation: API documentation
27
+ headers: Headers
28
+ header_name: Header name
27
29
 
@@ -25,6 +25,7 @@ module Apipie
25
25
  :api_from_routes => nil,
26
26
  :errors => [],
27
27
  :params => [],
28
+ :headers => [],
28
29
  :resouce_id => nil,
29
30
  :short_description => nil,
30
31
  :description => nil,
@@ -129,7 +130,6 @@ module Apipie
129
130
  end
130
131
  Apipie.set_controller_versions(self, versions)
131
132
  end
132
-
133
133
  end
134
134
 
135
135
  module Common
@@ -268,6 +268,23 @@ module Apipie
268
268
  @method_params[method]
269
269
  end
270
270
 
271
+ # Describe request header.
272
+ # Headers can't be validated with config.validate_presence = true
273
+ #
274
+ # Example:
275
+ # header 'ClientId', "client-id"
276
+ # def show
277
+ # render :text => headers['HTTP_CLIENT_ID']
278
+ # end
279
+ #
280
+ def header(header_name, description, options = {}) #:doc
281
+ return unless Apipie.active_dsl?
282
+ _apipie_dsl_data[:headers] << {
283
+ name: header_name,
284
+ description: description,
285
+ options: options
286
+ }
287
+ end
271
288
  end
272
289
 
273
290
  # this describes the params, it's in separate module because it's
@@ -17,7 +17,7 @@ module Apipie
17
17
 
18
18
  end
19
19
 
20
- attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :metadata
20
+ attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :metadata, :headers
21
21
 
22
22
  def initialize(method, resource, dsl_data)
23
23
  @method = method.to_s
@@ -48,6 +48,7 @@ module Apipie
48
48
  Apipie::ParamDescription.from_dsl_data(self, args)
49
49
  end
50
50
  @params_ordered = ParamDescription.unify(@params_ordered)
51
+ @headers = dsl_data[:headers]
51
52
  end
52
53
 
53
54
  def id
@@ -142,7 +143,8 @@ module Apipie
142
143
  :params => params_ordered.map{ |param| param.to_json(lang) }.flatten,
143
144
  :examples => @examples,
144
145
  :metadata => @metadata,
145
- :see => see.map(&:to_json)
146
+ :see => see.map(&:to_json),
147
+ :headers => headers
146
148
  }
147
149
  end
148
150
 
@@ -9,10 +9,12 @@ module Apipie
9
9
  # name - human readable alias of resource (Articles)
10
10
  # id - resouce name
11
11
  # formats - acceptable request/response format types
12
+ # headers - array of headers
12
13
  class ResourceDescription
13
14
 
14
15
  attr_reader :controller, :_short_description, :_full_description, :_methods, :_id,
15
- :_path, :_name, :_params_args, :_errors_args, :_formats, :_parent, :_metadata
16
+ :_path, :_name, :_params_args, :_errors_args, :_formats, :_parent, :_metadata,
17
+ :_headers
16
18
 
17
19
  def initialize(controller, resource_name, dsl_data = nil, version = nil, &block)
18
20
 
@@ -39,6 +41,7 @@ module Apipie
39
41
  @_params_args = dsl_data[:params]
40
42
  @_metadata = dsl_data[:meta]
41
43
  @_api_base_url = dsl_data[:api_base_url]
44
+ @_headers = dsl_data[:headers]
42
45
 
43
46
  if dsl_data[:app_info]
44
47
  Apipie.configuration.app_info[_version] = dsl_data[:app_info]
@@ -105,7 +108,8 @@ module Apipie
105
108
  :version => _version,
106
109
  :formats => @_formats,
107
110
  :metadata => @_metadata,
108
- :methods => methods
111
+ :methods => methods,
112
+ :headers => _headers
109
113
  }
110
114
  end
111
115
 
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
@@ -35,6 +35,7 @@ describe UsersController do
35
35
  methods.keys.should include(:create)
36
36
  methods.keys.should include(:update)
37
37
  methods.keys.should include(:two_urls)
38
+ methods.keys.should include(:action_with_headers)
38
39
  end
39
40
 
40
41
  it "should contain info about resource" do
@@ -444,6 +445,57 @@ describe UsersController do
444
445
  a.instance_variable_get('@params_ordered').count.should == 9
445
446
  end
446
447
 
448
+ context 'headers' do
449
+ context 'for methods' do
450
+ let(:expected_required_header) do
451
+ {
452
+ name: :RequredHeaderName,
453
+ description: 'Required header description',
454
+ options: {
455
+ required: true
456
+ }
457
+ }
458
+ end
459
+
460
+ let(:expected_optional_header) do
461
+ {
462
+ name: :OptionalHeaderName,
463
+ description: 'Optional header description',
464
+ options: {
465
+ required: false
466
+ }
467
+ }
468
+ end
469
+
470
+ it 'contains all headers description in method doc' do
471
+ headers = Apipie.get_method_description(UsersController, :action_with_headers).headers
472
+ headers.should be_an(Array)
473
+
474
+ compare_hashes headers[0], expected_required_header
475
+ compare_hashes headers[1], expected_optional_header
476
+ end
477
+ end
478
+
479
+ context 'for resource' do
480
+ let(:expected_resource_header) do
481
+ {
482
+ name: :CommonHeader,
483
+ description: 'Common header description',
484
+ options: {
485
+ required: true
486
+ }
487
+ }
488
+ end
489
+
490
+ it 'contains all headers description in resource doc' do
491
+ headers = Apipie.get_resource_description(UsersController)._headers
492
+ headers.should be_an(Array)
493
+
494
+ compare_hashes headers[0], expected_resource_header
495
+ end
496
+ end
497
+ end
498
+
447
499
  it "should contain all api method description" do
448
500
  method_description = Apipie[UsersController, :two_urls]
449
501
  method_description.class.should be(Apipie::MethodDescription)
@@ -39,6 +39,7 @@ class UsersController < ApplicationController
39
39
  By default, Rails will compile each template to a method in order to render it. When you alter a template,
40
40
  Rails will check the file's modification time and recompile it in development mode.
41
41
  EOS
42
+ header :CommonHeader, 'Common header description', required: true
42
43
  end
43
44
 
44
45
  description <<-eos
@@ -278,4 +279,9 @@ class UsersController < ApplicationController
278
279
  def create_route
279
280
  end
280
281
 
282
+ api :GET, '/users/action_with_headers'
283
+ header :RequredHeaderName, 'Required header description', required: true
284
+ header :OptionalHeaderName, 'Optional header description', required: false
285
+ def action_with_headers
286
+ end
281
287
  end
metadata CHANGED
@@ -1,169 +1,165 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: apipie-rails
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 3
10
+ version: 0.3.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Pavel Pokorny
9
14
  - Ivan Necas
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2015-03-18 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2015-03-23 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
16
23
  name: rails
17
- requirement: !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: 3.0.10
23
- type: :development
24
24
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 19
31
+ segments:
32
+ - 3
33
+ - 0
34
+ - 10
30
35
  version: 3.0.10
31
- - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
32
39
  name: json
33
- requirement: !ruby/object:Gem::Requirement
34
- none: false
35
- requirements:
36
- - - ! '>='
37
- - !ruby/object:Gem::Version
38
- version: '0'
39
- type: :runtime
40
40
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
42
  none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
- - !ruby/object:Gem::Dependency
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
48
53
  name: rspec-rails
49
- requirement: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 2.14.2
55
- type: :development
56
54
  prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
58
56
  none: false
59
- requirements:
57
+ requirements:
60
58
  - - ~>
61
- - !ruby/object:Gem::Version
59
+ - !ruby/object:Gem::Version
60
+ hash: 51
61
+ segments:
62
+ - 2
63
+ - 14
64
+ - 2
62
65
  version: 2.14.2
63
- - !ruby/object:Gem::Dependency
64
- name: sqlite3
65
- requirement: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
66
  type: :development
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: sqlite3
72
70
  prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
79
- - !ruby/object:Gem::Dependency
80
- name: minitest
81
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &id004 !ruby/object:Gem::Requirement
82
72
  none: false
83
- requirements:
84
- - - ! '>='
85
- - !ruby/object:Gem::Version
86
- version: '0'
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
87
80
  type: :development
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: minitest
88
84
  prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
95
- - !ruby/object:Gem::Dependency
96
- name: maruku
97
- requirement: !ruby/object:Gem::Requirement
85
+ requirement: &id005 !ruby/object:Gem::Requirement
98
86
  none: false
99
- requirements:
100
- - - ! '>='
101
- - !ruby/object:Gem::Version
102
- version: '0'
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
103
94
  type: :development
95
+ version_requirements: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ name: maruku
104
98
  prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: RedCloth
113
- requirement: !ruby/object:Gem::Requirement
99
+ requirement: &id006 !ruby/object:Gem::Requirement
114
100
  none: false
115
- requirements:
116
- - - ! '>='
117
- - !ruby/object:Gem::Version
118
- version: '0'
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
119
108
  type: :development
109
+ version_requirements: *id006
110
+ - !ruby/object:Gem::Dependency
111
+ name: RedCloth
120
112
  prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
113
+ requirement: &id007 !ruby/object:Gem::Requirement
122
114
  none: false
123
- requirements:
124
- - - ! '>='
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- - !ruby/object:Gem::Dependency
128
- name: rake
129
- requirement: !ruby/object:Gem::Requirement
130
- none: false
131
- requirements:
132
- - - ! '>='
133
- - !ruby/object:Gem::Version
134
- version: '0'
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
135
122
  type: :development
123
+ version_requirements: *id007
124
+ - !ruby/object:Gem::Dependency
125
+ name: rake
136
126
  prerelease: false
137
- version_requirements: !ruby/object:Gem::Requirement
127
+ requirement: &id008 !ruby/object:Gem::Requirement
138
128
  none: false
139
- requirements:
140
- - - ! '>='
141
- - !ruby/object:Gem::Version
142
- version: '0'
143
- - !ruby/object:Gem::Dependency
144
- name: rdoc
145
- requirement: !ruby/object:Gem::Requirement
146
- none: false
147
- requirements:
148
- - - ! '>='
149
- - !ruby/object:Gem::Version
150
- version: '0'
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
151
136
  type: :development
137
+ version_requirements: *id008
138
+ - !ruby/object:Gem::Dependency
139
+ name: rdoc
152
140
  prerelease: false
153
- version_requirements: !ruby/object:Gem::Requirement
141
+ requirement: &id009 !ruby/object:Gem::Requirement
154
142
  none: false
155
- requirements:
156
- - - ! '>='
157
- - !ruby/object:Gem::Version
158
- version: '0'
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ type: :development
151
+ version_requirements: *id009
159
152
  description: Rails REST API documentation tool
160
- email:
153
+ email:
161
154
  - pajkycz@gmail.com
162
155
  - inecas@redhat.com
163
156
  executables: []
157
+
164
158
  extensions: []
159
+
165
160
  extra_rdoc_files: []
166
- files:
161
+
162
+ files:
167
163
  - .gitignore
168
164
  - .rspec
169
165
  - .travis.yml
@@ -177,6 +173,7 @@ files:
177
173
  - NOTICE
178
174
  - README.rst
179
175
  - Rakefile
176
+ - apipie-rails-0.3.1.gem
180
177
  - apipie-rails.gemspec
181
178
  - app/controllers/apipie/apipies_controller.rb
182
179
  - app/helpers/apipie_helper.rb
@@ -190,6 +187,7 @@ files:
190
187
  - app/public/apipie/stylesheets/bundled/bootstrap.min.css
191
188
  - app/public/apipie/stylesheets/bundled/prettify.css
192
189
  - app/views/apipie/apipies/_disqus.html.erb
190
+ - app/views/apipie/apipies/_headers.html.erb
193
191
  - app/views/apipie/apipies/_languages.erb
194
192
  - app/views/apipie/apipies/_metadata.erb
195
193
  - app/views/apipie/apipies/_method_detail.erb
@@ -304,31 +302,41 @@ files:
304
302
  - spec/lib/validators/array_validator_spec.rb
305
303
  - spec/spec_helper.rb
306
304
  - spec/support/rake.rb
305
+ has_rdoc: true
307
306
  homepage: http://github.com/Pajk/apipie-rails
308
307
  licenses: []
308
+
309
309
  post_install_message:
310
310
  rdoc_options: []
311
- require_paths:
311
+
312
+ require_paths:
312
313
  - lib
313
- required_ruby_version: !ruby/object:Gem::Requirement
314
+ required_ruby_version: !ruby/object:Gem::Requirement
314
315
  none: false
315
- requirements:
316
- - - ! '>='
317
- - !ruby/object:Gem::Version
318
- version: '0'
319
- required_rubygems_version: !ruby/object:Gem::Requirement
316
+ requirements:
317
+ - - ">="
318
+ - !ruby/object:Gem::Version
319
+ hash: 3
320
+ segments:
321
+ - 0
322
+ version: "0"
323
+ required_rubygems_version: !ruby/object:Gem::Requirement
320
324
  none: false
321
- requirements:
322
- - - ! '>='
323
- - !ruby/object:Gem::Version
324
- version: '0'
325
+ requirements:
326
+ - - ">="
327
+ - !ruby/object:Gem::Version
328
+ hash: 3
329
+ segments:
330
+ - 0
331
+ version: "0"
325
332
  requirements: []
333
+
326
334
  rubyforge_project:
327
- rubygems_version: 1.8.23
335
+ rubygems_version: 1.6.2
328
336
  signing_key:
329
337
  specification_version: 3
330
338
  summary: Rails REST API documentation tool
331
- test_files:
339
+ test_files:
332
340
  - spec/controllers/api/v1/architectures_controller_spec.rb
333
341
  - spec/controllers/api/v2/architectures_controller_spec.rb
334
342
  - spec/controllers/api/v2/nested/resources_controller_spec.rb
@@ -395,4 +403,3 @@ test_files:
395
403
  - spec/lib/validators/array_validator_spec.rb
396
404
  - spec/spec_helper.rb
397
405
  - spec/support/rake.rb
398
- has_rdoc: