apipie-rails 0.5.16 → 0.5.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76693e27a28b80ae01788b2e561edf21c696281dfc2e4136849dfbc4c4f32c15
4
- data.tar.gz: 7143177bc11ccf92dec72f636683a46561ac05eaf5e788a1f3184028a6ed7dfe
3
+ metadata.gz: 855ada05457368ea7521d46865242c73a15c33a33546d7b0dac1d2b90d779c70
4
+ data.tar.gz: 0cc30d4f4a38a476cab6ed92b6a4a00c45bd2036c8b35fb8373fbb215fb2ea80
5
5
  SHA512:
6
- metadata.gz: 2d3e61a2f83762bbdcd2d90393f14a617ba0dac25f0a7367d20faa36f7d2829577c34db65ab2fe7902ee133b080030fe7460cea2b56e167b772a12d86a9aef4c
7
- data.tar.gz: a2dec8a9cadfbf5ed44df8868c23af5ed8de9eff3b349222a2a829ee09773725e6dabbd1af6f155a1d1800a1636284f2db37f683c3f30b70dfa6442a71f77972
6
+ metadata.gz: 9b0ba79aee65ed21249fa35336166783697719fabc74831816513ea1d0b91162bde342b51fad08121ea38c27f5015bbf196ac524049dcbbc8635dd0a57f13cff
7
+ data.tar.gz: 0f9f593ee579dba0baf16175e8c9d916dd370eba6a5c37cee4df2a92dea1efe0ea936b2444597274dd327244063000bb3a9cff454413956cd98bd27c5652afc6
@@ -16,6 +16,8 @@ gemfile:
16
16
  - Gemfile.rails60 # Min ruby 2.5.0
17
17
  matrix:
18
18
  exclude:
19
+ - rvm: 2.5.3
20
+ gemfile: Gemfile.rails42
19
21
  - rvm: 2.6.0
20
22
  gemfile: Gemfile.rails42
21
23
  - rvm: 2.2.10
@@ -1,6 +1,13 @@
1
1
  Changelog
2
2
  ===========
3
3
 
4
+ [v0.5.17](https://github.com/Apipie/apipie-rails/tree/v0.5.17) (2020-01-20)
5
+ --------
6
+
7
+ [Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.5.16...v0.5.17)
8
+
9
+ - Allows update metadata for methods [\#667](https://github.com/Apipie/apipie-rails/pull/667) ([speckins](https://github.com/speckins))
10
+
4
11
  [v0.5.16](https://github.com/Apipie/apipie-rails/tree/v0.5.16) (2019-05-22)
5
12
  --------
6
13
 
@@ -208,7 +215,7 @@ v0.3.2
208
215
  v0.3.1
209
216
  ------
210
217
 
211
- * Support for ``api!`` keyword in concerns
218
+ * Support for ``api!`` keyword in concerns
212
219
  [#322](https://github.com/Apipie/apipie-rails/pull/322) [@iNecas][]
213
220
  * More explicit ordering of the static dispatcher middleware
214
221
  [#315](https://github.com/Apipie/apipie-rails/pull/315) [@iNecas][]
@@ -4,3 +4,4 @@ gemspec
4
4
 
5
5
  gem 'rails', '~> 4.1.0'
6
6
  gem 'mime-types', '~> 2.99.3'
7
+ gem 'test_engine', path: 'spec/dummy/components/test_engine', group: :test
@@ -10,3 +10,5 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1.0')
10
10
  gem 'nokogiri', '~> 1.6.8'
11
11
  gem 'rdoc', '~> 4.2.2'
12
12
  end
13
+
14
+ gem 'test_engine', path: 'spec/dummy/components/test_engine', group: :test
@@ -6,3 +6,4 @@ gem 'rails', '~> 5.0.0'
6
6
  gem 'mime-types', '~> 2.99.3'
7
7
  gem 'rails-controller-testing'
8
8
 
9
+ gem 'test_engine', path: 'spec/dummy/components/test_engine', group: :test
@@ -5,3 +5,5 @@ gemspec
5
5
  gem 'rails', '~> 5.1.0.rc1'
6
6
  gem 'mime-types', '~> 2.99.3'
7
7
  gem 'rails-controller-testing'
8
+
9
+ gem 'test_engine', path: 'spec/dummy/components/test_engine', group: :test
@@ -10,3 +10,5 @@ gem 'rspec-core', git: 'https://github.com/rspec/rspec-core'
10
10
  gem 'rspec-mocks', git: 'https://github.com/rspec/rspec-mocks'
11
11
  gem 'rspec-support', git: 'https://github.com/rspec/rspec-support'
12
12
  gem 'rspec-expectations', git: 'https://github.com/rspec/rspec-expectations'
13
+
14
+ gem 'test_engine', path: 'spec/dummy/components/test_engine', group: :test
@@ -2,6 +2,8 @@ require 'i18n'
2
2
  require 'json'
3
3
  require 'active_support/hash_with_indifferent_access'
4
4
 
5
+ require 'apipie/core_ext/route.rb'
6
+
5
7
  require "apipie/routing"
6
8
  require "apipie/markup"
7
9
  require "apipie/apipie_module"
@@ -29,7 +29,7 @@ module Apipie
29
29
  @controller_to_resource_id[controller] = resource_id
30
30
  end
31
31
 
32
- def rails_routes(route_set = nil)
32
+ def rails_routes(route_set = nil, base_url = "")
33
33
  if route_set.nil? && @rails_routes
34
34
  return @rails_routes
35
35
  end
@@ -40,10 +40,13 @@ module Apipie
40
40
  flatten_routes = []
41
41
 
42
42
  route_set.routes.each do |route|
43
- if route.app.respond_to?(:routes) && route.app.routes.is_a?(ActionDispatch::Routing::RouteSet)
44
- # recursively go though the moutned engines
45
- flatten_routes.concat(rails_routes(route.app.routes))
43
+ # This is a hack to workaround a bug in apipie with Rails 4.2.5.1 or newer. See https://github.com/Apipie/apipie-rails/issues/415
44
+ route_app = Rails::VERSION::STRING.to_f >= 4.2 ? route.app.app : route.app
45
+ if route_app.respond_to?(:routes) && route_app.routes.is_a?(ActionDispatch::Routing::RouteSet)
46
+ # recursively go though the mounted engines
47
+ flatten_routes.concat(rails_routes(route_app.routes, File.join(base_url, route.path.spec.to_s)))
46
48
  else
49
+ route.base_url = base_url
47
50
  flatten_routes << route
48
51
  end
49
52
  end
@@ -0,0 +1,9 @@
1
+ module Apipie
2
+ module BaseUrlExtension
3
+ attr_accessor :base_url
4
+ end
5
+ end
6
+
7
+ class ActionDispatch::Journey::Route
8
+ include Apipie::BaseUrlExtension
9
+ end
@@ -488,19 +488,33 @@ module Apipie
488
488
  # param_names.each { |p| param p, String }
489
489
  # end
490
490
  # end
491
- def apipie_update_params(methods, *args, &block)
491
+ def _apipie_update_params(method_desc, dsl_data)
492
+ params_ordered = dsl_data[:params].map do |args|
493
+ Apipie::ParamDescription.from_dsl_data(method_desc, args)
494
+ end
495
+ ParamDescription.merge(method_desc.params_ordered_self, params_ordered)
496
+ end
497
+
498
+ def _apipie_update_meta(method_desc, dsl_data)
499
+ return unless dsl_data[:meta] && dsl_data[:meta].is_a?(Hash)
500
+
501
+ method_desc.metadata ||= {}
502
+ method_desc.metadata.merge!(dsl_data[:meta])
503
+ end
504
+
505
+ def apipie_update_methods(methods, *args, &block)
492
506
  methods.each do |method|
493
- method_description = Apipie.get_method_description(self, method)
494
- unless method_description
507
+ method_desc = Apipie.get_method_description(self, method)
508
+ unless method_desc
495
509
  raise "Could not find method description for #{self}##{method}. Was the method defined?"
496
510
  end
497
511
  dsl_data = _apipie_eval_dsl(*args, &block)
498
- params_ordered = dsl_data[:params].map do |args|
499
- Apipie::ParamDescription.from_dsl_data(method_description, args)
500
- end
501
- ParamDescription.merge(method_description.params_ordered_self, params_ordered)
512
+ _apipie_update_params(method_desc, dsl_data)
513
+ _apipie_update_meta(method_desc, dsl_data)
502
514
  end
503
515
  end
516
+ # backwards compatibility
517
+ alias_method :apipie_update_params, :apipie_update_methods
504
518
 
505
519
  def _apipie_concern_subst
506
520
  @_apipie_concern_subst ||= {:controller_path => self.controller_path,
@@ -550,7 +564,7 @@ module Apipie
550
564
  controller._apipie_define_validators(description)
551
565
  end
552
566
  _apipie_concern_update_api_blocks.each do |(methods, block)|
553
- controller.apipie_update_params(methods, &block)
567
+ controller.apipie_update_methods(methods, &block)
554
568
  end
555
569
  end
556
570
 
@@ -17,7 +17,8 @@ module Apipie
17
17
 
18
18
  end
19
19
 
20
- attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :metadata, :headers, :show
20
+ attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :headers, :show
21
+ attr_accessor :metadata
21
22
 
22
23
  def initialize(method, resource, dsl_data)
23
24
  @method = method.to_s
@@ -16,7 +16,7 @@ module Apipie
16
16
  end
17
17
 
18
18
  def format_path(rails_route)
19
- rails_route.path.spec.to_s.gsub('(.:format)', '')
19
+ File.join(rails_route.base_url, rails_route.path.spec.to_s.gsub('(.:format)', ''))
20
20
  end
21
21
 
22
22
  def format_verb(rails_route)
@@ -651,14 +651,15 @@ module Apipie
651
651
 
652
652
  def add_headers_from_hash(swagger_params_array, headers)
653
653
  swagger_headers = headers.map do |header|
654
- {
654
+ header_hash = {
655
655
  name: header[:name],
656
656
  in: 'header',
657
657
  required: header[:options][:required],
658
658
  description: header[:description],
659
659
  type: header[:options][:type] || 'string'
660
660
  }
661
-
661
+ header_hash[:default] = header[:options][:default] if header[:options][:default]
662
+ header_hash
662
663
  end
663
664
  swagger_params_array.push(*swagger_headers)
664
665
  end
@@ -129,6 +129,8 @@ module Apipie
129
129
  'array'
130
130
  elsif @type.ancestors.include? Numeric
131
131
  'numeric'
132
+ elsif @type.ancestors.include? File
133
+ 'file'
132
134
  else
133
135
  'string'
134
136
  end
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.5.16'
2
+ VERSION = '0.5.17'
3
3
  end
@@ -7,5 +7,8 @@ describe ExtendedController do
7
7
  user_param = Apipie["extended#create"].params[:user]
8
8
  expect(user_param.validator.params_ordered.map(&:name)).to eq [:name, :password, :from_concern]
9
9
  end
10
- end
11
10
 
11
+ it 'should include updated metadata' do
12
+ expect(Apipie['extended#create'].metadata).to eq metadata: 'data'
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe TestEngine::MemesController do
4
+
5
+ describe "#index" do
6
+ it "should have the full mounted path of engine" do
7
+ Apipie.routes_for_action(TestEngine::MemesController, :index, {}).first[:path].should eq("/test/memes")
8
+ end
9
+ end
10
+ end
@@ -488,12 +488,24 @@ describe UsersController do
488
488
  }
489
489
  end
490
490
 
491
+ let(:expected_header_with_default) do
492
+ {
493
+ name: :HeaderNameWithDefaultValue,
494
+ description: 'Header with default value',
495
+ options: {
496
+ required: true,
497
+ default: 'default value'
498
+ }
499
+ }
500
+ end
501
+
491
502
  it 'contains all headers description in method doc' do
492
503
  headers = Apipie.get_method_description(UsersController, :action_with_headers).headers
493
504
  expect(headers).to be_an(Array)
494
505
 
495
506
  compare_hashes headers[0], expected_required_header
496
507
  compare_hashes headers[1], expected_optional_header
508
+ compare_hashes headers[2], expected_header_with_default
497
509
  end
498
510
  end
499
511
 
@@ -6,6 +6,7 @@ module Concerns
6
6
  param :user, Hash do
7
7
  param :from_concern, String, :desc => 'param from concern', :allow_nil => false
8
8
  end
9
+ meta metadata: 'data'
9
10
  end
10
11
  end
11
12
  end
@@ -292,6 +292,7 @@ class UsersController < ApplicationController
292
292
  api :GET, '/users/action_with_headers'
293
293
  header :RequredHeaderName, 'Required header description', required: true
294
294
  header :OptionalHeaderName, 'Optional header description', required: false, type: 'string'
295
+ header :HeaderNameWithDefaultValue, 'Header with default value', required: true, default: 'default value'
295
296
  def action_with_headers
296
297
  end
297
298
  end
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in test_engine.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
@@ -0,0 +1,4 @@
1
+ module TestEngine
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,37 @@
1
+ module TestEngine
2
+ class MemesController < TestEngine::ApplicationController
3
+ api! 'Returns a list of all good memes on Twitter'
4
+ param :api_token, String, required: true, desc: 'Your Twitter API token'
5
+ def index
6
+ render json: []
7
+ end
8
+
9
+ api! 'Shows info about a particular meme on Twitter'
10
+ param :id, :number, required: true, desc: 'ID of the meme'
11
+ def show
12
+ render json: {id: params[:id]}
13
+ end
14
+
15
+ api! 'Create a new meme on Twitter'
16
+ param :api_token, String, required: true, desc: 'Your Twitter API token'
17
+ param :name, String, required: true, desc: 'Name of your meme'
18
+ param :src_url, String, required: true, desc: 'URL for your meme'
19
+ def create
20
+ render json: {name: params[:name], src_url: params[:src_url]}, status: :created
21
+ end
22
+
23
+ api! 'Update a meme on Twitter'
24
+ param :api_token, String, required: true, desc: 'Your Twitter API token'
25
+ param :name, String, required: false, desc: 'Name of your meme'
26
+ param :src_url, String, required: false, desc: 'URL for your meme'
27
+ def update
28
+ render json: {name: params[:name], src_url: params[:src_url]}
29
+ end
30
+
31
+ api! 'Delete a meme on Twitter'
32
+ param :id, :number, required: true, desc: 'ID of the meme'
33
+ def destroy
34
+ head :ok
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ TestEngine::Engine.routes.draw do
2
+ resources :memes, only: [:index, :show, :create, :update, :destroy]
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'apipie-rails'
2
+
3
+ module TestEngine
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace TestEngine
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ # Describe your gem and declare its dependencies:
4
+ Gem::Specification.new do |s|
5
+ s.name = 'test_engine'
6
+ s.version = '0.0.1'
7
+ s.summary = 'Test Engine'
8
+ s.authors = 'Test Author'
9
+
10
+ s.files = Dir['{app,config,db,lib}/**/*']
11
+ end
@@ -8,6 +8,7 @@ require "action_mailer/railtie"
8
8
 
9
9
  Bundler.require
10
10
  require "apipie-rails"
11
+ require "test_engine"
11
12
 
12
13
  module Dummy
13
14
  class Application < Rails::Application
@@ -1,5 +1,7 @@
1
1
  Dummy::Application.routes.draw do
2
2
 
3
+ mount TestEngine::Engine => '/test'
4
+
3
5
  scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
4
6
 
5
7
  scope '/api' do
@@ -8,6 +8,7 @@ require File.expand_path("../dummy/config/environment", __FILE__)
8
8
  require 'rspec/rails'
9
9
 
10
10
  require 'apipie-rails'
11
+ require 'test_engine'
11
12
 
12
13
  module Rails4Compatibility
13
14
  module Testing
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.5.16
4
+ version: 0.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Pokorny
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-22 00:00:00.000000000 Z
12
+ date: 2020-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -208,6 +208,7 @@ files:
208
208
  - lib/apipie/apipie_module.rb
209
209
  - lib/apipie/application.rb
210
210
  - lib/apipie/configuration.rb
211
+ - lib/apipie/core_ext/route.rb
211
212
  - lib/apipie/dsl_definition.rb
212
213
  - lib/apipie/error_description.rb
213
214
  - lib/apipie/errors.rb
@@ -247,6 +248,7 @@ files:
247
248
  - spec/controllers/apipies_controller_spec.rb
248
249
  - spec/controllers/concerns_controller_spec.rb
249
250
  - spec/controllers/extended_controller_spec.rb
251
+ - spec/controllers/memes_controller_spec.rb
250
252
  - spec/controllers/users_controller_spec.rb
251
253
  - spec/dummy/Rakefile
252
254
  - spec/dummy/app/controllers/api/base_controller.rb
@@ -271,6 +273,13 @@ files:
271
273
  - spec/dummy/app/controllers/twitter_example_controller.rb
272
274
  - spec/dummy/app/controllers/users_controller.rb
273
275
  - spec/dummy/app/views/layouts/application.html.erb
276
+ - spec/dummy/components/test_engine/Gemfile
277
+ - spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb
278
+ - spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb
279
+ - spec/dummy/components/test_engine/config/routes.rb
280
+ - spec/dummy/components/test_engine/db/.gitkeep
281
+ - spec/dummy/components/test_engine/lib/test_engine.rb
282
+ - spec/dummy/components/test_engine/test_engine.gemspec
274
283
  - spec/dummy/config.ru
275
284
  - spec/dummy/config/application.rb
276
285
  - spec/dummy/config/boot.rb
@@ -333,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
333
342
  version: '0'
334
343
  requirements: []
335
344
  rubyforge_project:
336
- rubygems_version: 2.7.6
345
+ rubygems_version: 2.7.10
337
346
  signing_key:
338
347
  specification_version: 4
339
348
  summary: Rails REST API documentation tool
@@ -344,6 +353,7 @@ test_files:
344
353
  - spec/controllers/apipies_controller_spec.rb
345
354
  - spec/controllers/concerns_controller_spec.rb
346
355
  - spec/controllers/extended_controller_spec.rb
356
+ - spec/controllers/memes_controller_spec.rb
347
357
  - spec/controllers/users_controller_spec.rb
348
358
  - spec/dummy/Rakefile
349
359
  - spec/dummy/app/controllers/api/base_controller.rb
@@ -368,6 +378,13 @@ test_files:
368
378
  - spec/dummy/app/controllers/twitter_example_controller.rb
369
379
  - spec/dummy/app/controllers/users_controller.rb
370
380
  - spec/dummy/app/views/layouts/application.html.erb
381
+ - spec/dummy/components/test_engine/Gemfile
382
+ - spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb
383
+ - spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb
384
+ - spec/dummy/components/test_engine/config/routes.rb
385
+ - spec/dummy/components/test_engine/db/.gitkeep
386
+ - spec/dummy/components/test_engine/lib/test_engine.rb
387
+ - spec/dummy/components/test_engine/test_engine.gemspec
371
388
  - spec/dummy/config.ru
372
389
  - spec/dummy/config/application.rb
373
390
  - spec/dummy/config/boot.rb