apipie-rails 0.5.19 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +31 -0
- data/.github/workflows/rubocop-challenger.yml +28 -0
- data/.github/workflows/rubocop.yml +18 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +128 -0
- data/.rubocop_todo.yml +2056 -0
- data/.vscode/settings.json +3 -0
- data/CHANGELOG.md +161 -0
- data/Gemfile +20 -0
- data/README.rst +117 -23
- data/Rakefile +0 -5
- data/apipie-rails.gemspec +18 -9
- data/app/controllers/apipie/apipies_controller.rb +14 -29
- data/app/helpers/apipie_helper.rb +1 -1
- 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/_deprecation.html.erb +16 -0
- data/app/views/apipie/apipies/_params.html.erb +7 -1
- data/config/locales/en.yml +8 -0
- data/config/locales/ko.yml +31 -0
- data/gemfiles/Gemfile.tools +9 -0
- data/lib/apipie/apipie_module.rb +7 -7
- data/lib/apipie/application.rb +132 -97
- data/lib/apipie/configuration.rb +43 -33
- data/lib/apipie/dsl_definition.rb +44 -33
- data/lib/apipie/error_description.rb +3 -3
- data/lib/apipie/errors.rb +17 -17
- data/lib/apipie/extractor/collector.rb +5 -6
- data/lib/apipie/extractor/recorder.rb +35 -8
- data/lib/apipie/extractor/writer.rb +15 -15
- data/lib/apipie/extractor.rb +6 -9
- data/lib/apipie/generator/config.rb +12 -0
- data/lib/apipie/generator/generator.rb +2 -0
- data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
- data/lib/apipie/generator/swagger/config.rb +80 -0
- data/lib/apipie/generator/swagger/context.rb +38 -0
- data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
- data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +89 -0
- data/lib/apipie/generator/swagger/method_description/decorator.rb +22 -0
- data/lib/apipie/generator/swagger/method_description/parameters_service.rb +139 -0
- data/lib/apipie/generator/swagger/method_description/response_schema_service.rb +46 -0
- data/lib/apipie/generator/swagger/method_description/response_service.rb +58 -0
- data/lib/apipie/generator/swagger/method_description.rb +2 -0
- data/lib/apipie/generator/swagger/operation_id.rb +51 -0
- data/lib/apipie/generator/swagger/param_description/builder.rb +114 -0
- data/lib/apipie/generator/swagger/param_description/composite.rb +119 -0
- data/lib/apipie/generator/swagger/param_description/description.rb +15 -0
- data/lib/apipie/generator/swagger/param_description/in.rb +37 -0
- data/lib/apipie/generator/swagger/param_description/name.rb +18 -0
- data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +61 -0
- data/lib/apipie/generator/swagger/param_description/referenced_composite.rb +36 -0
- data/lib/apipie/generator/swagger/param_description/type.rb +128 -0
- data/lib/apipie/generator/swagger/param_description.rb +18 -0
- data/lib/apipie/generator/swagger/path_decorator.rb +36 -0
- data/lib/apipie/generator/swagger/referenced_definitions.rb +17 -0
- data/lib/apipie/generator/swagger/resource_description_collection.rb +30 -0
- data/lib/apipie/generator/swagger/resource_description_composite.rb +56 -0
- data/lib/apipie/generator/swagger/schema.rb +63 -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 +51 -0
- data/lib/apipie/generator/swagger/warning.rb +74 -0
- data/lib/apipie/generator/swagger/warning_writer.rb +54 -0
- data/lib/apipie/helpers.rb +3 -3
- data/lib/apipie/markup.rb +9 -8
- 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 +12 -56
- data/lib/apipie/param_description/deprecation.rb +24 -0
- data/lib/apipie/param_description.rb +57 -24
- data/lib/apipie/resource_description.rb +42 -14
- data/lib/apipie/response_description.rb +3 -3
- data/lib/apipie/response_description_adapter.rb +12 -10
- data/lib/apipie/routing.rb +1 -1
- data/lib/apipie/rspec/response_validation_helper.rb +3 -3
- data/lib/apipie/static_dispatcher.rb +10 -2
- data/lib/apipie/swagger_generator.rb +28 -691
- data/lib/apipie/validator.rb +41 -11
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +36 -5
- data/lib/generators/apipie/install/install_generator.rb +1 -1
- data/lib/generators/apipie/views_generator.rb +1 -1
- data/lib/tasks/apipie.rake +37 -32
- data/rel-eng/gem_release.ipynb +41 -9
- data/spec/controllers/api/v2/architectures_controller_spec.rb +10 -3
- data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +18 -2
- data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
- data/spec/controllers/included_param_group_controller_spec.rb +13 -0
- data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +26 -32
- data/spec/controllers/users_controller_spec.rb +47 -6
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +2 -1
- data/spec/dummy/app/controllers/api/v2/base_controller.rb +6 -0
- data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
- data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +2 -2
- data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
- data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
- data/spec/dummy/app/controllers/{concerns/extending_concern.rb → extending_concern.rb} +0 -2
- 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 +5 -5
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
- data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +0 -2
- data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
- data/spec/dummy/app/controllers/users_controller.rb +17 -5
- data/spec/dummy/app/helpers/random_param_group.rb +8 -0
- data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
- data/spec/dummy/config/application.rb +2 -5
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +0 -3
- data/spec/dummy/config/environments/production.rb +0 -3
- data/spec/dummy/config/environments/test.rb +0 -5
- data/spec/dummy/config/initializers/apipie.rb +2 -2
- data/spec/dummy/config/routes.rb +8 -0
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/script/rails +2 -2
- data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +95 -23
- data/spec/lib/apipie/application_spec.rb +62 -0
- data/spec/lib/apipie/configuration_spec.rb +38 -0
- data/spec/lib/apipie/extractor/collector_spec.rb +57 -0
- data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
- data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +8 -6
- data/spec/lib/{extractor → apipie}/extractor_spec.rb +1 -1
- data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +7 -0
- data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
- data/spec/lib/apipie/generator/swagger/context_spec.rb +56 -0
- data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +119 -0
- data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
- data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +215 -0
- data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +95 -0
- data/spec/lib/apipie/generator/swagger/param_description/description_spec.rb +79 -0
- data/spec/lib/apipie/generator/swagger/param_description/in_spec.rb +86 -0
- data/spec/lib/apipie/generator/swagger/param_description/name_spec.rb +81 -0
- data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +183 -0
- data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
- data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
- data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
- data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
- data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
- data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
- data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +38 -0
- data/spec/lib/apipie/generator/swagger/warning_spec.rb +51 -0
- data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +71 -0
- data/spec/lib/apipie/method_description/apis_service_spec.rb +60 -0
- data/spec/lib/apipie/method_description_spec.rb +133 -0
- data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
- data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
- data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +332 -6
- data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +6 -5
- data/spec/lib/apipie/resource_description_spec.rb +91 -0
- data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
- data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
- data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +48 -12
- data/spec/lib/rake_spec.rb +3 -5
- data/spec/lib/swagger/openapi_2_0_schema.json +8 -1
- data/spec/lib/swagger/rake_swagger_spec.rb +30 -10
- data/spec/lib/swagger/swagger_dsl_spec.rb +18 -12
- data/spec/lib/validators/array_validator_spec.rb +1 -1
- data/spec/spec_helper.rb +10 -32
- data/spec/support/custom_bool_validator.rb +17 -0
- data/spec/{controllers → test_engine}/memes_controller_spec.rb +1 -1
- metadata +173 -125
- data/.travis.yml +0 -41
- data/Gemfile +0 -1
- data/Gemfile.rails41 +0 -7
- data/Gemfile.rails42 +0 -14
- data/Gemfile.rails50 +0 -9
- data/Gemfile.rails51 +0 -9
- data/Gemfile.rails60 +0 -10
- data/Gemfile.rails61 +0 -10
- data/spec/lib/application_spec.rb +0 -49
- data/spec/lib/method_description_spec.rb +0 -98
- data/spec/lib/resource_description_spec.rb +0 -48
- /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
@@ -34,17 +34,17 @@ module Apipie
|
|
34
34
|
|
35
35
|
@language = get_language
|
36
36
|
|
37
|
-
Apipie.load_documentation if Apipie.configuration.reload_controllers? ||
|
37
|
+
Apipie.load_documentation if Apipie.configuration.reload_controllers? || !Rails.application.config.eager_load
|
38
38
|
|
39
39
|
I18n.locale = @language
|
40
40
|
|
41
41
|
if should_render_swagger
|
42
|
-
prev_warning_value = Apipie.configuration.
|
42
|
+
prev_warning_value = Apipie.configuration.generator.swagger.suppress_warnings
|
43
43
|
begin
|
44
|
-
Apipie.configuration.
|
44
|
+
Apipie.configuration.generator.swagger.suppress_warnings = true
|
45
45
|
@doc = Apipie.to_swagger_json(params[:version], params[:resource], params[:method], @language)
|
46
46
|
ensure
|
47
|
-
Apipie.configuration.
|
47
|
+
Apipie.configuration.generator.swagger.suppress_warnings = prev_warning_value
|
48
48
|
end
|
49
49
|
else
|
50
50
|
@doc = Apipie.to_json(params[:version], params[:resource], params[:method], @language)
|
@@ -98,12 +98,11 @@ module Apipie
|
|
98
98
|
return nil unless Apipie.configuration.translate
|
99
99
|
lang = Apipie.configuration.default_locale
|
100
100
|
[:resource, :method, :version].each do |par|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
101
|
+
next unless params[par]
|
102
|
+
splitted = params[par].split('.')
|
103
|
+
if splitted.length > 1 && (Apipie.configuration.languages.include?(splitted.last) || Apipie.configuration.default_locale == splitted.last)
|
104
|
+
lang = splitted.last
|
105
|
+
params[par].sub!(".#{lang}", '')
|
107
106
|
end
|
108
107
|
end
|
109
108
|
lang
|
@@ -120,7 +119,7 @@ module Apipie
|
|
120
119
|
authorize_resource(resource)
|
121
120
|
end
|
122
121
|
else
|
123
|
-
@doc[:docs][:resources].select do |
|
122
|
+
@doc[:docs][:resources].select do |_resource_id, resource|
|
124
123
|
authorize_resource(resource)
|
125
124
|
end
|
126
125
|
end
|
@@ -155,29 +154,15 @@ module Apipie
|
|
155
154
|
|
156
155
|
def render_from_cache
|
157
156
|
path = Apipie.configuration.doc_base_url.dup
|
158
|
-
# some params can contain dot, but only one in row
|
159
|
-
if [:resource, :method, :format, :version].any? { |p| params[p].to_s.gsub(".", "") =~ /\W/ || params[p].to_s =~ /\.\./ }
|
160
|
-
head :bad_request and return
|
161
|
-
end
|
162
|
-
|
163
157
|
path << "/" << params[:version] if params[:version].present?
|
164
158
|
path << "/" << params[:resource] if params[:resource].present?
|
165
159
|
path << "/" << params[:method] if params[:method].present?
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
path << ".html"
|
170
|
-
end
|
171
|
-
|
172
|
-
# we sanitize the params before so in ideal case, this condition
|
173
|
-
# will be never satisfied. It's here for cases somebody adds new
|
174
|
-
# param into the path later and forgets about sanitation.
|
175
|
-
if path =~ /\.\./
|
176
|
-
head :bad_request and return
|
177
|
-
end
|
160
|
+
# Sanitize path against directory traversal attacks (e.g. ../../foo)
|
161
|
+
# by turning path into an absolute path before appending it to the cache dir
|
162
|
+
path = File.expand_path("#{path}.#{request.format.symbol}", '/')
|
178
163
|
|
179
164
|
cache_file = File.join(Apipie.configuration.cache_dir, path)
|
180
|
-
if File.
|
165
|
+
if File.exist?(cache_file)
|
181
166
|
content_type = case params[:format]
|
182
167
|
when "json" then "application/json"
|
183
168
|
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);
|