apipie-rails 0.9.1 → 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 +81 -0
- data/.rubocop_todo.yml +815 -351
- data/CHANGELOG.md +17 -0
- data/README.rst +20 -0
- data/apipie-rails.gemspec +4 -0
- data/app/controllers/apipie/apipies_controller.rb +5 -6
- 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/apipie_module.rb +2 -2
- data/lib/apipie/application.rb +10 -12
- data/lib/apipie/configuration.rb +24 -13
- data/lib/apipie/dsl_definition.rb +13 -12
- data/lib/apipie/error_description.rb +2 -2
- data/lib/apipie/extractor/recorder.rb +1 -1
- data/lib/apipie/extractor/writer.rb +11 -11
- data/lib/apipie/extractor.rb +1 -1
- data/lib/apipie/generator/swagger/context.rb +27 -0
- data/lib/apipie/generator/swagger/operation_id.rb +51 -0
- data/lib/apipie/generator/swagger/param_description/builder.rb +105 -0
- data/lib/apipie/generator/swagger/param_description/composite.rb +111 -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/type.rb +108 -0
- data/lib/apipie/generator/swagger/param_description.rb +18 -0
- data/lib/apipie/generator/swagger/type_extractor.rb +2 -2
- data/lib/apipie/markup.rb +9 -8
- data/lib/apipie/method_description.rb +4 -5
- data/lib/apipie/param_description/deprecation.rb +24 -0
- data/lib/apipie/param_description.rb +45 -18
- data/lib/apipie/resource_description.rb +4 -4
- data/lib/apipie/response_description.rb +2 -2
- data/lib/apipie/response_description_adapter.rb +7 -5
- data/lib/apipie/swagger_generator.rb +54 -202
- data/lib/apipie/validator.rb +8 -9
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +10 -0
- data/lib/tasks/apipie.rake +6 -6
- data/spec/controllers/users_controller_spec.rb +11 -3
- 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/apipie/generator/swagger/context_spec.rb +35 -0
- data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +163 -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 +178 -0
- data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
- data/spec/lib/{generator → apipie/generator}/swagger/type_extractor_spec.rb +38 -18
- 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/{param_group_spec.rb → apipie/param_group_spec.rb} +5 -5
- 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 +85 -19
- /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/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/{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,6 +4,23 @@
|
|
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
|
+
|
16
|
+
## [v0.9.2](https://github.com/Apipie/apipie-rails/tree/v0.9.2) (2023-02-07)
|
17
|
+
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.9.1...v0.9.2)
|
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)
|
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)
|
20
|
+
* [Refactor] Move swagger param description creation [#810](https://github.com/Apipie/apipie-rails/pull/810) (Panos Dalitsouris)
|
21
|
+
* [Rubocop] Redo rubocop TODOs, set HashSyntax config to most used style [#814](https://github.com/Apipie/apipie-rails/pull/814) (Mathieu Jobin)
|
22
|
+
* [Fix] Swagger missing i18n [#815](https://github.com/Apipie/apipie-rails/pull/815) (@jirubio)
|
23
|
+
|
7
24
|
## [v0.9.1](https://github.com/Apipie/apipie-rails/tree/v0.9.1) (2023-01-16)
|
8
25
|
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.9.0...v0.9.1)
|
9
26
|
* [Refactor] Create test cache files under a not version controlled directory [#809](https://github.com/Apipie/apipie-rails/pull/809) (Panos Dalitsouris)
|
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
|
@@ -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
|
@@ -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/apipie_module.rb
CHANGED
@@ -70,11 +70,11 @@ module Apipie
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def self.app_info_version_valid?(version)
|
73
|
-
version && self.configuration.app_info.
|
73
|
+
version && self.configuration.app_info.key?(version)
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.api_base_url_version_valid?(version)
|
77
|
-
version && self.configuration.api_base_url.
|
77
|
+
version && self.configuration.api_base_url.key?(version)
|
78
78
|
end
|
79
79
|
|
80
80
|
def self.record(record)
|
data/lib/apipie/application.rb
CHANGED
@@ -147,7 +147,7 @@ module Apipie
|
|
147
147
|
|
148
148
|
def get_param_group(controller, name)
|
149
149
|
key = "#{controller.name}##{name}"
|
150
|
-
if @param_groups.
|
150
|
+
if @param_groups.key?(key)
|
151
151
|
return @param_groups[key]
|
152
152
|
else
|
153
153
|
raise "param group #{key} not defined"
|
@@ -181,11 +181,9 @@ 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
|
-
alias
|
186
|
+
alias [] get_method_description
|
189
187
|
|
190
188
|
# options:
|
191
189
|
# => "users"
|
@@ -198,7 +196,7 @@ module Apipie
|
|
198
196
|
version = crumbs.first
|
199
197
|
end
|
200
198
|
version ||= Apipie.configuration.default_version
|
201
|
-
if @resource_descriptions.
|
199
|
+
if @resource_descriptions.key?(version)
|
202
200
|
return @resource_descriptions[version][crumbs.last]
|
203
201
|
end
|
204
202
|
else
|
@@ -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)
|
@@ -373,7 +371,7 @@ module Apipie
|
|
373
371
|
def get_resource_name(klass)
|
374
372
|
if klass.class == String
|
375
373
|
klass
|
376
|
-
elsif @controller_to_resource_id.
|
374
|
+
elsif @controller_to_resource_id.key?(klass)
|
377
375
|
@controller_to_resource_id[klass]
|
378
376
|
elsif Apipie.configuration.namespaced_resources? && klass.respond_to?(:controller_path)
|
379
377
|
return nil if klass == ActionController::Base
|
@@ -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)
|
@@ -408,9 +406,9 @@ module Apipie
|
|
408
406
|
# Make sure that the version/resource_name/method_name are valid combination
|
409
407
|
# resource_name and method_name can be nil
|
410
408
|
def valid_search_args?(version, resource_name, method_name)
|
411
|
-
return false unless self.resource_descriptions.
|
409
|
+
return false unless self.resource_descriptions.key?(version)
|
412
410
|
if resource_name
|
413
|
-
return false unless self.resource_descriptions[version].
|
411
|
+
return false unless self.resource_descriptions[version].key?(resource_name)
|
414
412
|
if method_name
|
415
413
|
resource_description = self.resource_descriptions[version][resource_name]
|
416
414
|
return false unless resource_description.valid_method_name?(method_name)
|
data/lib/apipie/configuration.rb
CHANGED
@@ -14,19 +14,29 @@ module Apipie
|
|
14
14
|
:swagger_allow_additional_properties_in_response, :swagger_responses_use_refs,
|
15
15
|
:swagger_schemes, :swagger_security_definitions, :swagger_global_security
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
alias validate? validate
|
18
|
+
alias required_by_default? required_by_default
|
19
|
+
alias namespaced_resources? namespaced_resources
|
20
|
+
alias swagger_include_warning_tags? swagger_include_warning_tags
|
21
|
+
alias swagger_json_input_uses_refs? swagger_json_input_uses_refs
|
22
|
+
alias swagger_responses_use_refs? swagger_responses_use_refs
|
23
|
+
alias swagger_generate_x_computed_id_field? swagger_generate_x_computed_id_field
|
24
24
|
|
25
25
|
# matcher to be used in Dir.glob to find controllers to be reloaded e.g.
|
26
26
|
#
|
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.
|
@@ -51,17 +61,17 @@ module Apipie
|
|
51
61
|
def validate_value
|
52
62
|
return (validate? && @validate_value)
|
53
63
|
end
|
54
|
-
|
64
|
+
alias validate_value? validate_value
|
55
65
|
|
56
66
|
def validate_presence
|
57
67
|
return (validate? && @validate_presence)
|
58
68
|
end
|
59
|
-
|
69
|
+
alias validate_presence? validate_presence
|
60
70
|
|
61
71
|
def validate_key
|
62
72
|
return (validate? && @validate_key)
|
63
73
|
end
|
64
|
-
|
74
|
+
alias validate_key? validate_key
|
65
75
|
|
66
76
|
def process_value?
|
67
77
|
@process_params
|
@@ -73,7 +83,7 @@ module Apipie
|
|
73
83
|
#
|
74
84
|
# rake apipie:cache
|
75
85
|
attr_accessor :use_cache
|
76
|
-
|
86
|
+
alias use_cache? use_cache
|
77
87
|
|
78
88
|
attr_writer :cache_dir
|
79
89
|
def cache_dir
|
@@ -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
|
@@ -70,7 +70,7 @@ module Apipie
|
|
70
70
|
def short(short)
|
71
71
|
_apipie_dsl_data[:short_description] = short
|
72
72
|
end
|
73
|
-
alias
|
73
|
+
alias short_description short
|
74
74
|
|
75
75
|
def path(path)
|
76
76
|
_apipie_dsl_data[:path] = path
|
@@ -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]
|
@@ -160,7 +160,7 @@ module Apipie
|
|
160
160
|
def api_versions(*versions)
|
161
161
|
_apipie_dsl_data[:api_versions].concat(versions)
|
162
162
|
end
|
163
|
-
alias
|
163
|
+
alias api_version api_versions
|
164
164
|
|
165
165
|
# Describe the next method.
|
166
166
|
#
|
@@ -177,8 +177,8 @@ module Apipie
|
|
177
177
|
end
|
178
178
|
_apipie_dsl_data[:description] = description
|
179
179
|
end
|
180
|
-
alias
|
181
|
-
alias
|
180
|
+
alias description desc
|
181
|
+
alias full_description desc
|
182
182
|
|
183
183
|
# describe next method with document in given path
|
184
184
|
# in convension, these doc located under "#{Rails.root}/doc"
|
@@ -246,14 +246,14 @@ module Apipie
|
|
246
246
|
if Apipie.configuration.validate_presence?
|
247
247
|
method_params.each do |_, param|
|
248
248
|
# check if required parameters are present
|
249
|
-
raise ParamMissing.new(param) if param.required && !params.
|
249
|
+
raise ParamMissing.new(param) if param.required && !params.key?(param.name)
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
253
253
|
if Apipie.configuration.validate_value?
|
254
254
|
method_params.each do |_, param|
|
255
255
|
# params validations
|
256
|
-
param.validate(params[:"#{param.name}"]) if params.
|
256
|
+
param.validate(params[:"#{param.name}"]) if params.key?(param.name)
|
257
257
|
end
|
258
258
|
end
|
259
259
|
|
@@ -272,7 +272,7 @@ module Apipie
|
|
272
272
|
@api_params ||= {}
|
273
273
|
method_params.each do |_, param|
|
274
274
|
# params processing
|
275
|
-
@api_params[param.as] = param.process_value(params[:"#{param.name}"]) if params.
|
275
|
+
@api_params[param.as] = param.process_value(params[:"#{param.name}"]) if params.key?(param.name)
|
276
276
|
end
|
277
277
|
end
|
278
278
|
end
|
@@ -293,9 +293,10 @@ module Apipie
|
|
293
293
|
end
|
294
294
|
|
295
295
|
def _apipie_handle_validate_key_error params, param
|
296
|
-
|
296
|
+
case Apipie.configuration.action_on_non_validated_keys
|
297
|
+
when :raise
|
297
298
|
raise UnknownParam, param
|
298
|
-
|
299
|
+
when :skip
|
299
300
|
params.delete(param)
|
300
301
|
Rails.logger.warn(UnknownParam.new(param).to_s)
|
301
302
|
end
|
@@ -507,7 +508,7 @@ module Apipie
|
|
507
508
|
end
|
508
509
|
|
509
510
|
def _apipie_update_meta(method_desc, dsl_data)
|
510
|
-
return unless dsl_data[:meta]
|
511
|
+
return unless dsl_data[:meta].is_a?(Hash)
|
511
512
|
|
512
513
|
method_desc.metadata ||= {}
|
513
514
|
method_desc.metadata.merge!(dsl_data[:meta])
|
@@ -525,7 +526,7 @@ module Apipie
|
|
525
526
|
end
|
526
527
|
end
|
527
528
|
# backwards compatibility
|
528
|
-
|
529
|
+
alias apipie_update_params apipie_update_methods
|
529
530
|
|
530
531
|
def _apipie_concern_subst
|
531
532
|
@_apipie_concern_subst ||= {:controller_path => self.controller_path,
|
@@ -103,7 +103,7 @@ module Apipie
|
|
103
103
|
call = call.stringify_keys
|
104
104
|
ordered_call = OrderedHash.new
|
105
105
|
%w[title verb path versions query request_data response_data code show_in_doc recorded].each do |k|
|
106
|
-
next unless call.
|
106
|
+
next unless call.key?(k)
|
107
107
|
ordered_call[k] = case call[k]
|
108
108
|
when ActiveSupport::HashWithIndifferentAccess
|
109
109
|
convert_file_value(call[k]).to_hash
|
@@ -116,9 +116,10 @@ module Apipie
|
|
116
116
|
|
117
117
|
def convert_file_value hash
|
118
118
|
hash.each do |k, v|
|
119
|
-
|
119
|
+
case v
|
120
|
+
when Rack::Test::UploadedFile, ActionDispatch::Http::UploadedFile
|
120
121
|
hash[k] = "<FILE CONTENT '#{v.original_filename}'>"
|
121
|
-
|
122
|
+
when Hash
|
122
123
|
hash[k] = convert_file_value(v)
|
123
124
|
end
|
124
125
|
end
|
@@ -134,8 +135,8 @@ module Apipie
|
|
134
135
|
old_examples = self.load_recorded_examples
|
135
136
|
merged_examples = []
|
136
137
|
(new_examples.keys + old_examples.keys).uniq.each do |key|
|
137
|
-
if new_examples.
|
138
|
-
if old_examples.
|
138
|
+
if new_examples.key?(key)
|
139
|
+
if old_examples.key?(key)
|
139
140
|
records = deep_merge_examples(new_examples[key], old_examples[key])
|
140
141
|
else
|
141
142
|
records = new_examples[key]
|
@@ -407,12 +408,11 @@ module Apipie
|
|
407
408
|
if line =~ /\s*\b(module|class|def)\b /
|
408
409
|
break
|
409
410
|
end
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
end
|
411
|
+
next unless line =~ /do\s*(\|.*?\|)?\s*$/
|
412
|
+
block_level -= 1
|
413
|
+
if block_level == 0
|
414
|
+
added_lines.concat(lines_to_add)
|
415
|
+
lines_to_add = []
|
416
416
|
end
|
417
417
|
end
|
418
418
|
return added_lines.reverse.join
|
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
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Apipie::Generator::Swagger::Context
|
2
|
+
attr_reader :default_in_value, :language, :http_method, :controller_method
|
3
|
+
|
4
|
+
def initialize(
|
5
|
+
allow_null:,
|
6
|
+
http_method:,
|
7
|
+
controller_method:,
|
8
|
+
default_in_value: nil,
|
9
|
+
language: nil,
|
10
|
+
in_schema: true
|
11
|
+
)
|
12
|
+
@default_in_value = default_in_value
|
13
|
+
@allow_null = allow_null
|
14
|
+
@language = language
|
15
|
+
@in_schema = in_schema
|
16
|
+
@http_method = http_method
|
17
|
+
@controller_method = controller_method
|
18
|
+
end
|
19
|
+
|
20
|
+
def allow_null?
|
21
|
+
@allow_null == true
|
22
|
+
end
|
23
|
+
|
24
|
+
def in_schema?
|
25
|
+
@in_schema == true
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Apipie::Generator::Swagger::OperationId
|
2
|
+
def initialize(path:, http_method:, param: nil)
|
3
|
+
@path = path
|
4
|
+
@http_method = http_method
|
5
|
+
@param = param
|
6
|
+
end
|
7
|
+
|
8
|
+
# @return [String]
|
9
|
+
def to_s
|
10
|
+
base = normalized_http_method + path
|
11
|
+
|
12
|
+
if @param.present?
|
13
|
+
"#{base}_param_#{@param}"
|
14
|
+
else
|
15
|
+
base
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param [Apipie::MethodDescription::Api, Apipie::MethodDescription] describable
|
20
|
+
# @param [String, Symbol, nil] param
|
21
|
+
#
|
22
|
+
# @return [Apipie::Generator::Swagger::OperationId]
|
23
|
+
def self.from(describable, param: nil)
|
24
|
+
path, http_method =
|
25
|
+
if describable.is_a?(Apipie::MethodDescription::Api)
|
26
|
+
[describable.path, describable.http_method]
|
27
|
+
elsif describable.is_a?(Apipie::MethodDescription)
|
28
|
+
[describable.apis.first.path, describable.apis.first.http_method]
|
29
|
+
end
|
30
|
+
|
31
|
+
new(path: path, http_method: http_method, param: param)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Converts an http path for example `/api/concerns/:id` to `_api_concerns_id`
|
37
|
+
#
|
38
|
+
# @return [String]
|
39
|
+
def path
|
40
|
+
@path.gsub(/\//, '_').gsub(/:(\w+)/, '\1').gsub(/_$/, '')
|
41
|
+
end
|
42
|
+
|
43
|
+
# Converts an http method like `GET` to `get` Using lowercase http method,
|
44
|
+
# because the 'swagger-codegen' tool outputs strange method names if the
|
45
|
+
# http method is in uppercase
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
def normalized_http_method
|
49
|
+
@http_method.to_s.downcase
|
50
|
+
end
|
51
|
+
end
|