apipie-rails 0.3.6 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +67 -0
- data/.github/workflows/rubocop-challenger.yml +28 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +37 -0
- data/.rubocop_todo.yml +1991 -0
- data/CHANGELOG.md +246 -2
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.rst +646 -25
- data/Rakefile +0 -5
- data/apipie-rails.gemspec +14 -9
- data/app/controllers/apipie/apipies_controller.rb +51 -20
- data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
- data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
- data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
- data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
- data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
- data/app/views/apipie/apipies/_method_detail.erb +21 -0
- data/app/views/apipie/apipies/_params.html.erb +4 -2
- data/app/views/apipie/apipies/index.html.erb +5 -1
- data/app/views/apipie/apipies/resource.html.erb +3 -0
- data/app/views/layouts/apipie/apipie.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/config/locales/fr.yml +31 -0
- data/config/locales/it.yml +31 -0
- data/config/locales/ja.yml +31 -0
- data/config/locales/ko.yml +31 -0
- data/config/locales/pt-BR.yml +1 -1
- data/gemfiles/Gemfile.rails50 +10 -0
- data/gemfiles/Gemfile.rails51 +10 -0
- data/gemfiles/Gemfile.rails52 +10 -0
- data/gemfiles/Gemfile.rails60 +17 -0
- data/gemfiles/Gemfile.rails61 +17 -0
- data/gemfiles/Gemfile.rails70 +17 -0
- data/lib/apipie/apipie_module.rb +22 -4
- data/lib/apipie/application.rb +54 -25
- data/lib/apipie/configuration.rb +26 -4
- data/lib/apipie/core_ext/route.rb +9 -0
- data/lib/apipie/dsl_definition.rb +168 -16
- data/lib/apipie/error_description.rb +9 -2
- data/lib/apipie/errors.rb +34 -0
- data/lib/apipie/extractor/collector.rb +4 -0
- data/lib/apipie/extractor/recorder.rb +14 -12
- data/lib/apipie/extractor/writer.rb +86 -58
- data/lib/apipie/extractor.rb +5 -5
- data/lib/apipie/generator/generator.rb +2 -0
- data/lib/apipie/generator/swagger/swagger.rb +2 -0
- data/lib/apipie/generator/swagger/type.rb +16 -0
- data/lib/apipie/generator/swagger/type_extractor.rb +70 -0
- data/lib/apipie/generator/swagger/warning.rb +77 -0
- data/lib/apipie/generator/swagger/warning_writer.rb +48 -0
- data/lib/apipie/markup.rb +14 -11
- data/lib/apipie/method_description/api.rb +12 -0
- data/lib/apipie/method_description/apis_service.rb +82 -0
- data/lib/apipie/method_description.rb +51 -49
- data/lib/apipie/param_description.rb +63 -5
- data/lib/apipie/resource_description.rb +11 -4
- data/lib/apipie/response_description.rb +131 -0
- data/lib/apipie/response_description_adapter.rb +200 -0
- data/lib/apipie/routes_formatter.rb +1 -1
- data/lib/apipie/rspec/response_validation_helper.rb +194 -0
- data/lib/apipie/static_dispatcher.rb +5 -2
- data/lib/apipie/swagger_generator.rb +717 -0
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/validator.rb +83 -9
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +15 -4
- data/lib/generators/apipie/install/install_generator.rb +1 -1
- data/lib/generators/apipie/views_generator.rb +1 -1
- data/lib/tasks/apipie.rake +115 -15
- data/rel-eng/gem_release.ipynb +398 -0
- data/spec/controllers/apipies_controller_spec.rb +79 -14
- data/spec/controllers/concerns_controller_spec.rb +2 -2
- data/spec/controllers/extended_controller_spec.rb +14 -0
- data/spec/controllers/included_param_group_controller_spec.rb +13 -0
- data/spec/controllers/memes_controller_spec.rb +10 -0
- data/spec/controllers/users_controller_spec.rb +139 -76
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/controllers/application_controller.rb +5 -1
- data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
- data/spec/dummy/app/controllers/extended_controller.rb +14 -0
- data/spec/dummy/app/controllers/extending_concern.rb +10 -0
- data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
- data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
- data/spec/dummy/app/controllers/pets_controller.rb +408 -0
- data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
- data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +5 -7
- data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
- data/spec/dummy/app/controllers/tagged_dogs_controller.rb +15 -0
- data/spec/dummy/app/controllers/twitter_example_controller.rb +5 -0
- data/spec/dummy/app/controllers/users_controller.rb +26 -12
- data/spec/dummy/app/helpers/random_param_group.rb +8 -0
- data/spec/dummy/components/test_engine/Gemfile +6 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb +4 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb +37 -0
- data/spec/dummy/components/test_engine/config/routes.rb +3 -0
- data/spec/dummy/components/test_engine/db/.gitkeep +0 -0
- data/spec/dummy/components/test_engine/lib/test_engine.rb +7 -0
- data/spec/dummy/components/test_engine/test_engine.gemspec +11 -0
- data/spec/dummy/config/application.rb +6 -4
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +3 -3
- data/spec/dummy/config/environments/production.rb +3 -3
- data/spec/dummy/config/environments/test.rb +3 -5
- data/spec/dummy/config/initializers/apipie.rb +5 -3
- data/spec/dummy/config/routes.rb +25 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/script/rails +2 -2
- data/spec/lib/application_spec.rb +1 -1
- data/spec/lib/extractor/writer_spec.rb +37 -7
- data/spec/lib/file_handler_spec.rb +25 -0
- data/spec/lib/generator/swagger/type_extractor_spec.rb +61 -0
- data/spec/lib/generator/swagger/warning_spec.rb +51 -0
- data/spec/lib/generator/swagger/warning_writer_spec.rb +59 -0
- data/spec/lib/method_description/apis_service_spec.rb +60 -0
- data/spec/lib/method_description_spec.rb +34 -0
- data/spec/lib/param_description_spec.rb +90 -4
- data/spec/lib/rake_spec.rb +2 -4
- data/spec/lib/swagger/openapi_2_0_schema.json +1607 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +154 -0
- data/spec/lib/swagger/response_validation_spec.rb +104 -0
- data/spec/lib/swagger/swagger_dsl_spec.rb +658 -0
- data/spec/lib/validator_spec.rb +59 -1
- data/spec/lib/validators/array_validator_spec.rb +28 -8
- data/spec/spec_helper.rb +49 -3
- data/spec/support/custom_bool_validator.rb +17 -0
- metadata +104 -99
- data/.travis.yml +0 -12
- data/Gemfile +0 -7
- data/Gemfile.rails32 +0 -6
- data/Gemfile.rails40 +0 -5
- data/Gemfile.rails41 +0 -5
- data/Gemfile.rails42 +0 -5
- data/lib/apipie/client/generator.rb +0 -135
@@ -4,7 +4,7 @@ class UsersController < ApplicationController
|
|
4
4
|
short 'Site members'
|
5
5
|
path '/users'
|
6
6
|
formats ['json']
|
7
|
-
param :id,
|
7
|
+
param :id, Integer, :desc => "User ID", :required => false
|
8
8
|
param :legacy_param, Hash, :desc => 'Deprecated parameter not documented', :show => false, :required => false do
|
9
9
|
param :resource_param, Hash, :desc => 'Param description for all methods' do
|
10
10
|
param :ausername, String, :desc => "Username for login", :required => true
|
@@ -192,15 +192,15 @@ class UsersController < ApplicationController
|
|
192
192
|
end
|
193
193
|
def show
|
194
194
|
unless params[:session] == "secret_hash"
|
195
|
-
render :
|
195
|
+
render :plain => "Not authorized", :status => 401
|
196
196
|
return
|
197
197
|
end
|
198
198
|
|
199
199
|
unless params[:id].to_i == 5
|
200
|
-
render :
|
200
|
+
render :plain => "Not Found", :status => 404 and return
|
201
201
|
end
|
202
202
|
|
203
|
-
render :
|
203
|
+
render :plain => "OK"
|
204
204
|
end
|
205
205
|
|
206
206
|
def_param_group :credentials do
|
@@ -221,8 +221,10 @@ class UsersController < ApplicationController
|
|
221
221
|
param :permalink, String
|
222
222
|
end
|
223
223
|
param :facts, Hash, :desc => "Additional optional facts about the user", :allow_nil => true
|
224
|
+
param :age, :number, :desc => "Age is just a number", :allow_blank => true
|
225
|
+
error :unprocessable_entity, 'Unprocessable Entity'
|
224
226
|
def create
|
225
|
-
render :
|
227
|
+
render :plain => "OK #{params.inspect}"
|
226
228
|
end
|
227
229
|
|
228
230
|
api :PUT, "/users/:id", "Update an user"
|
@@ -231,13 +233,13 @@ class UsersController < ApplicationController
|
|
231
233
|
param :comment, String
|
232
234
|
end
|
233
235
|
def update
|
234
|
-
render :
|
236
|
+
render :plain => "OK #{params.inspect}"
|
235
237
|
end
|
236
238
|
|
237
239
|
api :POST, "/users/admin", "Create admin user"
|
238
240
|
param_group :user, :as => :create
|
239
241
|
def admin_create
|
240
|
-
render :
|
242
|
+
render :plain => "OK #{params.inspect}"
|
241
243
|
end
|
242
244
|
|
243
245
|
api :GET, "/users", "List users"
|
@@ -247,14 +249,14 @@ class UsersController < ApplicationController
|
|
247
249
|
param :oauth, nil,
|
248
250
|
:desc => "Hide this global param (eg dont need auth here)"
|
249
251
|
def index
|
250
|
-
render :
|
252
|
+
render :plain => "List of users"
|
251
253
|
end
|
252
254
|
|
253
255
|
api :GET, '/company_users', 'Get company users'
|
254
256
|
api :GET, '/company/:id/users', 'Get users working in given company'
|
255
257
|
param :id, Integer, :desc => "Company ID"
|
256
258
|
def two_urls
|
257
|
-
render :
|
259
|
+
render :plain => 'List of users'
|
258
260
|
end
|
259
261
|
|
260
262
|
api :GET, '/users/see_another', 'Boring method'
|
@@ -263,14 +265,25 @@ class UsersController < ApplicationController
|
|
263
265
|
see 'development#users#index', "very interesting method reference"
|
264
266
|
desc 'This method is boring, look at users#create. It is hidden from documentation.'
|
265
267
|
def see_another
|
266
|
-
render :
|
268
|
+
render :plain => 'This is very similar to create action'
|
267
269
|
end
|
268
270
|
|
271
|
+
api :GET, '/users/by_department', 'show users from a specific department'
|
272
|
+
param :department, ["finance", "operations", "sales", "marketing", "HR"], required: false, default_value: "sales"
|
273
|
+
def get_by_department
|
274
|
+
render :plain => 'nothing to see here'
|
275
|
+
end
|
276
|
+
|
277
|
+
api :GET, '/users/in_departments', 'show users from specific departments'
|
278
|
+
param :departments, Array, in: ["finance", "operations", "sales", "marketing", "HR"], default_value: ['sales']
|
279
|
+
def get_in_departments
|
280
|
+
render :plain => 'nothing to see here'
|
281
|
+
end
|
269
282
|
|
270
283
|
api :GET, '/users/desc_from_file', 'desc from file'
|
271
284
|
document 'users/desc_from_file.md'
|
272
285
|
def desc_from_file
|
273
|
-
render :
|
286
|
+
render :plain => 'document from file action'
|
274
287
|
end
|
275
288
|
|
276
289
|
api! 'Create user'
|
@@ -284,7 +297,8 @@ class UsersController < ApplicationController
|
|
284
297
|
|
285
298
|
api :GET, '/users/action_with_headers'
|
286
299
|
header :RequredHeaderName, 'Required header description', required: true
|
287
|
-
header :OptionalHeaderName, 'Optional header description', required: false
|
300
|
+
header :OptionalHeaderName, 'Optional header description', required: false, type: 'string'
|
301
|
+
header :HeaderNameWithDefaultValue, 'Header with default value', required: true, default: 'default value'
|
288
302
|
def action_with_headers
|
289
303
|
end
|
290
304
|
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
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.push File.expand_path('lib', __dir__)
|
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
|
@@ -1,13 +1,11 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('boot', __dir__)
|
2
2
|
|
3
|
-
require "active_model/railtie"
|
4
|
-
require "active_record/railtie"
|
5
3
|
require "action_controller/railtie"
|
6
4
|
require "action_view/railtie"
|
7
|
-
require "action_mailer/railtie"
|
8
5
|
|
9
6
|
Bundler.require
|
10
7
|
require "apipie-rails"
|
8
|
+
require "test_engine"
|
11
9
|
|
12
10
|
module Dummy
|
13
11
|
class Application < Rails::Application
|
@@ -41,5 +39,9 @@ module Dummy
|
|
41
39
|
|
42
40
|
# Configure sensitive parameters which will be filtered from the log file.
|
43
41
|
config.filter_parameters += [:password]
|
42
|
+
|
43
|
+
config.to_prepare do
|
44
|
+
ExtendedController.send(:include, ExtendingConcern)
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
gemfile = File.expand_path('
|
2
|
+
gemfile = File.expand_path('../../../Gemfile', __dir__)
|
3
3
|
|
4
4
|
if File.exist?(gemfile)
|
5
5
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -7,4 +7,4 @@ if File.exist?(gemfile)
|
|
7
7
|
Bundler.setup
|
8
8
|
end
|
9
9
|
|
10
|
-
$:.unshift File.expand_path('
|
10
|
+
$:.unshift File.expand_path('../../../lib', __dir__)
|
@@ -13,13 +13,13 @@ Dummy::Application.configure do
|
|
13
13
|
config.consider_all_requests_local = true
|
14
14
|
config.action_controller.perform_caching = false
|
15
15
|
|
16
|
-
# Don't care if the mailer can't send
|
17
|
-
config.action_mailer.raise_delivery_errors = false
|
18
|
-
|
19
16
|
# Print deprecation notices to the Rails logger
|
20
17
|
config.active_support.deprecation = :log
|
21
18
|
|
22
19
|
# Only use best-standards-support built into browsers
|
23
20
|
config.action_dispatch.best_standards_support = :builtin
|
21
|
+
|
22
|
+
# Do not eager load code on boot. (Rails 5)
|
23
|
+
config.eager_load = false
|
24
24
|
end
|
25
25
|
|
@@ -34,9 +34,6 @@ Dummy::Application.configure do
|
|
34
34
|
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
35
|
# config.action_controller.asset_host = "http://assets.example.com"
|
36
36
|
|
37
|
-
# Disable delivery errors, bad email addresses will be ignored
|
38
|
-
# config.action_mailer.raise_delivery_errors = false
|
39
|
-
|
40
37
|
# Enable threaded mode
|
41
38
|
# config.threadsafe!
|
42
39
|
|
@@ -46,4 +43,7 @@ Dummy::Application.configure do
|
|
46
43
|
|
47
44
|
# Send deprecation notices to registered listeners
|
48
45
|
config.active_support.deprecation = :notify
|
46
|
+
|
47
|
+
# Eager load code on boot (Rails 5)
|
48
|
+
config.eager_load = true
|
49
49
|
end
|
@@ -20,11 +20,6 @@ Dummy::Application.configure do
|
|
20
20
|
# Disable request forgery protection in test environment
|
21
21
|
config.action_controller.allow_forgery_protection = false
|
22
22
|
|
23
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
-
# The :test delivery method accumulates sent emails in the
|
25
|
-
# ActionMailer::Base.deliveries array.
|
26
|
-
config.action_mailer.delivery_method = :test
|
27
|
-
|
28
23
|
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
24
|
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
25
|
# like if you have constraints or database-specific column types
|
@@ -32,4 +27,7 @@ Dummy::Application.configure do
|
|
32
27
|
|
33
28
|
# Print deprecation notices to the stderr
|
34
29
|
config.active_support.deprecation = :stderr
|
30
|
+
|
31
|
+
# Do not eager load code on boot. (Rails 5)
|
32
|
+
config.eager_load = false
|
35
33
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
Apipie.configure do |config|
|
2
2
|
config.app_name = "Test app"
|
3
3
|
config.copyright = "© 2012 Pavel Pokorny"
|
4
|
+
config.languages = ['en']
|
5
|
+
config.default_locale = 'en'
|
4
6
|
|
5
7
|
# set default API version
|
6
8
|
# can be overriden in resource_description
|
7
9
|
# by default is it 1.0 if not specified anywhere
|
8
10
|
# this must be defined before api_base_url and app_info
|
9
|
-
config.default_version = "development"
|
11
|
+
config.default_version = "development".freeze
|
10
12
|
|
11
13
|
config.doc_base_url = "/apidoc"
|
12
14
|
|
@@ -21,7 +23,7 @@ Apipie.configure do |config|
|
|
21
23
|
# rake apipie:cache
|
22
24
|
#
|
23
25
|
config.use_cache = Rails.env.production?
|
24
|
-
|
26
|
+
config.cache_dir = File.join(Rails.root, "tmp", "apipie-cache") # optional
|
25
27
|
|
26
28
|
# set to enable/disable reloading controllers (and the documentation with it),
|
27
29
|
# by default enabled in development
|
@@ -87,7 +89,7 @@ class Apipie::Validator::IntegerValidator < Apipie::Validator::BaseValidator
|
|
87
89
|
end
|
88
90
|
|
89
91
|
def self.build(param_description, argument, options, block)
|
90
|
-
if argument == Integer
|
92
|
+
if argument == Integer
|
91
93
|
self.new(param_description, argument)
|
92
94
|
end
|
93
95
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -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
|
@@ -9,9 +11,15 @@ Dummy::Application.routes.draw do
|
|
9
11
|
end
|
10
12
|
end
|
11
13
|
resources :concerns, :only => [:index, :show]
|
14
|
+
get '/:resource_id/:custom_subst' => 'concerns#custom'
|
12
15
|
namespace :files do
|
13
|
-
get '/*file_path',
|
16
|
+
get '/*file_path', format: false, :action => 'download'
|
14
17
|
end
|
18
|
+
|
19
|
+
# This is not directly used in the specs.
|
20
|
+
# It is only there to tests apipies tolerance regarding
|
21
|
+
# missing controllers.
|
22
|
+
resources :dangeling_stuff
|
15
23
|
resources :twitter_example do
|
16
24
|
collection do
|
17
25
|
get :lookup
|
@@ -21,6 +29,22 @@ Dummy::Application.routes.draw do
|
|
21
29
|
get :contributors
|
22
30
|
end
|
23
31
|
end
|
32
|
+
|
33
|
+
get "/pets/return_and_validate_expected_response" => "pets#return_and_validate_expected_response"
|
34
|
+
get "/pets/return_and_validate_expected_array_response" => "pets#return_and_validate_expected_array_response"
|
35
|
+
get "/pets/return_and_validate_type_mismatch" => "pets#return_and_validate_type_mismatch"
|
36
|
+
get "/pets/return_and_validate_missing_field" => "pets#return_and_validate_missing_field"
|
37
|
+
get "/pets/return_and_validate_extra_property" => "pets#return_and_validate_extra_property"
|
38
|
+
get "/pets/return_and_validate_allowed_extra_property" => "pets#return_and_validate_allowed_extra_property"
|
39
|
+
get "/pets/sub_object_invalid_extra_property" => "pets#sub_object_invalid_extra_property"
|
40
|
+
get "/pets/sub_object_allowed_extra_property" => "pets#sub_object_allowed_extra_property"
|
41
|
+
get "/pets/return_and_validate_unexpected_array_response" => "pets#return_and_validate_unexpected_array_response"
|
42
|
+
get "/pets/return_and_validate_expected_response_with_null" => "pets#return_and_validate_expected_response_with_null"
|
43
|
+
get "/pets/return_and_validate_expected_response_with_null_object" => "pets#return_and_validate_expected_response_with_null_object"
|
44
|
+
|
45
|
+
get "/pets/returns_response_with_valid_array" => "pets#returns_response_with_valid_array"
|
46
|
+
get "/pets/returns_response_with_invalid_array" => "pets#returns_response_with_invalid_array"
|
47
|
+
get "/pets/undocumented_method" => "pets#undocumented_method"
|
24
48
|
end
|
25
49
|
|
26
50
|
apipie
|
data/spec/dummy/config.ru
CHANGED
data/spec/dummy/script/rails
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
3
|
|
4
|
-
APP_PATH = File.expand_path('
|
5
|
-
require File.expand_path('
|
4
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
5
|
+
require File.expand_path('../config/boot', __dir__)
|
6
6
|
require 'rails/commands'
|
@@ -27,7 +27,7 @@ describe Apipie::Application do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
context "with an undefined base url" do
|
30
|
-
before {allow(Apipie.app).to receive(:get_base_url)
|
30
|
+
before {allow(Apipie.app).to receive(:get_base_url).and_return(nil)}
|
31
31
|
|
32
32
|
it "should not raise an error" do
|
33
33
|
expect { Apipie.get_resource_name(Api::V2::ArchitecturesController) }.
|
@@ -6,7 +6,8 @@ describe Apipie::Extractor::Writer do
|
|
6
6
|
let(:writer_class) { Apipie::Extractor::Writer }
|
7
7
|
let(:writer) { writer_class.new(collector) }
|
8
8
|
let(:test_examples_file) { File.join(Rails.root, "doc", "apipie_examples_test.json") }
|
9
|
-
let(:records) {
|
9
|
+
let(:records) {
|
10
|
+
{
|
10
11
|
"concern_resources#show" =>
|
11
12
|
[{
|
12
13
|
:controller=>ConcernsController,
|
@@ -31,7 +32,8 @@ describe Apipie::Extractor::Writer do
|
|
31
32
|
}]
|
32
33
|
}
|
33
34
|
}
|
34
|
-
let(:loaded_records) {
|
35
|
+
let(:loaded_records) {
|
36
|
+
{
|
35
37
|
"concern_resources#show" =>
|
36
38
|
[{
|
37
39
|
"verb"=>:GET,
|
@@ -57,10 +59,38 @@ describe Apipie::Extractor::Writer do
|
|
57
59
|
}
|
58
60
|
}
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
Apipie.configuration.doc_path
|
63
|
-
|
62
|
+
context 'with doc_path overridden in configuration' do
|
63
|
+
around(:each) do |example|
|
64
|
+
standard_path = Apipie.configuration.doc_path
|
65
|
+
Apipie.configuration.doc_path = 'tmp/user_specified_doc_path'
|
66
|
+
example.run
|
67
|
+
Apipie.configuration.doc_path = standard_path
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should use the doc_path specified in configuration' do
|
71
|
+
expect(writer_class.examples_file).to eql(File.join(Rails.root, 'tmp', 'user_specified_doc_path', 'apipie_examples.json'))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when compressing examples' do
|
76
|
+
around(:each) do |example|
|
77
|
+
Apipie.configuration.compress_examples = true
|
78
|
+
example.run
|
79
|
+
FileUtils.rm(writer_class.examples_file) if File.exist?(writer_class.examples_file)
|
80
|
+
Apipie.configuration.compress_examples = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should write to a compressed file' do
|
84
|
+
expect(writer_class.examples_file).to match(/\.gz$/)
|
85
|
+
writer_class.write_recorded_examples(records)
|
86
|
+
expect(File.exist?(writer_class.examples_file))
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should read from a compressed file' do
|
90
|
+
writer_class.write_recorded_examples(records)
|
91
|
+
expected_string = writer_class.send(:serialize_examples, records)
|
92
|
+
expect(writer_class.load_recorded_examples)
|
93
|
+
.to eql(writer_class.send(:deserialize_examples, expected_string))
|
64
94
|
end
|
65
95
|
end
|
66
96
|
|
@@ -76,7 +106,7 @@ describe Apipie::Extractor::Writer do
|
|
76
106
|
end
|
77
107
|
|
78
108
|
after do
|
79
|
-
File.unlink(test_examples_file) if File.
|
109
|
+
File.unlink(test_examples_file) if File.exist?(test_examples_file)
|
80
110
|
end
|
81
111
|
end
|
82
112
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::FileHandler do
|
4
|
+
|
5
|
+
describe "match?" do
|
6
|
+
let(:file_handler) { Apipie::FileHandler.new File.dirname(__FILE__) }
|
7
|
+
|
8
|
+
it { expect(file_handler.match? 'file_handler_spec.rb').to be_truthy }
|
9
|
+
it { expect(file_handler.match? 'foo.bar').to be_falsy }
|
10
|
+
|
11
|
+
context 'path contains null bytes' do
|
12
|
+
let(:path) { "foo%00.bar" }
|
13
|
+
|
14
|
+
it { expect(file_handler.match? path).to be_falsy }
|
15
|
+
it { expect { file_handler.match? path }.to_not raise_error }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when the path contans an invalid byte sequence in UTF-8' do
|
19
|
+
let(:path) { "%B6" }
|
20
|
+
|
21
|
+
it { expect(file_handler.match? path).to be_falsy }
|
22
|
+
it { expect { file_handler.match? path }.to_not raise_error }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apipie::Generator::Swagger::TypeExtractor do
|
4
|
+
let(:validator) {}
|
5
|
+
let(:extractor) { described_class.new(validator) }
|
6
|
+
|
7
|
+
describe '#extarct_with_warnings' do
|
8
|
+
let(:warnings) { {} }
|
9
|
+
|
10
|
+
before { Apipie.configuration.swagger_suppress_warnings = false }
|
11
|
+
|
12
|
+
subject { extractor.extract_with_warnings(warnings) }
|
13
|
+
|
14
|
+
it { is_expected.to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:string]) }
|
15
|
+
|
16
|
+
context "when enum validator is used" do
|
17
|
+
let(:enum_values) { ["Name"] }
|
18
|
+
|
19
|
+
context "of type Apipie::Validator::EnumValidator" do
|
20
|
+
let(:validator) { Apipie::Validator::EnumValidator.new(nil, enum_values) }
|
21
|
+
|
22
|
+
it { is_expected.to eq("enum") }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "that responds to is_enum?" do
|
26
|
+
let(:validator) do
|
27
|
+
Apipie::ResponseDescriptionAdapter::PropDesc::Validator.new('some-type', enum_values)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns an enum type' do
|
31
|
+
expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:enum])
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'and has `true`, `false` as values' do
|
35
|
+
let(:param_description_name) { :visible }
|
36
|
+
let(:enum_values) { [true, false] }
|
37
|
+
|
38
|
+
it 'returns a boolean type' do
|
39
|
+
expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:boolean])
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'and a boolean warning is passed' do
|
43
|
+
let(:boolean_warning) do
|
44
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
45
|
+
Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
|
46
|
+
'SampleController#action',
|
47
|
+
{ parameter: 'some-param' }
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:warnings) { { boolean: boolean_warning } }
|
52
|
+
|
53
|
+
it 'outputs the warning' do
|
54
|
+
expect { subject }.to output(boolean_warning.warning_message).to_stderr
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::Generator::Swagger::Warning do
|
4
|
+
let(:code) { Apipie::Generator::Swagger::Warning::MISSING_METHOD_SUMMARY_CODE }
|
5
|
+
let(:method_id) { 'Examples#index' }
|
6
|
+
let(:info_message) { 'Something went wrong' }
|
7
|
+
|
8
|
+
let(:warning) { described_class.new(code, info_message, method_id) }
|
9
|
+
|
10
|
+
describe '#id' do
|
11
|
+
subject { warning.id }
|
12
|
+
|
13
|
+
it { is_expected.to eq("#{method_id}#{code}#{info_message}") }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#warning_message' do
|
17
|
+
subject { warning.warning_message }
|
18
|
+
|
19
|
+
it { is_expected.to eq("WARNING (#{code}): [#{method_id}] -- #{info_message}") }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#warn' do
|
23
|
+
subject { warning.warn }
|
24
|
+
|
25
|
+
it 'outputs the warning' do
|
26
|
+
expect { subject }.to output(warning.warning_message).to_stderr
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#warn_through_writer' do
|
31
|
+
subject { warning.warn }
|
32
|
+
|
33
|
+
it 'outputs the warning' do
|
34
|
+
expect { subject }.to output(warning.warning_message).to_stderr
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.for_code' do
|
39
|
+
subject { described_class.for_code(code, method_id) }
|
40
|
+
|
41
|
+
it { is_expected.to be_an_instance_of(described_class)}
|
42
|
+
|
43
|
+
context 'when code is invalid' do
|
44
|
+
let(:code) { 12345 }
|
45
|
+
|
46
|
+
it 'raises an argument error' do
|
47
|
+
expect { subject }.to raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|