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
@@ -12,9 +12,9 @@ module Apipie
|
|
12
12
|
attr_reader :additional_properties, :is_array
|
13
13
|
attr_accessor :parent, :required
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
alias response_only? response_only
|
16
|
+
alias request_only? request_only
|
17
|
+
alias is_array? is_array
|
18
18
|
|
19
19
|
def self.from_dsl_data(method_description, args)
|
20
20
|
param_name, validator, desc_or_options, options, block = args
|
@@ -57,6 +57,10 @@ module Apipie
|
|
57
57
|
@from_concern = @options[:param_group][:from_concern]
|
58
58
|
end
|
59
59
|
|
60
|
+
if validator.is_a?(Hash)
|
61
|
+
@options.merge!(validator.select{|k,v| k != :array_of })
|
62
|
+
end
|
63
|
+
|
60
64
|
@method_description = method_description
|
61
65
|
@name = concern_subst(name)
|
62
66
|
@as = options[:as] || @name
|
@@ -71,7 +75,7 @@ module Apipie
|
|
71
75
|
@request_only = (@options[:only_in] == :request)
|
72
76
|
raise ArgumentError.new("'#{@options[:only_in]}' is not a valid value for :only_in") if (!@response_only && !@request_only) && @options[:only_in].present?
|
73
77
|
|
74
|
-
@show = if @options.
|
78
|
+
@show = if @options.key? :show
|
75
79
|
@options[:show]
|
76
80
|
else
|
77
81
|
true
|
@@ -85,9 +89,7 @@ module Apipie
|
|
85
89
|
if validator
|
86
90
|
if (validator != Hash) && (validator.is_a? Hash) && (validator[:array_of])
|
87
91
|
@is_array = true
|
88
|
-
rest_of_options = validator
|
89
92
|
validator = validator[:array_of]
|
90
|
-
options.merge!(rest_of_options.select{|k,v| k != :array_of })
|
91
93
|
raise "an ':array_of =>' validator is allowed exclusively on response-only fields" unless @response_only
|
92
94
|
end
|
93
95
|
@validator = Validator::BaseValidator.find(self, validator, @options, block)
|
@@ -97,6 +99,7 @@ module Apipie
|
|
97
99
|
@validations = Array(options[:validations]).map {|v| concern_subst(Apipie.markup_to_html(v)) }
|
98
100
|
|
99
101
|
@additional_properties = @options[:additional_properties]
|
102
|
+
@deprecated = @options[:deprecated] || false
|
100
103
|
end
|
101
104
|
|
102
105
|
def from_concern?
|
@@ -114,16 +117,20 @@ module Apipie
|
|
114
117
|
end
|
115
118
|
|
116
119
|
def validate(value)
|
117
|
-
return true if
|
118
|
-
return true if
|
120
|
+
return true if allow_nil && value.nil?
|
121
|
+
return true if allow_blank && value.blank?
|
119
122
|
value = normalized_value(value)
|
120
|
-
if (
|
121
|
-
error =
|
123
|
+
if (!allow_nil && value.nil?) || (blank_forbidden? && value.blank?) || !validator.valid?(value)
|
124
|
+
error = validator.error
|
122
125
|
error = ParamError.new(error) unless error.is_a? StandardError
|
123
126
|
raise error
|
124
127
|
end
|
125
128
|
end
|
126
129
|
|
130
|
+
def blank_forbidden?
|
131
|
+
!Apipie.configuration.ignore_allow_blank_false && !allow_blank && !validator.ignore_allow_blank?
|
132
|
+
end
|
133
|
+
|
127
134
|
def process_value(value)
|
128
135
|
value = normalized_value(value)
|
129
136
|
if @validator.respond_to?(:process_value)
|
@@ -151,17 +158,25 @@ module Apipie
|
|
151
158
|
end
|
152
159
|
|
153
160
|
def to_json(lang = nil)
|
154
|
-
hash = {
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
161
|
+
hash = {
|
162
|
+
name: name.to_s,
|
163
|
+
full_name: full_name,
|
164
|
+
description: preformat_text(Apipie.app.translate(@options[:desc], lang)),
|
165
|
+
required: required,
|
166
|
+
allow_nil: allow_nil,
|
167
|
+
allow_blank: allow_blank,
|
168
|
+
validator: validator.to_s,
|
169
|
+
expected_type: validator.expected_type,
|
170
|
+
metadata: metadata,
|
171
|
+
show: show,
|
172
|
+
validations: validations,
|
173
|
+
deprecated: deprecated?
|
174
|
+
}
|
175
|
+
|
176
|
+
if deprecation.present?
|
177
|
+
hash[:deprecation] = deprecation.to_json
|
178
|
+
end
|
179
|
+
|
165
180
|
if sub_params = validator.params_ordered
|
166
181
|
hash[:params] = sub_params.map { |p| p.to_json(lang)}
|
167
182
|
end
|
@@ -208,7 +223,7 @@ module Apipie
|
|
208
223
|
# action awareness is being inherited from ancestors (in terms of
|
209
224
|
# nested params)
|
210
225
|
def action_aware?
|
211
|
-
if @options.
|
226
|
+
if @options.key?(:action_aware)
|
212
227
|
return @options[:action_aware]
|
213
228
|
elsif @parent
|
214
229
|
@parent.action_aware?
|
@@ -233,7 +248,7 @@ module Apipie
|
|
233
248
|
# crate/update actions.
|
234
249
|
def action_awareness
|
235
250
|
if action_aware?
|
236
|
-
if !@options.
|
251
|
+
if !@options.key?(:allow_nil)
|
237
252
|
if @required
|
238
253
|
@allow_nil = false
|
239
254
|
else
|
@@ -264,7 +279,7 @@ module Apipie
|
|
264
279
|
end
|
265
280
|
|
266
281
|
def is_required?
|
267
|
-
if @options.
|
282
|
+
if @options.key?(:required)
|
268
283
|
if (@options[:required] == true) || (@options[:required] == false)
|
269
284
|
@options[:required]
|
270
285
|
else
|
@@ -275,6 +290,24 @@ module Apipie
|
|
275
290
|
end
|
276
291
|
end
|
277
292
|
|
293
|
+
def deprecated?
|
294
|
+
@deprecated.present?
|
295
|
+
end
|
296
|
+
|
297
|
+
def deprecation
|
298
|
+
return if @deprecated.blank? || @deprecated == true
|
299
|
+
|
300
|
+
case @deprecated
|
301
|
+
when Hash
|
302
|
+
Apipie::ParamDescription::Deprecation.new(
|
303
|
+
info: @deprecated[:info],
|
304
|
+
deprecated_in: @deprecated[:in],
|
305
|
+
sunset_at: @deprecated[:sunset]
|
306
|
+
)
|
307
|
+
when String
|
308
|
+
Apipie::ParamDescription::Deprecation.new(info: @deprecated)
|
309
|
+
end
|
310
|
+
end
|
278
311
|
end
|
279
312
|
|
280
313
|
end
|
@@ -7,35 +7,35 @@ module Apipie
|
|
7
7
|
# path - relative path (/api/articles)
|
8
8
|
# methods - array of keys to Apipie.method_descriptions (array of Apipie::MethodDescription)
|
9
9
|
# name - human readable alias of resource (Articles)
|
10
|
-
# id -
|
10
|
+
# id - resource name
|
11
11
|
# formats - acceptable request/response format types
|
12
12
|
# headers - array of headers
|
13
13
|
# deprecated - boolean indicating if resource is deprecated
|
14
14
|
class ResourceDescription
|
15
15
|
|
16
16
|
attr_reader :controller, :_short_description, :_full_description, :_methods, :_id,
|
17
|
-
:_path, :
|
17
|
+
:_path, :_params_args, :_returns_args, :_tag_list_arg, :_errors_args,
|
18
18
|
:_formats, :_parent, :_metadata, :_headers, :_deprecated
|
19
19
|
|
20
|
-
def initialize(controller,
|
21
|
-
|
20
|
+
def initialize(controller, id, dsl_data = nil, version = nil)
|
22
21
|
@_methods = ActiveSupport::OrderedHash.new
|
23
22
|
@_params_args = []
|
24
23
|
@_errors_args = []
|
25
24
|
@_returns_args = []
|
26
25
|
|
27
26
|
@controller = controller
|
28
|
-
@_id =
|
27
|
+
@_id = id
|
29
28
|
@_version = version || Apipie.configuration.default_version
|
30
|
-
@
|
31
|
-
|
29
|
+
@_parent = Apipie.value_from_parents(controller.superclass, version) do |parent, ver|
|
30
|
+
Apipie.get_resource_description(parent, ver)
|
31
|
+
end
|
32
32
|
|
33
33
|
update_from_dsl_data(dsl_data) if dsl_data
|
34
34
|
end
|
35
35
|
|
36
36
|
def update_from_dsl_data(dsl_data)
|
37
|
-
@
|
38
|
-
@_full_description =
|
37
|
+
@_resource_name = dsl_data[:resource_name] if dsl_data[:resource_name]
|
38
|
+
@_full_description = dsl_data[:description]
|
39
39
|
@_short_description = dsl_data[:short_description]
|
40
40
|
@_path = dsl_data[:path] || ""
|
41
41
|
@_formats = dsl_data[:formats]
|
@@ -61,8 +61,22 @@ module Apipie
|
|
61
61
|
@_api_base_url || @_parent.try(:_api_base_url) || Apipie.api_base_url(_version)
|
62
62
|
end
|
63
63
|
|
64
|
+
def name
|
65
|
+
@name ||= case resource_name
|
66
|
+
when Proc
|
67
|
+
resource_name.call(controller)
|
68
|
+
when Symbol
|
69
|
+
controller.public_send(resource_name)
|
70
|
+
when String
|
71
|
+
resource_name
|
72
|
+
else
|
73
|
+
default_name
|
74
|
+
end
|
75
|
+
end
|
76
|
+
alias _name name
|
77
|
+
|
64
78
|
def add_method_description(method_description)
|
65
|
-
Apipie.debug "@resource_descriptions[#{self._version}][#{self.
|
79
|
+
Apipie.debug "@resource_descriptions[#{self._version}][#{self._id}]._methods[#{method_description.method}] = #{method_description}"
|
66
80
|
@_methods[method_description.method.to_sym] = method_description
|
67
81
|
end
|
68
82
|
|
@@ -71,7 +85,7 @@ module Apipie
|
|
71
85
|
end
|
72
86
|
|
73
87
|
def remove_method_description(method_name)
|
74
|
-
if @_methods.
|
88
|
+
if @_methods.key?(method_name)
|
75
89
|
@_methods.delete(method_name)
|
76
90
|
end
|
77
91
|
end
|
@@ -87,7 +101,9 @@ module Apipie
|
|
87
101
|
Apipie.full_url crumbs.join('/')
|
88
102
|
end
|
89
103
|
|
90
|
-
def api_url
|
104
|
+
def api_url
|
105
|
+
"#{Apipie.api_base_url(_version)}#{@_path}"
|
106
|
+
end
|
91
107
|
|
92
108
|
def valid_method_name?(method_name)
|
93
109
|
@_methods.keys.map(&:to_s).include?(method_name.to_s)
|
@@ -108,9 +124,9 @@ module Apipie
|
|
108
124
|
:doc_url => doc_url,
|
109
125
|
:id => _id,
|
110
126
|
:api_url => api_url,
|
111
|
-
:name =>
|
127
|
+
:name => name,
|
112
128
|
:short_description => Apipie.app.translate(@_short_description, lang),
|
113
|
-
:full_description => Apipie.app.translate(@_full_description, lang),
|
129
|
+
:full_description => Apipie.markup_to_html(Apipie.app.translate(@_full_description, lang)),
|
114
130
|
:version => _version,
|
115
131
|
:formats => @_formats,
|
116
132
|
:metadata => @_metadata,
|
@@ -120,5 +136,17 @@ module Apipie
|
|
120
136
|
}
|
121
137
|
end
|
122
138
|
|
139
|
+
protected
|
140
|
+
|
141
|
+
def resource_name
|
142
|
+
@_resource_name.presence || @_parent&.resource_name
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
def default_name
|
148
|
+
@_id.split('-').map(&:capitalize).join('::')
|
149
|
+
end
|
150
|
+
|
123
151
|
end
|
124
152
|
end
|
@@ -116,12 +116,12 @@ module Apipie
|
|
116
116
|
def additional_properties
|
117
117
|
!!@response_object.additional_properties
|
118
118
|
end
|
119
|
-
alias
|
119
|
+
alias allow_additional_properties additional_properties
|
120
120
|
|
121
|
-
def to_json(lang=nil)
|
121
|
+
def to_json(lang = nil)
|
122
122
|
{
|
123
123
|
:code => code,
|
124
|
-
:description => description,
|
124
|
+
:description => Apipie.app.translate(description, lang),
|
125
125
|
:is_array => is_array?,
|
126
126
|
:returns_object => params_ordered.map{ |param| param.to_json(lang).tap{|h| h.delete(:validations) }}.flatten,
|
127
127
|
:additional_properties => additional_properties,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Apipie
|
2
2
|
|
3
|
-
def self.prop(name, expected_type, options={}, sub_properties=[])
|
3
|
+
def self.prop(name, expected_type, options = {}, sub_properties = [])
|
4
4
|
Apipie::ResponseDescriptionAdapter::PropDesc.new(name, expected_type, options, sub_properties)
|
5
5
|
end
|
6
6
|
|
@@ -57,10 +57,10 @@ module Apipie
|
|
57
57
|
attr_reader :expected_type
|
58
58
|
|
59
59
|
def [](key)
|
60
|
-
|
60
|
+
self.send(key) if self.respond_to?(key.to_s)
|
61
61
|
end
|
62
62
|
|
63
|
-
def initialize(expected_type, enum_values=nil, sub_properties=nil)
|
63
|
+
def initialize(expected_type, enum_values = nil, sub_properties = nil)
|
64
64
|
@expected_type = expected_type
|
65
65
|
@enum_values = enum_values
|
66
66
|
@is_enum = !!enum_values
|
@@ -84,7 +84,7 @@ module Apipie
|
|
84
84
|
#======================================================================
|
85
85
|
|
86
86
|
|
87
|
-
def initialize(name, expected_type, options={}, sub_properties=[])
|
87
|
+
def initialize(name, expected_type, options = {}, sub_properties = [])
|
88
88
|
@name = name
|
89
89
|
@required = true
|
90
90
|
@required = false if options[:required] == false
|
@@ -102,14 +102,15 @@ module Apipie
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def [](key)
|
105
|
-
|
105
|
+
self.send(key) if self.respond_to?(key.to_s)
|
106
106
|
end
|
107
107
|
|
108
108
|
def add_sub_property(prop_desc)
|
109
109
|
raise "Only properties with expected_type 'object' can have sub-properties" unless @expected_type == 'object'
|
110
|
-
|
110
|
+
case prop_desc
|
111
|
+
when PropDesc
|
111
112
|
@sub_properties << prop_desc
|
112
|
-
|
113
|
+
when Modifier
|
113
114
|
prop_desc.apply(self)
|
114
115
|
else
|
115
116
|
raise "Unrecognized prop_desc type (#{prop_desc.class})"
|
@@ -130,7 +131,7 @@ module Apipie
|
|
130
131
|
attr_reader :name, :required, :expected_type, :options, :description
|
131
132
|
attr_accessor :additional_properties
|
132
133
|
|
133
|
-
|
134
|
+
alias desc description
|
134
135
|
|
135
136
|
def is_array?
|
136
137
|
@is_array
|
@@ -170,9 +171,10 @@ module Apipie
|
|
170
171
|
end
|
171
172
|
|
172
173
|
def add(prop_desc)
|
173
|
-
|
174
|
+
case prop_desc
|
175
|
+
when PropDesc
|
174
176
|
@property_descs << prop_desc
|
175
|
-
|
177
|
+
when Modifier
|
176
178
|
prop_desc.apply(self)
|
177
179
|
else
|
178
180
|
raise "Unrecognized prop_desc type (#{prop_desc.class})"
|
data/lib/apipie/routing.rb
CHANGED
@@ -4,7 +4,7 @@ module Apipie
|
|
4
4
|
def apipie(options = {})
|
5
5
|
namespace "apipie", :path => Apipie.configuration.doc_base_url do
|
6
6
|
get 'apipie_checksum', :to => "apipies#apipie_checksum", :format => "json"
|
7
|
-
constraints(:version =>
|
7
|
+
constraints(:version => %r{[^/]+}, :resource => %r{[^/]+}, :method => %r{[^/]+}) do
|
8
8
|
get(options.reverse_merge("(:version)/(:resource)/(:method)" => "apipies#index", :as => :apipie))
|
9
9
|
end
|
10
10
|
end
|
@@ -112,7 +112,7 @@ class ActionController::Base
|
|
112
112
|
end
|
113
113
|
|
114
114
|
module Apipie
|
115
|
-
def self.print_validation_errors(validation_errors, schema, response, error_object=nil)
|
115
|
+
def self.print_validation_errors(validation_errors, schema, response, error_object = nil)
|
116
116
|
Rails.logger.warn(validation_errors.to_s)
|
117
117
|
if Rails.env.test?
|
118
118
|
puts "schema validation errors:"
|
@@ -161,8 +161,8 @@ ActionController::TestCase::Behavior.instance_eval do
|
|
161
161
|
# instrument the 'process' method in ActionController::TestCase to enable response validation
|
162
162
|
module Apipie::ResponseValidationHelpers
|
163
163
|
@is_response_validation_on = false
|
164
|
-
def process(
|
165
|
-
result = super
|
164
|
+
def process(*, **)
|
165
|
+
result = super
|
166
166
|
validate_response if @is_response_validation_on
|
167
167
|
|
168
168
|
result
|
@@ -4,12 +4,20 @@ module Apipie
|
|
4
4
|
def initialize(root)
|
5
5
|
@root = root.chomp('/')
|
6
6
|
@compiled_root = /^#{Regexp.escape(root)}/
|
7
|
-
@file_server = ::Rack::
|
7
|
+
@file_server = if defined?(::Rack::Files)
|
8
|
+
::Rack::Files.new(@root)
|
9
|
+
else
|
10
|
+
# Deprecated in Rack 3.0, kept
|
11
|
+
# for backward compatibility
|
12
|
+
::Rack::File.new(@root)
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
def match?(path)
|
11
17
|
# Replace all null bytes
|
12
|
-
path = ::Rack::Utils.unescape(path || '')
|
18
|
+
path = ::Rack::Utils.unescape(path || '')
|
19
|
+
.encode(Encoding::UTF_8, invalid: :replace, replace: '')
|
20
|
+
.gsub("\x0", '')
|
13
21
|
|
14
22
|
full_path = path.empty? ? @root : File.join(@root, path)
|
15
23
|
paths = "#{full_path}#{ext}"
|