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
data/Rakefile
CHANGED
data/apipie-rails.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path(
|
2
|
+
$:.push File.expand_path('lib', __dir__)
|
3
3
|
require "apipie/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
@@ -10,19 +10,24 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "http://github.com/Apipie/apipie-rails"
|
11
11
|
s.summary = %q{Rails REST API documentation tool}
|
12
12
|
s.description = %q{Rails REST API documentation tool}
|
13
|
-
|
13
|
+
s.required_ruby_version = '>= 2.6.0'
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.
|
20
|
-
s.add_dependency
|
19
|
+
s.add_dependency "actionpack", ">= 5.0"
|
20
|
+
s.add_dependency "activesupport", ">= 5.0"
|
21
|
+
|
22
|
+
# Optional dependencies
|
23
|
+
s.add_development_dependency "maruku" # for Markdown support
|
24
|
+
s.add_development_dependency "RedCloth" # for Textile support
|
25
|
+
|
26
|
+
# Dev/tests only dependencies
|
27
|
+
s.add_development_dependency "json-schema", "~> 2.8"
|
21
28
|
s.add_development_dependency "rspec-rails", "~> 3.0"
|
22
|
-
s.add_development_dependency "sqlite3"
|
23
|
-
s.add_development_dependency "minitest"
|
24
|
-
s.add_development_dependency "maruku"
|
25
|
-
s.add_development_dependency "RedCloth"
|
26
29
|
s.add_development_dependency "rake"
|
27
|
-
s.add_development_dependency
|
30
|
+
s.add_development_dependency 'rubocop_challenger'
|
31
|
+
s.add_development_dependency "simplecov"
|
32
|
+
s.add_development_dependency "sqlite3"
|
28
33
|
end
|
@@ -5,8 +5,8 @@ module Apipie
|
|
5
5
|
|
6
6
|
layout Apipie.configuration.layout
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
around_action :set_script_name
|
9
|
+
before_action :authenticate
|
10
10
|
|
11
11
|
def authenticate
|
12
12
|
if Apipie.configuration.authenticate
|
@@ -14,11 +14,17 @@ module Apipie
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
|
17
18
|
def index
|
18
19
|
params[:version] ||= Apipie.configuration.default_version
|
19
20
|
|
20
21
|
get_format
|
21
22
|
|
23
|
+
if params[:type].to_s == 'swagger' && params[:format].to_s == 'json'
|
24
|
+
head :forbidden and return if Apipie.configuration.authorize
|
25
|
+
should_render_swagger = true
|
26
|
+
end
|
27
|
+
|
22
28
|
respond_to do |format|
|
23
29
|
|
24
30
|
if Apipie.configuration.use_cache?
|
@@ -28,12 +34,22 @@ module Apipie
|
|
28
34
|
|
29
35
|
@language = get_language
|
30
36
|
|
31
|
-
Apipie.load_documentation if Apipie.configuration.reload_controllers? ||
|
37
|
+
Apipie.load_documentation if Apipie.configuration.reload_controllers? || !Rails.application.config.eager_load
|
32
38
|
|
33
39
|
I18n.locale = @language
|
34
|
-
@doc = Apipie.to_json(params[:version], params[:resource], params[:method], @language)
|
35
40
|
|
36
|
-
|
41
|
+
if should_render_swagger
|
42
|
+
prev_warning_value = Apipie.configuration.swagger_suppress_warnings
|
43
|
+
begin
|
44
|
+
Apipie.configuration.swagger_suppress_warnings = true
|
45
|
+
@doc = Apipie.to_swagger_json(params[:version], params[:resource], params[:method], @language)
|
46
|
+
ensure
|
47
|
+
Apipie.configuration.swagger_suppress_warnings = prev_warning_value
|
48
|
+
end
|
49
|
+
else
|
50
|
+
@doc = Apipie.to_json(params[:version], params[:resource], params[:method], @language)
|
51
|
+
@doc = authorized_doc
|
52
|
+
end
|
37
53
|
|
38
54
|
format.json do
|
39
55
|
if @doc
|
@@ -79,11 +95,12 @@ module Apipie
|
|
79
95
|
helper_method :heading
|
80
96
|
|
81
97
|
def get_language
|
82
|
-
|
98
|
+
return nil unless Apipie.configuration.translate
|
99
|
+
lang = Apipie.configuration.default_locale
|
83
100
|
[:resource, :method, :version].each do |par|
|
84
101
|
if params[par]
|
85
102
|
splitted = params[par].split('.')
|
86
|
-
if splitted.length > 1 && Apipie.configuration.languages.include?(splitted.last)
|
103
|
+
if splitted.length > 1 && (Apipie.configuration.languages.include?(splitted.last) || Apipie.configuration.default_locale == splitted.last)
|
87
104
|
lang = splitted.last
|
88
105
|
params[par].sub!(".#{lang}", '')
|
89
106
|
end
|
@@ -93,30 +110,44 @@ module Apipie
|
|
93
110
|
end
|
94
111
|
|
95
112
|
def authorized_doc
|
96
|
-
|
113
|
+
return if @doc.nil?
|
97
114
|
return @doc unless Apipie.configuration.authorize
|
98
115
|
|
99
116
|
new_doc = { :docs => @doc[:docs].clone }
|
100
117
|
|
101
|
-
new_doc[:docs][:resources] = @doc[:docs][:resources].
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
false
|
118
|
+
new_doc[:docs][:resources] = if @doc[:docs][:resources].kind_of?(Array)
|
119
|
+
@doc[:docs][:resources].select do |resource|
|
120
|
+
authorize_resource(resource)
|
121
|
+
end
|
122
|
+
else
|
123
|
+
@doc[:docs][:resources].select do |_resource_name, resource|
|
124
|
+
authorize_resource(resource)
|
109
125
|
end
|
110
126
|
end
|
111
127
|
|
112
128
|
new_doc
|
113
129
|
end
|
114
130
|
|
131
|
+
def authorize_resource resource
|
132
|
+
if instance_exec(resource[:id], nil, resource, &Apipie.configuration.authorize)
|
133
|
+
resource[:methods] = resource[:methods].select do |m|
|
134
|
+
instance_exec(resource[:id], m[:name], m, &Apipie.configuration.authorize)
|
135
|
+
end
|
136
|
+
true
|
137
|
+
else
|
138
|
+
false
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
115
142
|
def get_format
|
116
143
|
[:resource, :method, :version].each do |par|
|
117
|
-
|
118
|
-
|
119
|
-
|
144
|
+
next unless params[par]
|
145
|
+
[:html, :json].each do |format|
|
146
|
+
extension = ".#{format}"
|
147
|
+
if params[par].include?(extension)
|
148
|
+
params[par] = params[par].sub(extension, '')
|
149
|
+
params[:format] = format
|
150
|
+
end
|
120
151
|
end
|
121
152
|
end
|
122
153
|
request.format = params[:format] if params[:format]
|
@@ -146,7 +177,7 @@ module Apipie
|
|
146
177
|
end
|
147
178
|
|
148
179
|
cache_file = File.join(Apipie.configuration.cache_dir, path)
|
149
|
-
if File.
|
180
|
+
if File.exist?(cache_file)
|
150
181
|
content_type = case params[:format]
|
151
182
|
when "json" then "application/json"
|
152
183
|
else "text/html"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
/* =============================================================
|
2
|
-
* bootstrap-collapse.js v2.
|
3
|
-
* http://
|
2
|
+
* bootstrap-collapse.js v2.3.2
|
3
|
+
* http://getbootstrap.com/2.3.2/javascript.html#collapse
|
4
4
|
* =============================================================
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2013 Twitter, Inc.
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -17,16 +17,21 @@
|
|
17
17
|
* limitations under the License.
|
18
18
|
* ============================================================ */
|
19
19
|
|
20
|
-
!function( $ ){
|
21
20
|
|
22
|
-
|
21
|
+
!function ($) {
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
"use strict"; // jshint ;_;
|
24
|
+
|
25
|
+
|
26
|
+
/* COLLAPSE PUBLIC CLASS DEFINITION
|
27
|
+
* ================================ */
|
28
|
+
|
29
|
+
var Collapse = function (element, options) {
|
30
|
+
this.$element = $(element)
|
26
31
|
this.options = $.extend({}, $.fn.collapse.defaults, options)
|
27
32
|
|
28
|
-
if (this.options
|
29
|
-
this.$parent = $(this.options
|
33
|
+
if (this.options.parent) {
|
34
|
+
this.$parent = $(this.options.parent)
|
30
35
|
}
|
31
36
|
|
32
37
|
this.options.toggle && this.toggle()
|
@@ -42,31 +47,39 @@
|
|
42
47
|
}
|
43
48
|
|
44
49
|
, show: function () {
|
45
|
-
var dimension
|
46
|
-
, scroll
|
47
|
-
, actives
|
50
|
+
var dimension
|
51
|
+
, scroll
|
52
|
+
, actives
|
48
53
|
, hasData
|
49
54
|
|
55
|
+
if (this.transitioning || this.$element.hasClass('in')) return
|
56
|
+
|
57
|
+
dimension = this.dimension()
|
58
|
+
scroll = $.camelCase(['scroll', dimension].join('-'))
|
59
|
+
actives = this.$parent && this.$parent.find('> .accordion-group > .in')
|
60
|
+
|
50
61
|
if (actives && actives.length) {
|
51
62
|
hasData = actives.data('collapse')
|
63
|
+
if (hasData && hasData.transitioning) return
|
52
64
|
actives.collapse('hide')
|
53
65
|
hasData || actives.data('collapse', null)
|
54
66
|
}
|
55
67
|
|
56
68
|
this.$element[dimension](0)
|
57
|
-
this.transition('addClass', 'show', 'shown')
|
58
|
-
this.$element[dimension](this.$element[0][scroll])
|
59
|
-
|
69
|
+
this.transition('addClass', $.Event('show'), 'shown')
|
70
|
+
$.support.transition && this.$element[dimension](this.$element[0][scroll])
|
60
71
|
}
|
61
72
|
|
62
73
|
, hide: function () {
|
63
|
-
var dimension
|
74
|
+
var dimension
|
75
|
+
if (this.transitioning || !this.$element.hasClass('in')) return
|
76
|
+
dimension = this.dimension()
|
64
77
|
this.reset(this.$element[dimension]())
|
65
|
-
this.transition('removeClass', 'hide', 'hidden')
|
78
|
+
this.transition('removeClass', $.Event('hide'), 'hidden')
|
66
79
|
this.$element[dimension](0)
|
67
80
|
}
|
68
81
|
|
69
|
-
, reset: function (
|
82
|
+
, reset: function (size) {
|
70
83
|
var dimension = this.dimension()
|
71
84
|
|
72
85
|
this.$element
|
@@ -74,41 +87,49 @@
|
|
74
87
|
[dimension](size || 'auto')
|
75
88
|
[0].offsetWidth
|
76
89
|
|
77
|
-
this.$element[size ? 'addClass' : 'removeClass']('collapse')
|
90
|
+
this.$element[size !== null ? 'addClass' : 'removeClass']('collapse')
|
78
91
|
|
79
92
|
return this
|
80
93
|
}
|
81
94
|
|
82
|
-
, transition: function (
|
95
|
+
, transition: function (method, startEvent, completeEvent) {
|
83
96
|
var that = this
|
84
97
|
, complete = function () {
|
85
|
-
if (startEvent == 'show') that.reset()
|
98
|
+
if (startEvent.type == 'show') that.reset()
|
99
|
+
that.transitioning = 0
|
86
100
|
that.$element.trigger(completeEvent)
|
87
101
|
}
|
88
102
|
|
89
|
-
this.$element
|
90
|
-
|
91
|
-
|
103
|
+
this.$element.trigger(startEvent)
|
104
|
+
|
105
|
+
if (startEvent.isDefaultPrevented()) return
|
106
|
+
|
107
|
+
this.transitioning = 1
|
108
|
+
|
109
|
+
this.$element[method]('in')
|
92
110
|
|
93
111
|
$.support.transition && this.$element.hasClass('collapse') ?
|
94
112
|
this.$element.one($.support.transition.end, complete) :
|
95
113
|
complete()
|
96
|
-
|
114
|
+
}
|
97
115
|
|
98
116
|
, toggle: function () {
|
99
117
|
this[this.$element.hasClass('in') ? 'hide' : 'show']()
|
100
|
-
|
118
|
+
}
|
101
119
|
|
102
120
|
}
|
103
121
|
|
104
|
-
/* COLLAPSIBLE PLUGIN DEFINITION
|
105
|
-
* ============================== */
|
106
122
|
|
107
|
-
|
123
|
+
/* COLLAPSE PLUGIN DEFINITION
|
124
|
+
* ========================== */
|
125
|
+
|
126
|
+
var old = $.fn.collapse
|
127
|
+
|
128
|
+
$.fn.collapse = function (option) {
|
108
129
|
return this.each(function () {
|
109
130
|
var $this = $(this)
|
110
131
|
, data = $this.data('collapse')
|
111
|
-
, options = typeof option == 'object' && option
|
132
|
+
, options = $.extend({}, $.fn.collapse.defaults, $this.data(), typeof option == 'object' && option)
|
112
133
|
if (!data) $this.data('collapse', (data = new Collapse(this, options)))
|
113
134
|
if (typeof option == 'string') data[option]()
|
114
135
|
})
|
@@ -121,18 +142,26 @@
|
|
121
142
|
$.fn.collapse.Constructor = Collapse
|
122
143
|
|
123
144
|
|
124
|
-
/*
|
145
|
+
/* COLLAPSE NO CONFLICT
|
125
146
|
* ==================== */
|
126
147
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
148
|
+
$.fn.collapse.noConflict = function () {
|
149
|
+
$.fn.collapse = old
|
150
|
+
return this
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
/* COLLAPSE DATA-API
|
155
|
+
* ================= */
|
156
|
+
|
157
|
+
$(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) {
|
158
|
+
var $this = $(this), href
|
159
|
+
, target = $this.attr('data-target')
|
160
|
+
|| e.preventDefault()
|
161
|
+
|| (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
|
162
|
+
, option = $(target).data('collapse') ? 'toggle' : $this.data()
|
163
|
+
$this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
|
164
|
+
$(target).collapse(option)
|
136
165
|
})
|
137
166
|
|
138
|
-
}(
|
167
|
+
}(window.jQuery);
|