apipie-rails 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -2,6 +2,15 @@
2
2
  Changelog
3
3
  ===========
4
4
 
5
+ v0.0.24
6
+ -------
7
+
8
+ * fix DOS vulnerability for running in production without use_cache
9
+ * ability to load descriptions from external files
10
+ * improved examples extractor
11
+ * fixed deprecation warnings in Rails 4
12
+ * using StandardError instead of Exception for errors
13
+
5
14
  v0.0.23
6
15
  -------
7
16
 
data/README.rst CHANGED
@@ -781,11 +781,20 @@ For inspiration this is how Textile markup usage looks like:
781
781
  end
782
782
 
783
783
 
784
+ ================
785
+ Modifying Views
786
+ ================
787
+
788
+ To modify the views of your documentation, run ``rails g apipie:views``.
789
+ This will copy the Apipie views to ``app/views/apipie/apipies`` and
790
+ ``app/views/layouts/apipie``.
791
+
792
+
784
793
  ==============
785
794
  Static files
786
795
  ==============
787
796
 
788
- To generate static version of documentation (perhaps to put it on
797
+ To generate a static version of documentation (perhaps to put it on
789
798
  project site or something) run ``rake apipie:static`` task. It will
790
799
  create set of html files (multi-pages, single-page, plain) in your doc
791
800
  directory. By default the documentation for default API version is
@@ -28,10 +28,19 @@ module Apipie
28
28
  @doc = Apipie.to_json(params[:version], params[:resource], params[:method])
29
29
 
30
30
  format.json do
31
- render :json => @doc
31
+ if @doc
32
+ render :json => @doc
33
+ else
34
+ head :not_found
35
+ end
32
36
  end
33
37
 
34
38
  format.html do
39
+ unless @doc
40
+ render 'apipie_404', :status => 404
41
+ return
42
+ end
43
+
35
44
  @versions = Apipie.available_versions
36
45
  @doc = @doc[:docs]
37
46
  if @doc[:resources].blank?
@@ -9,4 +9,6 @@
9
9
  </small>
10
10
  </h1>
11
11
 
12
- Try going to <a href='<%= @doc[:doc_url] %>.html'><%= @doc[:name] %> API documentation homepage</a>
12
+ <% if @doc %>
13
+ Try going to <a href='<%= @doc[:doc_url] %>.html'><%= @doc[:name] %> API documentation homepage</a>
14
+ <% end %>
@@ -225,6 +225,8 @@ module Apipie
225
225
 
226
226
  def to_json(version, resource_name, method_name)
227
227
 
228
+ return unless resource_descriptions.has_key?(version)
229
+
228
230
  _resources = if resource_name.blank?
229
231
  # take just resources which have some methods because
230
232
  # we dont want to show eg ApplicationController as resource
@@ -4,7 +4,7 @@ module Apipie
4
4
  attr_accessor :app_name, :app_info, :copyright, :markup, :disqus_shortname,
5
5
  :api_base_url, :doc_base_url, :required_by_default, :layout,
6
6
  :default_version, :debug, :version_in_url, :namespaced_resources,
7
- :validate, :validate_value, :validate_presence, :authenticate
7
+ :validate, :validate_value, :validate_presence, :authenticate, :doc_path
8
8
 
9
9
 
10
10
  alias_method :validate?, :validate
@@ -123,6 +123,7 @@ module Apipie
123
123
  @debug = false
124
124
  @version_in_url = true
125
125
  @namespaced_resources = false
126
+ @doc_path = "doc"
126
127
  end
127
128
  end
128
129
  end
@@ -144,6 +144,18 @@ module Apipie
144
144
  alias :description :desc
145
145
  alias :full_description :desc
146
146
 
147
+ # describe next method with document in given path
148
+ # in convension, these doc located under "#{Rails.root}/doc"
149
+ # Example:
150
+ # document "hello_world.md"
151
+ # def hello_world
152
+ # puts "hello world"
153
+ # end
154
+ def document path
155
+ content = File.open(File.join(Rails.root, Apipie.configuration.doc_path, path)).read
156
+ desc content
157
+ end
158
+
147
159
  # Describe available request/response formats
148
160
  #
149
161
  # formats ['json', 'jsonp', 'xml']
@@ -152,6 +164,7 @@ module Apipie
152
164
  _apipie_dsl_data[:formats] = formats
153
165
  end
154
166
 
167
+
155
168
  # Describe possible errors
156
169
  #
157
170
  # Example:
@@ -41,7 +41,9 @@ module Apipie
41
41
  if record = call_recorder.record
42
42
  @collector.handle_record(record)
43
43
  end
44
- ensure
44
+ end
45
+
46
+ def clean_call_recorder
45
47
  Thread.current[:apipie_call_recorder] = nil
46
48
  end
47
49
 
@@ -46,7 +46,7 @@ module Apipie
46
46
  def parse_data(data)
47
47
  return nil if data.to_s =~ /^\s*$/
48
48
  JSON.parse(data)
49
- rescue Exception => e
49
+ rescue StandardError => e
50
50
  data
51
51
  end
52
52
 
@@ -98,9 +98,10 @@ module Apipie
98
98
  Apipie::Extractor.call_recorder.analyse_env(env)
99
99
  response = block.call
100
100
  Apipie::Extractor.call_recorder.analyse_response(response)
101
+ Apipie::Extractor.call_finished
101
102
  response
102
103
  ensure
103
- Apipie::Extractor.call_finished
104
+ Apipie::Extractor.clean_call_recorder
104
105
  end
105
106
  end
106
107
 
@@ -112,9 +113,10 @@ module Apipie
112
113
  def process_with_api_recording(*args) # action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
113
114
  ret = process_without_api_recording(*args)
114
115
  Apipie::Extractor.call_recorder.analyze_functional_test(self)
116
+ Apipie::Extractor.call_finished
115
117
  ret
116
118
  ensure
117
- Apipie::Extractor.call_finished
119
+ Apipie::Extractor.clean_call_recorder
118
120
  end
119
121
  end
120
122
 
@@ -140,9 +140,9 @@ module Apipie
140
140
 
141
141
  class ActionDescriptionUpdater
142
142
 
143
- class ControllerNotFound < Exception; end
143
+ class ControllerNotFound < StandardError; end
144
144
 
145
- class ActionNotFound < Exception; end
145
+ class ActionNotFound < StandardError; end
146
146
 
147
147
  def initialize(controller, action)
148
148
  @controller = controller
@@ -61,7 +61,7 @@ module Apipie
61
61
  return true if @allow_nil && value.nil?
62
62
  unless @validator.valid?(value)
63
63
  error = @validator.error
64
- error = ParamError.new(error) unless error.is_a? Exception
64
+ error = ParamError.new(error) unless error.is_a? StandardError
65
65
  raise error
66
66
  end
67
67
  end
@@ -27,10 +27,19 @@ module Apipie
27
27
 
28
28
  def ext
29
29
  @ext ||= begin
30
- ext = ::ActionController::Base.page_cache_extension
30
+ ext = cache_extension
31
31
  "{,#{ext},/index#{ext}}"
32
32
  end
33
33
  end
34
+
35
+ def cache_extension
36
+ if ::ActionController::Base.respond_to?(:default_static_extension)
37
+ ::ActionController::Base.default_static_extension
38
+ else
39
+ ::ActionController::Base.page_cache_extension
40
+ end
41
+
42
+ end
34
43
  end
35
44
 
36
45
  class StaticDispatcher
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.0.23'
2
+ VERSION = '0.0.24'
3
3
  end
@@ -0,0 +1,11 @@
1
+ module Apipie
2
+ class ViewsGenerator < ::Rails::Generators::Base
3
+ source_root File.expand_path("../../../../app/views", __FILE__)
4
+ desc 'Copy Apipie views to your application'
5
+
6
+ def copy_views
7
+ directory 'apipie', 'app/views/apipie'
8
+ directory 'layouts/apipie', 'app/views/layouts/apipie'
9
+ end
10
+ end
11
+ end
@@ -58,8 +58,13 @@ namespace :apipie do
58
58
  end
59
59
  end
60
60
 
61
+ # Attempt to use the Rails application views, otherwise default to built in views
61
62
  def renderer
62
- ActionView::Base.new(File.expand_path("../../../app/views/apipie/apipies", __FILE__))
63
+ if File.directory?("#{Rails.root}/app/views/apipie/apipies")
64
+ ActionView::Base.new("#{Rails.root}/app/views/apipie/apipies")
65
+ else
66
+ ActionView::Base.new(File.expand_path("../../../app/views/apipie/apipies", __FILE__))
67
+ end
63
68
  end
64
69
 
65
70
  def render_page(file_name, template, variables, layout = 'apipie')
@@ -393,6 +393,12 @@ GET /users/15
393
393
  404
394
394
  EOS2
395
395
  end
396
+
397
+ describe "document" do
398
+ it "should be able to load document from markup file" do
399
+ Apipie.get_method_description(UsersController, :desc_from_file).full_description.should include("description from document")
400
+ end
401
+ end
396
402
  end
397
403
 
398
404
  describe "param description" do
@@ -248,4 +248,11 @@ class UsersController < ApplicationController
248
248
  def see_another
249
249
  render :text => 'This is very similar to create action'
250
250
  end
251
+
252
+
253
+ api :GET, '/users/desc_from_file', 'desc from file'
254
+ document 'users/desc_from_file.md'
255
+ def desc_from_file
256
+ render :text => 'document from file action'
257
+ end
251
258
  end
@@ -0,0 +1 @@
1
+ description from document
@@ -24,7 +24,7 @@ describe Apipie::ParamDescription do
24
24
  end
25
25
 
26
26
  it "should pick type validator" do
27
- Apipie::Validator::BaseValidator.should receive(:find).and_return(:validator_instance)
27
+ Apipie::Validator::BaseValidator.should_receive(:find).and_return(:validator_instance)
28
28
  param = Apipie::ParamDescription.new(method_desc, :param, String)
29
29
  param.validator.should == :validator_instance
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apipie-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-04 00:00:00.000000000 Z
13
+ date: 2013-10-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -190,6 +190,7 @@ files:
190
190
  - lib/generators/apipie/install/README
191
191
  - lib/generators/apipie/install/install_generator.rb
192
192
  - lib/generators/apipie/install/templates/initializer.rb.erb
193
+ - lib/generators/apipie/views_generator.rb
193
194
  - lib/tasks/apipie.rake
194
195
  - rel-eng/packages/.readme
195
196
  - rel-eng/packages/rubygem-apipie-rails
@@ -232,6 +233,7 @@ files:
232
233
  - spec/dummy/config/routes.rb
233
234
  - spec/dummy/db/.gitkeep
234
235
  - spec/dummy/doc/apipie_examples.yml
236
+ - spec/dummy/doc/users/desc_from_file.md
235
237
  - spec/dummy/public/404.html
236
238
  - spec/dummy/public/422.html
237
239
  - spec/dummy/public/500.html
@@ -271,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
273
  version: '0'
272
274
  requirements: []
273
275
  rubyforge_project:
274
- rubygems_version: 1.8.25
276
+ rubygems_version: 1.8.23
275
277
  signing_key:
276
278
  specification_version: 3
277
279
  summary: Rails REST API documentation tool
@@ -314,6 +316,7 @@ test_files:
314
316
  - spec/dummy/config/routes.rb
315
317
  - spec/dummy/db/.gitkeep
316
318
  - spec/dummy/doc/apipie_examples.yml
319
+ - spec/dummy/doc/users/desc_from_file.md
317
320
  - spec/dummy/public/404.html
318
321
  - spec/dummy/public/422.html
319
322
  - spec/dummy/public/500.html
@@ -333,3 +336,4 @@ test_files:
333
336
  - spec/lib/resource_description_spec.rb
334
337
  - spec/lib/validator_spec.rb
335
338
  - spec/spec_helper.rb
339
+ has_rdoc: