apipie-rails 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop-challenger.yml +1 -1
- data/.github/workflows/rubocop.yml +20 -0
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +256 -371
- data/CHANGELOG.md +10 -1
- data/README.rst +20 -0
- data/apipie-rails.gemspec +4 -0
- 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 +7 -0
- data/lib/apipie/application.rb +4 -6
- data/lib/apipie/configuration.rb +13 -2
- data/lib/apipie/dsl_definition.rb +2 -2
- data/lib/apipie/extractor/recorder.rb +1 -1
- data/lib/apipie/extractor.rb +1 -1
- data/lib/apipie/markup.rb +9 -8
- data/lib/apipie/param_description/deprecation.rb +24 -0
- data/lib/apipie/param_description.rb +38 -11
- data/lib/apipie/resource_description.rb +1 -1
- data/lib/apipie/validator.rb +7 -8
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +1 -0
- data/lib/tasks/apipie.rake +1 -0
- data/spec/controllers/users_controller_spec.rb +8 -1
- data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +2 -2
- data/spec/lib/{application_spec.rb → apipie/application_spec.rb} +6 -3
- data/spec/lib/apipie/configuration_spec.rb +23 -0
- data/spec/lib/apipie/extractor/recorder_spec.rb +40 -0
- data/spec/lib/{method_description_spec.rb → apipie/method_description_spec.rb} +4 -4
- data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
- data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +81 -1
- data/spec/lib/{resource_description_spec.rb → apipie/resource_description_spec.rb} +2 -2
- data/spec/lib/swagger/swagger_dsl_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +76 -28
- /data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +0 -0
- /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
- /data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +0 -0
- /data/spec/lib/{extractor → apipie}/extractor_spec.rb +0 -0
- /data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/context_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/operation_id_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/param_description/builder_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/param_description/composite_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/param_description/description_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/param_description/in_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/param_description/name_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/param_description/type_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/param_description_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/type_extractor_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/warning_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/warning_writer_spec.rb +0 -0
- /data/spec/lib/{method_description → apipie/method_description}/apis_service_spec.rb +0 -0
- /data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +0 -0
- /data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +0 -0
- /data/spec/{controllers → test_engine}/memes_controller_spec.rb +0 -0
data/CHANGELOG.md
CHANGED
@@ -4,10 +4,19 @@
|
|
4
4
|
Also deleted the `Gemfile` that was now a broken symlink.
|
5
5
|
please use `export BUNDLE_GEMFILE='gemfiles/Gemfile.rails61'; bundle exec rspec` to run the test suite
|
6
6
|
|
7
|
+
## [v0.9.3](https://github.com/Apipie/apipie-rails/tree/v0.9.3) (2023-03-08)
|
8
|
+
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.9.2...v0.9.3)
|
9
|
+
* [Feature] Allow Apipie::ParamDescription to be marked as deprecated [#819](https://github.com/Apipie/apipie-rails/pull/819)[#811](https://github.com/Apipie/apipie-rails/pull/811) (Panos Dalitsouris)
|
10
|
+
* [Fix] Make html markup thread safe ([#822](https://github.com/Apipie/apipie-rails/issues/822)) (Adam Růžička)
|
11
|
+
* [Feature] Allow action matcher strategy to be configured [#821](https://github.com/Apipie/apipie-rails/pull/821) (Panos Dalitsouris)
|
12
|
+
* [CI] Run Rubocop when opening PR [#826](https://github.com/Apipie/apipie-rails/pull/826) (Panos Dalitsouris)
|
13
|
+
* [CI] Green rubocop - Fix after rubocop challenger upgrade [#829](https://github.com/Apipie/apipie-rails/pull/829) (Mathieu Jobin)
|
14
|
+
* [Rubocop] More Rubocop Auto corrections [#818](https://github.com/Apipie/apipie-rails/pull/818)[#825](https://github.com/Apipie/apipie-rails/pull/825)[#827](https://github.com/Apipie/apipie-rails/pull/827)[#837](https://github.com/Apipie/apipie-rails/pull/837)[#839](https://github.com/Apipie/apipie-rails/pull/839) (Rubocop Challenger)
|
15
|
+
|
7
16
|
## [v0.9.2](https://github.com/Apipie/apipie-rails/tree/v0.9.2) (2023-02-07)
|
8
17
|
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.9.1...v0.9.2)
|
9
18
|
* [Rubocop] More Rubocop Auto corrections [#795](https://github.com/Apipie/apipie-rails/pull/795)[#781](https://github.com/Apipie/apipie-rails/pull/781)[#791](https://github.com/Apipie/apipie-rails/pull/791)[#788](https://github.com/Apipie/apipie-rails/pull/788) (Rubocop Challenger)
|
10
|
-
* [Fix] Can't include translation in full description ([#446](https://github.com/Apipie/apipie-rails/issues/446)) [#808](https://github.com/Apipie/apipie-rails/pull/808)(
|
19
|
+
* [Fix] Can't include translation in full description ([#446](https://github.com/Apipie/apipie-rails/issues/446)) [#808](https://github.com/Apipie/apipie-rails/pull/808) (Peter Nagy)
|
11
20
|
* [Refactor] Move swagger param description creation [#810](https://github.com/Apipie/apipie-rails/pull/810) (Panos Dalitsouris)
|
12
21
|
* [Rubocop] Redo rubocop TODOs, set HashSyntax config to most used style [#814](https://github.com/Apipie/apipie-rails/pull/814) (Mathieu Jobin)
|
13
22
|
* [Fix] Swagger missing i18n [#815](https://github.com/Apipie/apipie-rails/pull/815) (@jirubio)
|
data/README.rst
CHANGED
@@ -355,6 +355,22 @@ Example:
|
|
355
355
|
#...
|
356
356
|
end
|
357
357
|
|
358
|
+
deprecated
|
359
|
+
Indicates if the parameter is marked as deprecated.
|
360
|
+
|
361
|
+
Example
|
362
|
+
~~~~~~~~
|
363
|
+
|
364
|
+
.. code:: ruby
|
365
|
+
|
366
|
+
param :pet_name, String, desc: "Name of pet", deprecated: true
|
367
|
+
param :pet_name, String, desc: "Name of pet", deprecated: 'Some deprecation info'
|
368
|
+
param :pet_name, String, desc: "Name of pet", deprecated: { in: "2.3", info: "Something", sunset: "3.0" }
|
369
|
+
def create
|
370
|
+
#...
|
371
|
+
end
|
372
|
+
|
373
|
+
|
358
374
|
DRY with param_group
|
359
375
|
--------------------
|
360
376
|
|
@@ -982,6 +998,9 @@ reload_controllers
|
|
982
998
|
api_controllers_matcher
|
983
999
|
For reloading to work properly you need to specify where your API controllers are. Can be an array if multiple paths are needed
|
984
1000
|
|
1001
|
+
api_action_matcher
|
1002
|
+
Determines the strategy to identity the correct controller action. Needs to be a class that implements a `.call(controller)` method
|
1003
|
+
|
985
1004
|
api_routes
|
986
1005
|
Set if your application uses a custom API router, different from the Rails
|
987
1006
|
default
|
@@ -1063,6 +1082,7 @@ Example:
|
|
1063
1082
|
config.markup = Apipie::Markup::Markdown.new
|
1064
1083
|
config.reload_controllers = Rails.env.development?
|
1065
1084
|
config.api_controllers_matcher = File.join(Rails.root, "app", "controllers", "**","*.rb")
|
1085
|
+
config.api_action_matcher = proc { |controller| controller.params[:action] }
|
1066
1086
|
config.api_routes = Rails.application.routes
|
1067
1087
|
config.app_info["1.0"] = "
|
1068
1088
|
This is where you can inform user about your application and API
|
data/apipie-rails.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
|
2
3
|
$:.push File.expand_path('lib', __dir__)
|
3
4
|
require "apipie/version"
|
4
5
|
|
@@ -28,6 +29,9 @@ Gem::Specification.new do |s|
|
|
28
29
|
s.add_development_dependency "rspec-rails", "~> 3.0"
|
29
30
|
s.add_development_dependency "rake"
|
30
31
|
s.add_development_dependency 'rubocop_challenger'
|
32
|
+
s.add_development_dependency 'rubocop-rails'
|
33
|
+
s.add_development_dependency 'rubocop-rspec'
|
34
|
+
s.add_development_dependency 'rubocop-performance'
|
31
35
|
s.add_development_dependency "simplecov"
|
32
36
|
s.add_development_dependency "sqlite3"
|
33
37
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% if deprecation.present? %>
|
2
|
+
<strong><%= t('apipie.deprecation_details') %></strong>
|
3
|
+
<ul>
|
4
|
+
<% if deprecation[:deprecated_in].present? %>
|
5
|
+
<li><%= t('apipie.deprecation.attributes.deprecated_in') %>: <%= deprecation[:deprecated_in] %></li>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<% if deprecation[:sunset_at].present? %>
|
9
|
+
<li><%= t('apipie.deprecation.attributes.sunset_at') %>: <%= deprecation[:sunset_at] %></li>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<% if deprecation[:info].present? %>
|
13
|
+
<li><%= t('apipie.deprecation.attributes.info') %>: <%= deprecation[:info] %></li>
|
14
|
+
<% end %>
|
15
|
+
</ul>
|
16
|
+
<% end %>
|
@@ -7,7 +7,11 @@
|
|
7
7
|
<% end %>
|
8
8
|
<tr style='background-color:rgb(<%= "#{col},#{col},#{col}" %>);'>
|
9
9
|
<td>
|
10
|
-
<strong><%= param[:full_name]
|
10
|
+
<strong><%= param[:full_name] %></strong>
|
11
|
+
<% if param[:deprecated].present? %>
|
12
|
+
<code><%= t('apipie.deprecated').upcase %></code>
|
13
|
+
<% end %>
|
14
|
+
<br>
|
11
15
|
<small>
|
12
16
|
<%= param[:required] ? t('apipie.required') : t('apipie.optional') %>
|
13
17
|
<%= param[:allow_nil] ? ', '+t('apipie.nil_allowed') : '' %>
|
@@ -29,6 +33,8 @@
|
|
29
33
|
</ul>
|
30
34
|
<%- end %>
|
31
35
|
|
36
|
+
<%= render partial: 'deprecation', locals: { deprecation: param[:deprecation] } %>
|
37
|
+
|
32
38
|
<% unless param[:metadata].blank? %>
|
33
39
|
<br>
|
34
40
|
Metadata:
|
data/config/locales/en.yml
CHANGED
data/lib/apipie/application.rb
CHANGED
@@ -181,9 +181,7 @@ module Apipie
|
|
181
181
|
else
|
182
182
|
raise ArgumentError.new("Resource #{resource_name} does not exists.")
|
183
183
|
end
|
184
|
-
|
185
|
-
resource_description.method_description(method_name.to_sym)
|
186
|
-
end
|
184
|
+
resource_description&.method_description(method_name.to_sym)
|
187
185
|
end
|
188
186
|
alias [] get_method_description
|
189
187
|
|
@@ -242,7 +240,7 @@ module Apipie
|
|
242
240
|
|
243
241
|
# initialize variables for gathering dsl data
|
244
242
|
def init_env
|
245
|
-
@resource_descriptions = HashWithIndifferentAccess.new { |h, version| h[version] = {} }
|
243
|
+
@resource_descriptions = ActiveSupport::HashWithIndifferentAccess.new { |h, version| h[version] = {} }
|
246
244
|
@controller_to_resource_id = {}
|
247
245
|
@param_groups = {}
|
248
246
|
@swagger_generator = Apipie::SwaggerGenerator.new(self)
|
@@ -388,11 +386,11 @@ module Apipie
|
|
388
386
|
end
|
389
387
|
|
390
388
|
def locale
|
391
|
-
Apipie.configuration.locale
|
389
|
+
Apipie.configuration.locale&.call(nil)
|
392
390
|
end
|
393
391
|
|
394
392
|
def locale=(locale)
|
395
|
-
Apipie.configuration.locale
|
393
|
+
Apipie.configuration.locale&.call(locale)
|
396
394
|
end
|
397
395
|
|
398
396
|
def translate(str, locale)
|
data/lib/apipie/configuration.rb
CHANGED
@@ -27,6 +27,16 @@ module Apipie
|
|
27
27
|
# "#{Rails.root}/app/controllers/api/*.rb"
|
28
28
|
attr_accessor :api_controllers_matcher
|
29
29
|
|
30
|
+
# An object that responds to a `.call(controller)` method responsible for
|
31
|
+
# matching the correct controller action
|
32
|
+
attr_reader :api_action_matcher
|
33
|
+
|
34
|
+
def api_action_matcher=(callable)
|
35
|
+
raise 'Must implement .call method' unless callable.respond_to?(:call)
|
36
|
+
|
37
|
+
@api_action_matcher = callable
|
38
|
+
end
|
39
|
+
|
30
40
|
# set to true if you want to reload the controllers at each refresh of the
|
31
41
|
# documentation. It requires +:api_controllers_matcher+ to be set to work
|
32
42
|
# properly.
|
@@ -147,7 +157,7 @@ module Apipie
|
|
147
157
|
def initialize
|
148
158
|
@markup = Apipie::Markup::RDoc.new
|
149
159
|
@app_name = "Another API"
|
150
|
-
@app_info = HashWithIndifferentAccess.new
|
160
|
+
@app_info = ActiveSupport::HashWithIndifferentAccess.new
|
151
161
|
@copyright = nil
|
152
162
|
@validate = :implicitly
|
153
163
|
@validate_value = true
|
@@ -155,7 +165,8 @@ module Apipie
|
|
155
165
|
@validate_key = false
|
156
166
|
@action_on_non_validated_keys = :raise
|
157
167
|
@required_by_default = false
|
158
|
-
@api_base_url = HashWithIndifferentAccess.new
|
168
|
+
@api_base_url = ActiveSupport::HashWithIndifferentAccess.new
|
169
|
+
@api_action_matcher = proc { |controller| controller.params[:action] }
|
159
170
|
@doc_base_url = "/apipie"
|
160
171
|
@layout = "apipie/apipie"
|
161
172
|
@disqus_shortname = nil
|
@@ -145,7 +145,7 @@ module Apipie
|
|
145
145
|
# EOS
|
146
146
|
def resource_description(options = {}, &block) #:doc:
|
147
147
|
return unless Apipie.active_dsl?
|
148
|
-
raise ArgumentError, "Block expected" unless
|
148
|
+
raise ArgumentError, "Block expected" unless block
|
149
149
|
|
150
150
|
dsl_data = ResourceDescriptionDsl.eval_dsl(self, &block)
|
151
151
|
versions = dsl_data[:api_versions]
|
@@ -508,7 +508,7 @@ module Apipie
|
|
508
508
|
end
|
509
509
|
|
510
510
|
def _apipie_update_meta(method_desc, dsl_data)
|
511
|
-
return unless dsl_data[:meta]
|
511
|
+
return unless dsl_data[:meta].is_a?(Hash)
|
512
512
|
|
513
513
|
method_desc.metadata ||= {}
|
514
514
|
method_desc.metadata.merge!(dsl_data[:meta])
|
data/lib/apipie/extractor.rb
CHANGED
@@ -157,7 +157,7 @@ module Apipie
|
|
157
157
|
method_key = "#{Apipie.get_resource_name(controller.safe_constantize || next)}##{action}"
|
158
158
|
old_apis = apis_from_docs[method_key] || []
|
159
159
|
new_apis.each do |new_api|
|
160
|
-
new_api[:path]
|
160
|
+
new_api[:path]&.sub!(/\(\.:format\)$/,"")
|
161
161
|
old_api = old_apis.find do |api|
|
162
162
|
api[:path] == "#{@api_prefix}#{new_api[:path]}"
|
163
163
|
end
|
data/lib/apipie/markup.rb
CHANGED
@@ -4,6 +4,11 @@ module Apipie
|
|
4
4
|
|
5
5
|
class RDoc
|
6
6
|
|
7
|
+
def initialize
|
8
|
+
require 'rdoc'
|
9
|
+
require 'rdoc/markup/to_html'
|
10
|
+
end
|
11
|
+
|
7
12
|
def to_html(text)
|
8
13
|
rdoc.convert(text)
|
9
14
|
end
|
@@ -11,14 +16,10 @@ module Apipie
|
|
11
16
|
private
|
12
17
|
|
13
18
|
def rdoc
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
::RDoc::Markup::ToHtml.new()
|
19
|
-
else
|
20
|
-
::RDoc::Markup::ToHtml.new(::RDoc::Options.new)
|
21
|
-
end
|
19
|
+
if Gem::Version.new(::RDoc::VERSION) < Gem::Version.new('4.0.0')
|
20
|
+
::RDoc::Markup::ToHtml.new()
|
21
|
+
else
|
22
|
+
::RDoc::Markup::ToHtml.new(::RDoc::Options.new)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Apipie
|
4
|
+
class ParamDescription
|
5
|
+
# Data transfer object, used when param description is deprecated
|
6
|
+
class Deprecation
|
7
|
+
attr_reader :info, :deprecated_in, :sunset_at
|
8
|
+
|
9
|
+
def initialize(info: nil, deprecated_in: nil, sunset_at: nil)
|
10
|
+
@info = info
|
11
|
+
@deprecated_in = deprecated_in
|
12
|
+
@sunset_at = sunset_at
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json(*_args)
|
16
|
+
{
|
17
|
+
info: @info,
|
18
|
+
deprecated_in: @deprecated_in,
|
19
|
+
sunset_at: @sunset_at
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -97,6 +97,7 @@ module Apipie
|
|
97
97
|
@validations = Array(options[:validations]).map {|v| concern_subst(Apipie.markup_to_html(v)) }
|
98
98
|
|
99
99
|
@additional_properties = @options[:additional_properties]
|
100
|
+
@deprecated = @options[:deprecated] || false
|
100
101
|
end
|
101
102
|
|
102
103
|
def from_concern?
|
@@ -155,17 +156,25 @@ module Apipie
|
|
155
156
|
end
|
156
157
|
|
157
158
|
def to_json(lang = nil)
|
158
|
-
hash = {
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
159
|
+
hash = {
|
160
|
+
name: name.to_s,
|
161
|
+
full_name: full_name,
|
162
|
+
description: preformat_text(Apipie.app.translate(@options[:desc], lang)),
|
163
|
+
required: required,
|
164
|
+
allow_nil: allow_nil,
|
165
|
+
allow_blank: allow_blank,
|
166
|
+
validator: validator.to_s,
|
167
|
+
expected_type: validator.expected_type,
|
168
|
+
metadata: metadata,
|
169
|
+
show: show,
|
170
|
+
validations: validations,
|
171
|
+
deprecated: deprecated?
|
172
|
+
}
|
173
|
+
|
174
|
+
if deprecation.present?
|
175
|
+
hash[:deprecation] = deprecation.to_json
|
176
|
+
end
|
177
|
+
|
169
178
|
if sub_params = validator.params_ordered
|
170
179
|
hash[:params] = sub_params.map { |p| p.to_json(lang)}
|
171
180
|
end
|
@@ -279,6 +288,24 @@ module Apipie
|
|
279
288
|
end
|
280
289
|
end
|
281
290
|
|
291
|
+
def deprecated?
|
292
|
+
@deprecated.present?
|
293
|
+
end
|
294
|
+
|
295
|
+
def deprecation
|
296
|
+
return if @deprecated.blank? || @deprecated == true
|
297
|
+
|
298
|
+
case @deprecated
|
299
|
+
when Hash
|
300
|
+
Apipie::ParamDescription::Deprecation.new(
|
301
|
+
info: @deprecated[:info],
|
302
|
+
deprecated_in: @deprecated[:in],
|
303
|
+
sunset_at: @deprecated[:sunset]
|
304
|
+
)
|
305
|
+
when String
|
306
|
+
Apipie::ParamDescription::Deprecation.new(info: @deprecated)
|
307
|
+
end
|
308
|
+
end
|
282
309
|
end
|
283
310
|
|
284
311
|
end
|
@@ -17,7 +17,7 @@ module Apipie
|
|
17
17
|
:_path, :_name, :_params_args, :_returns_args, :_tag_list_arg, :_errors_args,
|
18
18
|
:_formats, :_parent, :_metadata, :_headers, :_deprecated
|
19
19
|
|
20
|
-
def initialize(controller, resource_name, dsl_data = nil, version = nil
|
20
|
+
def initialize(controller, resource_name, dsl_data = nil, version = nil)
|
21
21
|
|
22
22
|
@_methods = ActiveSupport::OrderedHash.new
|
23
23
|
@_params_args = []
|
data/lib/apipie/validator.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
|
2
3
|
module Apipie
|
3
4
|
|
4
5
|
module Validator
|
@@ -344,14 +345,12 @@ module Apipie
|
|
344
345
|
|
345
346
|
def validate(value)
|
346
347
|
return false if !value.is_a? Hash
|
347
|
-
|
348
|
-
|
349
|
-
if
|
350
|
-
|
351
|
-
|
352
|
-
if
|
353
|
-
p.validate(value[k]) if value.key?(k)
|
354
|
-
end
|
348
|
+
@hash_params&.each do |k, p|
|
349
|
+
if Apipie.configuration.validate_presence?
|
350
|
+
raise ParamMissing.new(p) if p.required && !value.key?(k)
|
351
|
+
end
|
352
|
+
if Apipie.configuration.validate_value?
|
353
|
+
p.validate(value[k]) if value.key?(k)
|
355
354
|
end
|
356
355
|
end
|
357
356
|
return true
|
data/lib/apipie/version.rb
CHANGED
data/lib/apipie-rails.rb
CHANGED
@@ -12,6 +12,7 @@ require "apipie/configuration"
|
|
12
12
|
require "apipie/method_description"
|
13
13
|
require "apipie/resource_description"
|
14
14
|
require "apipie/param_description"
|
15
|
+
require "apipie/param_description/deprecation"
|
15
16
|
require "apipie/method_description/api"
|
16
17
|
require "apipie/method_description/apis_service"
|
17
18
|
require "apipie/errors"
|
data/lib/tasks/apipie.rake
CHANGED
@@ -269,6 +269,7 @@ describe UsersController do
|
|
269
269
|
:allow_blank => false,
|
270
270
|
:metadata => nil,
|
271
271
|
:show => true,
|
272
|
+
:deprecated => false,
|
272
273
|
:expected_type => "hash",
|
273
274
|
:validations => [])
|
274
275
|
end
|
@@ -585,6 +586,7 @@ describe UsersController do
|
|
585
586
|
:description=>"\n<p>Authorization</p>\n",
|
586
587
|
:name=>"oauth",
|
587
588
|
:show=>true,
|
589
|
+
:deprecated=>false,
|
588
590
|
:expected_type=>"string"},
|
589
591
|
{:validator=>"Must be a Hash",
|
590
592
|
:description=>"\n<p>Deprecated parameter not documented</p>\n",
|
@@ -595,15 +597,17 @@ describe UsersController do
|
|
595
597
|
:required=>false,
|
596
598
|
:full_name=>"legacy_param",
|
597
599
|
:show=>false,
|
600
|
+
:deprecated=>false,
|
598
601
|
:params=>
|
599
602
|
[{:validator=>"Must be a Hash",
|
600
603
|
:description=>"\n<p>Param description for all methods</p>\n",
|
601
604
|
:expected_type=>"hash",
|
602
605
|
:allow_nil=>false,
|
603
|
-
|
606
|
+
:allow_blank => false,
|
604
607
|
:name=>"resource_param",
|
605
608
|
:required=>false,
|
606
609
|
:full_name=>"resource_param",
|
610
|
+
:deprecated=>false,
|
607
611
|
:show=>true,
|
608
612
|
:params=>
|
609
613
|
[{:required=>true,
|
@@ -613,6 +617,7 @@ describe UsersController do
|
|
613
617
|
:description=>"\n<p>Username for login</p>\n",
|
614
618
|
:name=>"ausername", :full_name=>"resource_param[ausername]",
|
615
619
|
:show=>true,
|
620
|
+
:deprecated=>false,
|
616
621
|
:expected_type=>"string"},
|
617
622
|
{:required=>true,
|
618
623
|
:allow_nil => false,
|
@@ -621,6 +626,7 @@ describe UsersController do
|
|
621
626
|
:description=>"\n<p>Password for login</p>\n",
|
622
627
|
:name=>"apassword", :full_name=>"resource_param[apassword]",
|
623
628
|
:show=>true,
|
629
|
+
:deprecated=>false,
|
624
630
|
:expected_type=>"string"}
|
625
631
|
]}
|
626
632
|
]
|
@@ -631,6 +637,7 @@ describe UsersController do
|
|
631
637
|
:description=>"\n<p>Company ID</p>\n",
|
632
638
|
:name=>"id", :full_name=>"id",
|
633
639
|
:show=>true,
|
640
|
+
:deprecated=>false,
|
634
641
|
:expected_type=>"numeric"},
|
635
642
|
],
|
636
643
|
:name => 'two_urls',
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'fileutils'
|
3
3
|
require "json-schema"
|
4
4
|
|
5
|
-
describe Apipie::ApipiesController do
|
5
|
+
describe Apipie::ApipiesController, type: :controller do
|
6
6
|
|
7
7
|
describe "GET index" do
|
8
8
|
|
@@ -159,7 +159,7 @@ describe Apipie::ApipiesController do
|
|
159
159
|
describe "GET index as swagger" do
|
160
160
|
|
161
161
|
let(:swagger_schema) do
|
162
|
-
File.read(
|
162
|
+
File.read("#{Rails.root.parent}/lib/swagger/openapi_2_0_schema.json")
|
163
163
|
end
|
164
164
|
|
165
165
|
it "outputs swagger when format is json and type is swagger" do
|
@@ -3,7 +3,10 @@ require "spec_helper"
|
|
3
3
|
describe Apipie::Application do
|
4
4
|
|
5
5
|
describe "api_controllers_paths" do
|
6
|
-
before
|
6
|
+
before do
|
7
|
+
Apipie.configuration.api_controllers_matcher = [File.join(Rails.root, "app", "controllers", "**","*.rb"),
|
8
|
+
File.join(Rails.root, "lib", "**","*.rb")]
|
9
|
+
end
|
7
10
|
|
8
11
|
it "should support receiving array as parameter" do
|
9
12
|
expect { Apipie.api_controllers_paths}.
|
@@ -19,11 +22,11 @@ describe Apipie::Application do
|
|
19
22
|
context "with namespaced_resources enabled" do
|
20
23
|
before { Apipie.configuration.namespaced_resources = true }
|
21
24
|
context "with a defined base url" do
|
22
|
-
|
25
|
+
|
23
26
|
it "should not overwrite the parent resource" do
|
24
27
|
is_expected.not_to eq(Apipie.get_resource_name(Api::V2::ArchitecturesController))
|
25
28
|
end
|
26
|
-
|
29
|
+
|
27
30
|
end
|
28
31
|
|
29
32
|
context "with an undefined base url" do
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'Apipie::Configuration' do
|
6
|
+
let(:configuration) { Apipie::Configuration.new }
|
7
|
+
|
8
|
+
describe '#api_action_matcher=' do
|
9
|
+
subject(:setter) { configuration.api_action_matcher = matcher }
|
10
|
+
|
11
|
+
let(:matcher) { proc { |_| :some_action } }
|
12
|
+
|
13
|
+
it { is_expected.to eq(matcher) }
|
14
|
+
|
15
|
+
context 'when matcher does not implement .call method' do
|
16
|
+
let(:matcher) { 'I do not implement .call' }
|
17
|
+
|
18
|
+
it 'raises and exception' do
|
19
|
+
expect { setter }.to raise_error('Must implement .call method')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'Apipie::Extractor::Recorder' do
|
6
|
+
let(:recorder) { Apipie::Extractor::Recorder.new }
|
7
|
+
|
8
|
+
describe '#analyse_controller' do
|
9
|
+
subject do
|
10
|
+
recorder.analyse_controller(controller)
|
11
|
+
recorder.record[:action]
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:action) { :show }
|
15
|
+
|
16
|
+
let(:request) do
|
17
|
+
request = ActionDispatch::Request.new({})
|
18
|
+
request.request_parameters = { action: action }
|
19
|
+
request
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:controller) do
|
23
|
+
controller = ActionController::Metal.new
|
24
|
+
controller.set_request!(request)
|
25
|
+
controller
|
26
|
+
end
|
27
|
+
|
28
|
+
it { is_expected.to eq(action) }
|
29
|
+
|
30
|
+
context 'when a api_action_matcher is configured' do
|
31
|
+
let(:matcher_action) { "#{action}_from_new_matcher" }
|
32
|
+
|
33
|
+
before do
|
34
|
+
Apipie.configuration.api_action_matcher = proc { |_| matcher_action }
|
35
|
+
end
|
36
|
+
|
37
|
+
it { is_expected.to eq(matcher_action) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -58,12 +58,12 @@ describe Apipie::MethodDescription do
|
|
58
58
|
|
59
59
|
it "should be ordered" do
|
60
60
|
expect(@method.params.keys).to eq([:a, :b, :c])
|
61
|
-
expect(@method.to_json[:params].map{|h| h[:name]}).to eq(['a', 'b', 'c'])
|
61
|
+
expect(@method.to_json[:params].map { |h| h[:name] }).to eq(['a', 'b', 'c'])
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should be still ordered" do
|
65
65
|
expect(@method.params.keys).to eq([:a, :b, :c])
|
66
|
-
expect(@method.to_json[:params].map{|h| h[:name]}).to eq(['a', 'b', 'c'])
|
66
|
+
expect(@method.to_json[:params].map { |h| h[:name] }).to eq(['a', 'b', 'c'])
|
67
67
|
end
|
68
68
|
|
69
69
|
end
|
@@ -80,7 +80,7 @@ describe Apipie::MethodDescription do
|
|
80
80
|
|
81
81
|
it "should ignore response-only parameters" do
|
82
82
|
expect(@method.params.keys).to eq([:a, :c])
|
83
|
-
expect(@method.to_json[:params].map{|h| h[:name]}).to eq(['a', 'c'])
|
83
|
+
expect(@method.to_json[:params].map { |h| h[:name] }).to eq(['a', 'c'])
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -90,7 +90,7 @@ describe Apipie::MethodDescription do
|
|
90
90
|
@resource = Apipie::ResourceDescription.new(ApplicationController, "dummy")
|
91
91
|
dsl_data[:returns] = { 200 => [{:param_group => 'pet', :array_of => 'pet'}, nil, nil] }
|
92
92
|
|
93
|
-
expect {Apipie::MethodDescription.new(:a, @resource, dsl_data)}.to raise_error(Apipie::ReturnsMultipleDefinitionError)
|
93
|
+
expect { Apipie::MethodDescription.new(:a, @resource, dsl_data) }.to raise_error(Apipie::ReturnsMultipleDefinitionError)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::ParamDescription::Deprecation do
|
4
|
+
let(:info) { nil }
|
5
|
+
let(:deprecated_in) { nil }
|
6
|
+
let(:sunset_at) { nil }
|
7
|
+
|
8
|
+
let(:deprecation) do
|
9
|
+
described_class.new(
|
10
|
+
info: info,
|
11
|
+
deprecated_in: deprecated_in,
|
12
|
+
sunset_at: sunset_at
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#to_json' do
|
17
|
+
subject { deprecation.to_json }
|
18
|
+
|
19
|
+
it { is_expected.to eq({ info: nil, deprecated_in: nil, sunset_at: nil }) }
|
20
|
+
|
21
|
+
context 'when attributes are given' do
|
22
|
+
let(:info) { 'info' }
|
23
|
+
let(:deprecated_in) { '2.3' }
|
24
|
+
let(:sunset_at) { '3.0' }
|
25
|
+
|
26
|
+
it 'returns the correct attributes' do
|
27
|
+
expect(subject).to eq({ info: info, deprecated_in: deprecated_in, sunset_at: sunset_at })
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|