apipie-rails 0.9.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop.yml +2 -2
- data/.rubocop.yml +23 -14
- data/.rubocop_todo.yml +103 -487
- data/CHANGELOG.md +20 -3
- data/README.rst +12 -12
- data/app/controllers/apipie/apipies_controller.rb +6 -6
- data/app/helpers/apipie_helper.rb +1 -1
- data/lib/apipie/apipie_module.rb +5 -5
- data/lib/apipie/application.rb +81 -55
- data/lib/apipie/configuration.rb +19 -26
- data/lib/apipie/dsl_definition.rb +8 -9
- data/lib/apipie/error_description.rb +1 -1
- data/lib/apipie/errors.rb +2 -16
- data/lib/apipie/extractor/collector.rb +3 -3
- data/lib/apipie/extractor/recorder.rb +1 -1
- data/lib/apipie/extractor.rb +2 -2
- data/lib/apipie/generator/config.rb +12 -0
- data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
- data/lib/apipie/generator/swagger/config.rb +78 -0
- data/lib/apipie/generator/swagger/context.rb +12 -1
- data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
- data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +86 -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 +2 -2
- data/lib/apipie/generator/swagger/param_description/builder.rb +4 -4
- data/lib/apipie/generator/swagger/param_description/composite.rb +9 -1
- data/lib/apipie/generator/swagger/param_description/in.rb +1 -1
- 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 +9 -2
- 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/type_extractor.rb +0 -19
- data/lib/apipie/generator/swagger/warning.rb +3 -6
- data/lib/apipie/generator/swagger/warning_writer.rb +7 -1
- data/lib/apipie/helpers.rb +3 -3
- data/lib/apipie/method_description.rb +5 -3
- data/lib/apipie/param_description.rb +4 -2
- data/lib/apipie/resource_description.rb +11 -8
- data/lib/apipie/response_description.rb +1 -1
- data/lib/apipie/response_description_adapter.rb +3 -3
- data/lib/apipie/routing.rb +1 -1
- data/lib/apipie/rspec/response_validation_helper.rb +1 -1
- data/lib/apipie/swagger_generator.rb +27 -551
- data/lib/apipie/validator.rb +9 -5
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +17 -0
- data/lib/tasks/apipie.rake +25 -20
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +2 -2
- data/spec/controllers/pets_controller_spec.rb +10 -16
- data/spec/controllers/users_controller_spec.rb +2 -2
- data/spec/dummy/app/controllers/pets_controller.rb +4 -4
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
- data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
- data/spec/dummy/app/controllers/users_controller.rb +5 -5
- data/spec/dummy/config.ru +1 -1
- data/spec/lib/apipie/apipies_controller_spec.rb +4 -0
- data/spec/lib/apipie/application_spec.rb +25 -15
- data/spec/lib/apipie/configuration_spec.rb +15 -0
- data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
- data/spec/lib/apipie/generator/swagger/context_spec.rb +23 -2
- data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +106 -0
- data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +1 -1
- data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +2 -2
- data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +7 -7
- 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 +0 -43
- data/spec/lib/apipie/generator/swagger/warning_spec.rb +1 -1
- data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +19 -7
- data/spec/lib/apipie/method_description_spec.rb +101 -66
- data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
- data/spec/lib/apipie/param_description_spec.rb +209 -49
- data/spec/lib/apipie/param_group_spec.rb +1 -0
- data/spec/lib/apipie/resource_description_spec.rb +71 -28
- 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/apipie/validator_spec.rb +47 -11
- data/spec/lib/rake_spec.rb +1 -1
- data/spec/lib/swagger/rake_swagger_spec.rb +6 -6
- data/spec/lib/swagger/swagger_dsl_spec.rb +17 -11
- data/spec/lib/validators/array_validator_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- metadata +31 -3
data/CHANGELOG.md
CHANGED
@@ -4,18 +4,35 @@
|
|
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
|
+
## [v1.0.0](https://github.com/Apipie/apipie-rails/tree/v1.0.0) (2023-04-26)
|
8
|
+
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.9.4...v1.0.0)
|
9
|
+
* Refactor Swagger generator [#816](https://github.com/Apipie/apipie-rails/pull/816) (Panos Dalitsouris)
|
10
|
+
* Take into account validator options for `required` ParamDescription [#863](https://github.com/Apipie/apipie-rails/pull/863) (Panos Dalitsouris)
|
11
|
+
* Replace `get_resource_name` with `get_resource_id` [#864](https://github.com/Apipie/apipie-rails/pull/864) (Panos Dalitsouris)
|
12
|
+
* Namespace swagger configuration [#862](https://github.com/Apipie/apipie-rails/pull/862) (Panos Dalitsouris)
|
13
|
+
* Allow boolean array `[true, false]` to be a valid argument for BooleanValidator [#848](https://github.com/Apipie/apipie-rails/pull/848) (Panos Dalitsouris)
|
14
|
+
* Fix swagger warnings [#865](https://github.com/Apipie/apipie-rails/pull/865) (Panos Dalitsouris)
|
15
|
+
* Update README - Adds the new Integer option you added recently to the documentation here. [#866](https://github.com/Apipie/apipie-rails/pull/866) (Jeremy Lupoli)
|
16
|
+
* [Rubocop] More Rubocop Auto corrections [#859](https://github.com/Apipie/apipie-rails/pull/859)
|
17
|
+
|
18
|
+
## [v0.9.4](https://github.com/Apipie/apipie-rails/tree/v0.9.4) (2023-04-11)
|
19
|
+
[Full Changelog](https://github.com/Apipie/apipie-rails/compare/v0.9.3...v0.9.4)
|
20
|
+
* [Fix] Separate nested resource name [#855](https://github.com/Apipie/apipie-rails/pull/855), [#455](https://github.com/Apipie/apipie-rails/issues/455) (Panos Dalitsouris)
|
21
|
+
* [Rubocop] Disable a few Rubocop Rules, run Rubocop with ruby 3.2 [#851](https://github.com/Apipie/apipie-rails/pull/851), [#853](https://github.com/Apipie/apipie-rails/pull/853), [#840](https://github.com/Apipie/apipie-rails/pull/840), [#841](https://github.com/Apipie/apipie-rails/pull/841) (Panos Dalitsouris)
|
22
|
+
* [Rubocop] More Rubocop Auto corrections [#858](https://github.com/Apipie/apipie-rails/pull/858), [#849](https://github.com/Apipie/apipie-rails/pull/849), [#850](https://github.com/Apipie/apipie-rails/pull/850), [#844](https://github.com/Apipie/apipie-rails/pull/844), [#846](https://github.com/Apipie/apipie-rails/pull/846), [#834](https://github.com/Apipie/apipie-rails/pull/834), [#847](https://github.com/Apipie/apipie-rails/pull/847) (Rubocop Challenger)
|
23
|
+
|
7
24
|
## [v0.9.3](https://github.com/Apipie/apipie-rails/tree/v0.9.3) (2023-03-08)
|
8
25
|
[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)
|
26
|
+
* [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
27
|
* [Fix] Make html markup thread safe ([#822](https://github.com/Apipie/apipie-rails/issues/822)) (Adam Růžička)
|
11
28
|
* [Feature] Allow action matcher strategy to be configured [#821](https://github.com/Apipie/apipie-rails/pull/821) (Panos Dalitsouris)
|
12
29
|
* [CI] Run Rubocop when opening PR [#826](https://github.com/Apipie/apipie-rails/pull/826) (Panos Dalitsouris)
|
13
30
|
* [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)
|
31
|
+
* [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
32
|
|
16
33
|
## [v0.9.2](https://github.com/Apipie/apipie-rails/tree/v0.9.2) (2023-02-07)
|
17
34
|
[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)
|
35
|
+
* [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
36
|
* [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
37
|
* [Refactor] Move swagger param description creation [#810](https://github.com/Apipie/apipie-rails/pull/810) (Panos Dalitsouris)
|
21
38
|
* [Rubocop] Redo rubocop TODOs, set HashSyntax config to most used style [#814](https://github.com/Apipie/apipie-rails/pull/814) (Mathieu Jobin)
|
data/README.rst
CHANGED
@@ -1205,7 +1205,7 @@ after the ``apipie_validations`` before_action.
|
|
1205
1205
|
|
1206
1206
|
TypeValidator
|
1207
1207
|
-------------
|
1208
|
-
Check the parameter type. Only String, Hash and Array are supported
|
1208
|
+
Check the parameter type. Only String, Integer, Hash and Array are supported
|
1209
1209
|
for the sake of simplicity. Read more to find out how to add
|
1210
1210
|
your own validator.
|
1211
1211
|
|
@@ -1664,7 +1664,7 @@ Swagger-Specific Configuration Parameters
|
|
1664
1664
|
|
1665
1665
|
There are several configuration parameters that determine the structure of the generated swagger file:
|
1666
1666
|
|
1667
|
-
``config.
|
1667
|
+
``config.generator.swagger.content_type_input``
|
1668
1668
|
If the value is ``:form_data`` - the swagger file will indicate that the server consumes the content types
|
1669
1669
|
``application/x-www-form-urlencoded`` and ``multipart/form-data``. Non-path parameters will have the
|
1670
1670
|
value ``"in": "formData"``. Note that parameters of type Hash that do not have any fields in them will *be ommitted*
|
@@ -1677,52 +1677,52 @@ There are several configuration parameters that determine the structure of the g
|
|
1677
1677
|
You can specify the value of this configuration parameter as an additional input to the rake command (e.g.,
|
1678
1678
|
``rake apipie:static_swagger_json[2.0,form_data]``).
|
1679
1679
|
|
1680
|
-
``config.
|
1681
|
-
This parameter is only relevant if ``
|
1680
|
+
``config.generator.swagger.json_input_uses_refs``
|
1681
|
+
This parameter is only relevant if ``swagger.content_type_input`` is ``:json``.
|
1682
1682
|
|
1683
1683
|
If ``true``: the schema of the ``"in": "body"`` parameter of each method is given its own entry in the ``definitions``
|
1684
1684
|
section, and is referenced using ``$ref`` from the method definition.
|
1685
1685
|
|
1686
1686
|
If ``false``: the body parameter definitions are inlined within the method definitions.
|
1687
1687
|
|
1688
|
-
``config.
|
1688
|
+
``config.generator.swagger.include_warning_tags``
|
1689
1689
|
If ``true``: in addition to tagging methods with the name of the resource they belong to, methods for which warnings
|
1690
1690
|
have been issued will be tagged with.
|
1691
1691
|
|
1692
|
-
``config.
|
1692
|
+
``config.generator.swagger.suppress_warnings``
|
1693
1693
|
If ``false``: no warnings will be suppressed
|
1694
1694
|
|
1695
1695
|
If ``true``: all warnings will be suppressed
|
1696
1696
|
|
1697
1697
|
If an array of values (e.g., ``[100,102,107]``), only the warnings identified by the numbers in the array will be suppressed.
|
1698
1698
|
|
1699
|
-
``config.
|
1699
|
+
``config.generator.swagger.api_host``
|
1700
1700
|
The value to place in the swagger host field.
|
1701
1701
|
|
1702
1702
|
Default is ``localhost:3000``
|
1703
1703
|
|
1704
1704
|
If ``nil`` then then host field will not be included.
|
1705
1705
|
|
1706
|
-
``config.
|
1706
|
+
``config.generator.swagger.allow_additional_properties_in_response``
|
1707
1707
|
If ``false`` (default): response descriptions in the generated swagger will include an ``additional-properties: false``
|
1708
1708
|
field
|
1709
1709
|
|
1710
1710
|
If ``true``: the ``additional-properties: false`` field will not be included in response object descriptions
|
1711
1711
|
|
1712
|
-
``config.
|
1712
|
+
``config.generator.swagger.schemes``
|
1713
1713
|
An array of transport schemes that the API supports.
|
1714
1714
|
This can include any combination of ``http``, ``https``, ``ws`` and ``wss``.
|
1715
1715
|
By default to encourage good security practices, ``['https']`` is specified.
|
1716
1716
|
|
1717
1717
|
|
1718
|
-
``config:
|
1718
|
+
``config:swagger.security_definitions``
|
1719
1719
|
If the API requires authentication, you can specify details of the authentication mechanisms supported as a (Hash) value here.
|
1720
1720
|
See [https://swagger.io/docs/specification/2-0/authentication/] for details of what values can be specified
|
1721
1721
|
By default, no security is defined.
|
1722
1722
|
|
1723
|
-
``config.
|
1723
|
+
``config.generator.swagger.global_security``
|
1724
1724
|
If the API requires authentication, you can specify which of the authentication mechanisms are supported by all API operations as an Array of hashes here.
|
1725
|
-
This should be used in conjunction with the mechanisms defined by ``
|
1725
|
+
This should be used in conjunction with the mechanisms defined by ``swagger.security_definitions``.
|
1726
1726
|
See [https://swagger.io/docs/specification/2-0/authentication/] for details of what values can be specified
|
1727
1727
|
By default, no security is defined.
|
1728
1728
|
|
@@ -39,12 +39,12 @@ module Apipie
|
|
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)
|
@@ -119,7 +119,7 @@ module Apipie
|
|
119
119
|
authorize_resource(resource)
|
120
120
|
end
|
121
121
|
else
|
122
|
-
@doc[:docs][:resources].select do |
|
122
|
+
@doc[:docs][:resources].select do |_resource_id, resource|
|
123
123
|
authorize_resource(resource)
|
124
124
|
end
|
125
125
|
end
|
@@ -155,7 +155,7 @@ module Apipie
|
|
155
155
|
def render_from_cache
|
156
156
|
path = Apipie.configuration.doc_base_url.dup
|
157
157
|
# some params can contain dot, but only one in row
|
158
|
-
if [:resource, :method, :format, :version].any? { |p| params[p].to_s.gsub(".", "") =~ /\W/ || params[p].to_s
|
158
|
+
if [:resource, :method, :format, :version].any? { |p| params[p].to_s.gsub(".", "") =~ /\W/ || params[p].to_s.include?('..') }
|
159
159
|
head :bad_request and return
|
160
160
|
end
|
161
161
|
|
@@ -171,7 +171,7 @@ module Apipie
|
|
171
171
|
# we sanitize the params before so in ideal case, this condition
|
172
172
|
# will be never satisfied. It's here for cases somebody adds new
|
173
173
|
# param into the path later and forgets about sanitation.
|
174
|
-
if path
|
174
|
+
if path.include?('..')
|
175
175
|
head :bad_request and return
|
176
176
|
end
|
177
177
|
|
data/lib/apipie/apipie_module.rb
CHANGED
@@ -8,14 +8,14 @@ module Apipie
|
|
8
8
|
@application ||= Apipie::Application.new
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.to_json(version = nil,
|
11
|
+
def self.to_json(version = nil, resource_id = nil, method_name = nil, lang = nil)
|
12
12
|
version ||= Apipie.configuration.default_version
|
13
|
-
app.to_json(version,
|
13
|
+
app.to_json(version, resource_id, method_name, lang)
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.to_swagger_json(version = nil,
|
16
|
+
def self.to_swagger_json(version = nil, resource_id = nil, method_name = nil, lang = nil, clear_warnings = true)
|
17
17
|
version ||= Apipie.configuration.default_version
|
18
|
-
app.to_swagger_json(version,
|
18
|
+
app.to_swagger_json(version, resource_id, method_name, lang, clear_warnings)
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.json_schema_for_method_response(controller_name, method_name, return_code, allow_nulls)
|
@@ -24,7 +24,7 @@ module Apipie
|
|
24
24
|
app.json_schema_for_method_response(version, controller_name, method_name, return_code, allow_nulls)
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.json_schema_for_self_describing_class(cls, allow_nulls=true)
|
27
|
+
def self.json_schema_for_self_describing_class(cls, allow_nulls = true)
|
28
28
|
app.json_schema_for_self_describing_class(cls, allow_nulls)
|
29
29
|
end
|
30
30
|
|
data/lib/apipie/application.rb
CHANGED
@@ -25,10 +25,6 @@ module Apipie
|
|
25
25
|
@resource_descriptions.keys.sort
|
26
26
|
end
|
27
27
|
|
28
|
-
def set_resource_id(controller, resource_id)
|
29
|
-
@controller_to_resource_id[controller] = resource_id
|
30
|
-
end
|
31
|
-
|
32
28
|
def rails_routes(route_set = nil, base_url = "")
|
33
29
|
if route_set.nil? && @rails_routes
|
34
30
|
return @rails_routes
|
@@ -83,8 +79,8 @@ module Apipie
|
|
83
79
|
versions = controller_versions(controller) if versions.empty?
|
84
80
|
|
85
81
|
versions.each do |version|
|
86
|
-
|
87
|
-
resource_description = get_resource_description(
|
82
|
+
resource_id_with_version = "#{version}##{get_resource_id(controller)}"
|
83
|
+
resource_description = get_resource_description(resource_id_with_version)
|
88
84
|
|
89
85
|
if resource_description.nil?
|
90
86
|
resource_description = define_resource_description(controller, version)
|
@@ -100,24 +96,24 @@ module Apipie
|
|
100
96
|
resource_description.add_method_description(method_description)
|
101
97
|
end
|
102
98
|
|
103
|
-
|
99
|
+
ret_method_description
|
104
100
|
end
|
105
101
|
|
106
102
|
# create new resource api description
|
107
103
|
def define_resource_description(controller, version, dsl_data = nil)
|
108
104
|
return if ignored?(controller)
|
109
105
|
|
110
|
-
|
111
|
-
resource_description = @resource_descriptions[version][
|
106
|
+
resource_id = get_resource_id(controller)
|
107
|
+
resource_description = @resource_descriptions[version][resource_id]
|
112
108
|
if resource_description
|
113
109
|
# we already defined the description somewhere (probably in
|
114
110
|
# some method. Updating just meta data from dsl
|
115
111
|
resource_description.update_from_dsl_data(dsl_data) if dsl_data
|
116
112
|
else
|
117
|
-
resource_description = Apipie::ResourceDescription.new(controller,
|
113
|
+
resource_description = Apipie::ResourceDescription.new(controller, resource_id, dsl_data, version)
|
118
114
|
|
119
|
-
Apipie.debug("@resource_descriptions[#{version}][#{
|
120
|
-
@resource_descriptions[version][
|
115
|
+
Apipie.debug("@resource_descriptions[#{version}][#{resource_id}] = #{resource_description}")
|
116
|
+
@resource_descriptions[version][resource_id] ||= resource_description
|
121
117
|
end
|
122
118
|
|
123
119
|
return resource_description
|
@@ -158,28 +154,28 @@ module Apipie
|
|
158
154
|
#
|
159
155
|
# There are two ways how this method can be used:
|
160
156
|
# 1) Specify both parameters
|
161
|
-
#
|
157
|
+
# resource_id:
|
162
158
|
# controller class - UsersController
|
163
159
|
# string with resource name (plural) and version - "v1#users"
|
164
160
|
# method_name: name of the method (string or symbol)
|
165
161
|
#
|
166
162
|
# 2) Specify only first parameter:
|
167
|
-
#
|
163
|
+
# resource_id: string containing both resource and method name joined
|
168
164
|
# with '#' symbol.
|
169
165
|
# - "users#create" get default version
|
170
166
|
# - "v2#users#create" get specific version
|
171
|
-
def get_method_description(
|
172
|
-
if
|
173
|
-
crumbs =
|
167
|
+
def get_method_description(resource_id, method_name = nil)
|
168
|
+
if resource_id.is_a?(String)
|
169
|
+
crumbs = resource_id.split('#')
|
174
170
|
if method_name.nil?
|
175
171
|
method_name = crumbs.pop
|
176
172
|
end
|
177
|
-
|
178
|
-
resource_description = get_resource_description(
|
179
|
-
elsif
|
180
|
-
resource_description = get_resource_description(
|
173
|
+
resource_id = crumbs.join("#")
|
174
|
+
resource_description = get_resource_description(resource_id)
|
175
|
+
elsif resource_id.respond_to? :apipie_resource_descriptions
|
176
|
+
resource_description = get_resource_description(resource_id)
|
181
177
|
else
|
182
|
-
raise ArgumentError.new("Resource #{
|
178
|
+
raise ArgumentError.new("Resource #{resource_id} does not exists.")
|
183
179
|
end
|
184
180
|
resource_description&.method_description(method_name.to_sym)
|
185
181
|
end
|
@@ -200,15 +196,15 @@ module Apipie
|
|
200
196
|
return @resource_descriptions[version][crumbs.last]
|
201
197
|
end
|
202
198
|
else
|
203
|
-
|
199
|
+
resource_id = get_resource_id(resource)
|
204
200
|
if version
|
205
|
-
|
201
|
+
resource_id = "#{version}##{resource_id}"
|
206
202
|
end
|
207
203
|
|
208
|
-
if
|
204
|
+
if resource_id.nil?
|
209
205
|
return nil
|
210
206
|
end
|
211
|
-
resource_description = get_resource_description(
|
207
|
+
resource_description = get_resource_description(resource_id)
|
212
208
|
if resource_description && resource_description.controller.to_s == resource.to_s
|
213
209
|
return resource_description
|
214
210
|
end
|
@@ -231,7 +227,7 @@ module Apipie
|
|
231
227
|
|
232
228
|
def remove_method_description(resource, versions, method_name)
|
233
229
|
versions.each do |version|
|
234
|
-
resource =
|
230
|
+
resource = resource_id(resource)
|
235
231
|
if resource_description = get_resource_description("#{version}##{resource}")
|
236
232
|
resource_description.remove_method_description(method_name)
|
237
233
|
end
|
@@ -243,7 +239,6 @@ module Apipie
|
|
243
239
|
@resource_descriptions = ActiveSupport::HashWithIndifferentAccess.new { |h, version| h[version] = {} }
|
244
240
|
@controller_to_resource_id = {}
|
245
241
|
@param_groups = {}
|
246
|
-
@swagger_generator = Apipie::SwaggerGenerator.new(self)
|
247
242
|
|
248
243
|
# what versions does the controller belong in (specified by resource_description)?
|
249
244
|
@controller_versions = Hash.new { |h, controller| h[controller.to_s] = [] }
|
@@ -261,36 +256,41 @@ module Apipie
|
|
261
256
|
def json_schema_for_method_response(version, controller_name, method_name, return_code, allow_nulls)
|
262
257
|
method = @resource_descriptions[version][controller_name].method_description(method_name)
|
263
258
|
raise NoDocumentedMethod.new(controller_name, method_name) if method.nil?
|
264
|
-
|
259
|
+
|
260
|
+
Apipie::SwaggerGenerator
|
261
|
+
.json_schema_for_method_response(method, return_code, allow_nulls)
|
265
262
|
end
|
266
263
|
|
267
264
|
def json_schema_for_self_describing_class(cls, allow_nulls)
|
268
|
-
|
265
|
+
Apipie::SwaggerGenerator
|
266
|
+
.json_schema_for_self_describing_class(cls, allow_nulls)
|
269
267
|
end
|
270
268
|
|
271
|
-
def to_swagger_json(version,
|
272
|
-
return unless valid_search_args?(version,
|
269
|
+
def to_swagger_json(version, resource_id, method_name, language, clear_warnings = false)
|
270
|
+
return unless valid_search_args?(version, resource_id, method_name)
|
273
271
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
end
|
283
|
-
result
|
284
|
-
end
|
272
|
+
resources =
|
273
|
+
Apipie::Generator::Swagger::ResourceDescriptionsCollection
|
274
|
+
.new(resource_descriptions)
|
275
|
+
.filter(
|
276
|
+
resource_id: resource_id,
|
277
|
+
method_name: method_name,
|
278
|
+
version: version
|
279
|
+
)
|
285
280
|
|
286
|
-
|
281
|
+
Apipie::SwaggerGenerator.generate_from_resources(
|
282
|
+
resources,
|
283
|
+
version: version,
|
284
|
+
language: language,
|
285
|
+
clear_warnings: clear_warnings
|
286
|
+
)
|
287
287
|
end
|
288
288
|
|
289
|
-
def to_json(version,
|
289
|
+
def to_json(version, resource_id, method_name, lang)
|
290
290
|
|
291
|
-
return unless valid_search_args?(version,
|
291
|
+
return unless valid_search_args?(version, resource_id, method_name)
|
292
292
|
|
293
|
-
_resources = if
|
293
|
+
_resources = if resource_id.blank?
|
294
294
|
# take just resources which have some methods because
|
295
295
|
# we dont want to show eg ApplicationController as resource
|
296
296
|
resource_descriptions[version].inject({}) do |result, (k,v)|
|
@@ -298,7 +298,7 @@ module Apipie
|
|
298
298
|
result
|
299
299
|
end
|
300
300
|
else
|
301
|
-
[@resource_descriptions[version][
|
301
|
+
[@resource_descriptions[version][resource_id].to_json(method_name, lang)]
|
302
302
|
end
|
303
303
|
|
304
304
|
url_args = Apipie.configuration.version_in_url ? version : ''
|
@@ -368,15 +368,41 @@ module Apipie
|
|
368
368
|
Apipie.configuration.validate? || ! Apipie.configuration.use_cache? || Apipie.configuration.force_dsl?
|
369
369
|
end
|
370
370
|
|
371
|
+
# @deprecated Use {#get_resource_id} instead
|
371
372
|
def get_resource_name(klass)
|
373
|
+
ActiveSupport::Deprecation.warn(
|
374
|
+
<<~HEREDOC
|
375
|
+
Apipie::Application.get_resource_name is deprecated.
|
376
|
+
Use `Apipie::Application.get_resource_id instead.
|
377
|
+
HEREDOC
|
378
|
+
)
|
379
|
+
|
380
|
+
get_resource_id(klass)
|
381
|
+
end
|
382
|
+
|
383
|
+
def set_resource_id(controller, resource_id)
|
384
|
+
@controller_to_resource_id[controller] = resource_id
|
385
|
+
end
|
386
|
+
|
387
|
+
def get_resource_id(klass)
|
372
388
|
if klass.class == String
|
373
389
|
klass
|
374
390
|
elsif @controller_to_resource_id.key?(klass)
|
375
391
|
@controller_to_resource_id[klass]
|
376
392
|
elsif Apipie.configuration.namespaced_resources? && klass.respond_to?(:controller_path)
|
377
393
|
return nil if klass == ActionController::Base
|
394
|
+
|
395
|
+
version_prefix = version_prefix(klass)
|
378
396
|
path = klass.controller_path
|
379
|
-
|
397
|
+
|
398
|
+
path =
|
399
|
+
if version_prefix == '/'
|
400
|
+
path
|
401
|
+
else
|
402
|
+
path.gsub(version_prefix, '')
|
403
|
+
end
|
404
|
+
|
405
|
+
path.gsub('/', '-')
|
380
406
|
elsif klass.respond_to?(:controller_name)
|
381
407
|
return nil if klass == ActionController::Base
|
382
408
|
klass.controller_name
|
@@ -403,14 +429,14 @@ module Apipie
|
|
403
429
|
|
404
430
|
private
|
405
431
|
|
406
|
-
# Make sure that the version/
|
407
|
-
#
|
408
|
-
def valid_search_args?(version,
|
432
|
+
# Make sure that the version/resource_id/method_name are valid combination
|
433
|
+
# resource_id and method_name can be nil
|
434
|
+
def valid_search_args?(version, resource_id, method_name)
|
409
435
|
return false unless self.resource_descriptions.key?(version)
|
410
|
-
if
|
411
|
-
return false unless self.resource_descriptions[version].key?(
|
436
|
+
if resource_id
|
437
|
+
return false unless self.resource_descriptions[version].key?(resource_id)
|
412
438
|
if method_name
|
413
|
-
resource_description = self.resource_descriptions[version][
|
439
|
+
resource_description = self.resource_descriptions[version][resource_id]
|
414
440
|
return false unless resource_description.valid_method_name?(method_name)
|
415
441
|
end
|
416
442
|
end
|
data/lib/apipie/configuration.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Apipie
|
2
2
|
class Configuration
|
3
|
+
extend Forwardable
|
3
4
|
|
4
5
|
attr_accessor :app_name, :app_info, :copyright, :compress_examples,
|
5
6
|
:markup, :disqus_shortname,
|
@@ -8,19 +9,21 @@ module Apipie
|
|
8
9
|
:validate, :validate_value, :validate_presence, :validate_key, :action_on_non_validated_keys, :authenticate, :doc_path,
|
9
10
|
:show_all_examples, :process_params, :update_checksum, :checksum_path,
|
10
11
|
:link_extension, :record, :languages, :translate, :locale, :default_locale,
|
11
|
-
:persist_show_in_doc, :authorize, :ignore_allow_blank_false
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
:persist_show_in_doc, :authorize, :ignore_allow_blank_false
|
13
|
+
|
14
|
+
def_delegators :swagger, *Apipie::Generator::Swagger::Config.deprecated_methods
|
15
|
+
|
16
|
+
def swagger
|
17
|
+
Apipie::Generator::Swagger::Config.instance
|
18
|
+
end
|
19
|
+
|
20
|
+
def generator
|
21
|
+
Apipie::Generator::Config.instance
|
22
|
+
end
|
16
23
|
|
17
24
|
alias validate? validate
|
18
25
|
alias required_by_default? required_by_default
|
19
26
|
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
27
|
|
25
28
|
# matcher to be used in Dir.glob to find controllers to be reloaded e.g.
|
26
29
|
#
|
@@ -55,21 +58,22 @@ module Apipie
|
|
55
58
|
|
56
59
|
def reload_controllers?
|
57
60
|
@reload_controllers = Rails.env.development? unless defined? @reload_controllers
|
58
|
-
|
61
|
+
|
62
|
+
@reload_controllers && @api_controllers_matcher
|
59
63
|
end
|
60
64
|
|
61
65
|
def validate_value
|
62
|
-
|
66
|
+
validate? && @validate_value
|
63
67
|
end
|
64
68
|
alias validate_value? validate_value
|
65
69
|
|
66
70
|
def validate_presence
|
67
|
-
|
71
|
+
validate? && @validate_presence
|
68
72
|
end
|
69
73
|
alias validate_presence? validate_presence
|
70
74
|
|
71
75
|
def validate_key
|
72
|
-
|
76
|
+
validate? && @validate_key
|
73
77
|
end
|
74
78
|
alias validate_key? validate_key
|
75
79
|
|
@@ -77,7 +81,7 @@ module Apipie
|
|
77
81
|
@process_params
|
78
82
|
end
|
79
83
|
# set to true if you want to use pregenerated documentation cache and avoid
|
80
|
-
# generating the documentation on runtime (
|
84
|
+
# generating the documentation on runtime (useful for production
|
81
85
|
# environment).
|
82
86
|
# You can generate the cache by running
|
83
87
|
#
|
@@ -109,7 +113,7 @@ module Apipie
|
|
109
113
|
end
|
110
114
|
|
111
115
|
# array of controller names (strings) (might include actions as well)
|
112
|
-
# to be ignored # when
|
116
|
+
# to be ignored # when generating the documentation
|
113
117
|
# e.g. %w[Api::CommentsController Api::PostsController#post]
|
114
118
|
attr_writer :ignored
|
115
119
|
def ignored
|
@@ -187,17 +191,6 @@ module Apipie
|
|
187
191
|
@translate = lambda { |str, locale| str }
|
188
192
|
@persist_show_in_doc = false
|
189
193
|
@routes_formatter = RoutesFormatter.new
|
190
|
-
@swagger_content_type_input = :form_data # this can be :json or :form_data
|
191
|
-
@swagger_json_input_uses_refs = false
|
192
|
-
@swagger_include_warning_tags = false
|
193
|
-
@swagger_suppress_warnings = false #[105,100,102]
|
194
|
-
@swagger_api_host = "localhost:3000"
|
195
|
-
@swagger_generate_x_computed_id_field = false
|
196
|
-
@swagger_allow_additional_properties_in_response = false
|
197
|
-
@swagger_responses_use_refs = true
|
198
|
-
@swagger_schemes = [:https]
|
199
|
-
@swagger_security_definitions = {}
|
200
|
-
@swagger_global_security = []
|
201
194
|
end
|
202
195
|
end
|
203
196
|
end
|
@@ -51,9 +51,6 @@ module Apipie
|
|
51
51
|
end
|
52
52
|
|
53
53
|
module Resource
|
54
|
-
# by default, the resource id is derived from controller_name
|
55
|
-
# it can be overwritten with.
|
56
|
-
#
|
57
54
|
# resource_id "my_own_resource_id"
|
58
55
|
def resource_id(resource_id)
|
59
56
|
Apipie.set_resource_id(@controller, resource_id)
|
@@ -96,7 +93,7 @@ module Apipie
|
|
96
93
|
# # load paths from routes and don't provide description
|
97
94
|
# api
|
98
95
|
#
|
99
|
-
def api(method, path, desc = nil, options={}) #:doc:
|
96
|
+
def api(method, path, desc = nil, options = {}) #:doc:
|
100
97
|
return unless Apipie.active_dsl?
|
101
98
|
_apipie_dsl_data[:api] = true
|
102
99
|
_apipie_dsl_data[:api_args] << [method, path, desc, options]
|
@@ -105,7 +102,7 @@ module Apipie
|
|
105
102
|
# # load paths from routes
|
106
103
|
# api! "short description",
|
107
104
|
#
|
108
|
-
def api!(desc = nil, options={}) #:doc:
|
105
|
+
def api!(desc = nil, options = {}) #:doc:
|
109
106
|
return unless Apipie.active_dsl?
|
110
107
|
_apipie_dsl_data[:api] = true
|
111
108
|
_apipie_dsl_data[:api_from_routes] = { :desc => desc, :options =>options }
|
@@ -218,7 +215,7 @@ module Apipie
|
|
218
215
|
# puts "hello world"
|
219
216
|
# end
|
220
217
|
#
|
221
|
-
def error(code_or_options, desc=nil, options={}) #:doc:
|
218
|
+
def error(code_or_options, desc = nil, options = {}) #:doc:
|
222
219
|
return unless Apipie.active_dsl?
|
223
220
|
_apipie_dsl_data[:errors] << [code_or_options, desc, options]
|
224
221
|
end
|
@@ -403,7 +400,7 @@ module Apipie
|
|
403
400
|
# render json: {user: {name: "Alfred"}}
|
404
401
|
# end
|
405
402
|
#
|
406
|
-
def returns(pgroup_or_options, desc_or_options=nil, options={}, &block) #:doc:
|
403
|
+
def returns(pgroup_or_options, desc_or_options = nil, options = {}, &block) #:doc:
|
407
404
|
return unless Apipie.active_dsl?
|
408
405
|
|
409
406
|
|
@@ -529,8 +526,10 @@ module Apipie
|
|
529
526
|
alias apipie_update_params apipie_update_methods
|
530
527
|
|
531
528
|
def _apipie_concern_subst
|
532
|
-
@_apipie_concern_subst ||= {
|
533
|
-
|
529
|
+
@_apipie_concern_subst ||= {
|
530
|
+
controller_path: self.controller_path,
|
531
|
+
resource_id: Apipie.get_resource_id(self)
|
532
|
+
}
|
534
533
|
end
|
535
534
|
|
536
535
|
def _apipie_perform_concern_subst(string)
|