apipie-rails-jq 1.4.3.pre.beta.pre.jq.1
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 +7 -0
- data/.github/workflows/build.yml +32 -0
- data/.github/workflows/rubocop-challenger.yml +26 -0
- data/.github/workflows/rubocop.yml +18 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.rubocop.yml +132 -0
- data/.rubocop_todo.yml +1967 -0
- data/.vscode/settings.json +3 -0
- data/APACHE-LICENSE-2.0 +202 -0
- data/CHANGELOG.md +693 -0
- data/Gemfile +19 -0
- data/MIT-LICENSE +20 -0
- data/NOTICE +4 -0
- data/PROPOSAL_FOR_RESPONSE_DESCRIPTIONS.md +244 -0
- data/README.md +2088 -0
- data/Rakefile +8 -0
- data/apipie-rails.gemspec +44 -0
- data/app/controllers/apipie/apipies_controller.rb +184 -0
- data/app/helpers/apipie_helper.rb +10 -0
- data/app/public/apipie/javascripts/apipie.js +6 -0
- data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +167 -0
- data/app/public/apipie/javascripts/bundled/bootstrap.js +2280 -0
- data/app/public/apipie/javascripts/bundled/jquery.js +2 -0
- data/app/public/apipie/javascripts/bundled/prettify.js +28 -0
- data/app/public/apipie/stylesheets/application.css +7 -0
- data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -0
- data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -0
- data/app/public/apipie/stylesheets/bundled/prettify.css +30 -0
- data/app/views/apipie/apipies/_deprecation.html.erb +16 -0
- data/app/views/apipie/apipies/_disqus.html.erb +13 -0
- data/app/views/apipie/apipies/_errors.html.erb +23 -0
- data/app/views/apipie/apipies/_headers.html.erb +26 -0
- data/app/views/apipie/apipies/_languages.erb +6 -0
- data/app/views/apipie/apipies/_metadata.erb +1 -0
- data/app/views/apipie/apipies/_method_detail.erb +63 -0
- data/app/views/apipie/apipies/_params.html.erb +49 -0
- data/app/views/apipie/apipies/_params_plain.html.erb +21 -0
- data/app/views/apipie/apipies/apipie_404.html.erb +17 -0
- data/app/views/apipie/apipies/apipie_checksum.json.erb +1 -0
- data/app/views/apipie/apipies/getting_started.html.erb +6 -0
- data/app/views/apipie/apipies/index.html.erb +56 -0
- data/app/views/apipie/apipies/method.html.erb +41 -0
- data/app/views/apipie/apipies/plain.html.erb +77 -0
- data/app/views/apipie/apipies/resource.html.erb +80 -0
- data/app/views/apipie/apipies/static.html.erb +103 -0
- data/app/views/layouts/apipie/apipie.html.erb +27 -0
- data/config/locales/de.yml +28 -0
- data/config/locales/en.yml +41 -0
- data/config/locales/es.yml +28 -0
- data/config/locales/fr.yml +31 -0
- data/config/locales/it.yml +41 -0
- data/config/locales/ja.yml +31 -0
- data/config/locales/ko.yml +32 -0
- data/config/locales/pl.yml +28 -0
- data/config/locales/pt-BR.yml +28 -0
- data/config/locales/ru.yml +28 -0
- data/config/locales/tr.yml +28 -0
- data/config/locales/zh-CN.yml +28 -0
- data/config/locales/zh-TW.yml +28 -0
- data/gemfiles/Gemfile.tools +9 -0
- data/images/screenshot-1.png +0 -0
- data/images/screenshot-2.png +0 -0
- data/lib/apipie/apipie_module.rb +83 -0
- data/lib/apipie/application.rb +499 -0
- data/lib/apipie/configuration.rb +196 -0
- data/lib/apipie/core_ext/route.rb +9 -0
- data/lib/apipie/dsl_definition.rb +630 -0
- data/lib/apipie/error_description.rb +46 -0
- data/lib/apipie/errors.rb +86 -0
- data/lib/apipie/extractor/collector.rb +116 -0
- data/lib/apipie/extractor/recorder.rb +193 -0
- data/lib/apipie/extractor/writer.rb +454 -0
- data/lib/apipie/extractor.rb +181 -0
- 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 +71 -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 +132 -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 +73 -0
- data/lib/apipie/markup.rb +52 -0
- 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 +230 -0
- data/lib/apipie/middleware/checksum_in_headers.rb +35 -0
- data/lib/apipie/param_description/deprecation.rb +24 -0
- data/lib/apipie/param_description.rb +313 -0
- data/lib/apipie/railtie.rb +9 -0
- data/lib/apipie/resource_description.rb +152 -0
- data/lib/apipie/response_description.rb +157 -0
- data/lib/apipie/response_description_adapter.rb +202 -0
- data/lib/apipie/routes_formatter.rb +33 -0
- data/lib/apipie/routing.rb +16 -0
- data/lib/apipie/rspec/response_validation_helper.rb +194 -0
- data/lib/apipie/see_description.rb +39 -0
- data/lib/apipie/static_dispatcher.rb +75 -0
- data/lib/apipie/swagger_generator.rb +45 -0
- data/lib/apipie/tag_list_description.rb +11 -0
- data/lib/apipie/validator.rb +552 -0
- data/lib/apipie/version.rb +3 -0
- data/lib/apipie-rails.rb +60 -0
- data/lib/generators/apipie/install/README +6 -0
- data/lib/generators/apipie/install/install_generator.rb +25 -0
- data/lib/generators/apipie/install/templates/initializer.rb.erb +7 -0
- data/lib/generators/apipie/views_generator.rb +11 -0
- data/lib/tasks/apipie.rake +355 -0
- data/rel-eng/gem_release.ipynb +398 -0
- data/rel-eng/packages/.readme +3 -0
- data/rel-eng/packages/rubygem-apipie-rails +1 -0
- data/rel-eng/tito.props +5 -0
- data/spec/controllers/api/v1/architectures_controller_spec.rb +29 -0
- data/spec/controllers/api/v2/architectures_controller_spec.rb +19 -0
- data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +27 -0
- data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
- data/spec/controllers/concerns_controller_spec.rb +42 -0
- data/spec/controllers/extended_controller_spec.rb +14 -0
- data/spec/controllers/included_param_group_controller_spec.rb +13 -0
- data/spec/controllers/pets_controller_spec.rb +98 -0
- data/spec/controllers/users_controller_spec.rb +794 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/api/base_controller.rb +4 -0
- data/spec/dummy/app/controllers/api/v1/architectures_controller.rb +43 -0
- data/spec/dummy/app/controllers/api/v1/base_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +31 -0
- data/spec/dummy/app/controllers/api/v2/base_controller.rb +17 -0
- data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
- data/spec/dummy/app/controllers/api/v2/nested/architectures_controller.rb +32 -0
- data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +33 -0
- data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
- data/spec/dummy/app/controllers/application_controller.rb +18 -0
- data/spec/dummy/app/controllers/concerns_controller.rb +8 -0
- data/spec/dummy/app/controllers/extended_controller.rb +14 -0
- data/spec/dummy/app/controllers/extending_concern.rb +10 -0
- data/spec/dummy/app/controllers/files_controller.rb +5 -0
- data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
- data/spec/dummy/app/controllers/overridden_concerns_controller.rb +31 -0
- data/spec/dummy/app/controllers/pets_controller.rb +408 -0
- data/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +73 -0
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +95 -0
- data/spec/dummy/app/controllers/sample_controller.rb +39 -0
- data/spec/dummy/app/controllers/tagged_cats_controller.rb +32 -0
- data/spec/dummy/app/controllers/tagged_dogs_controller.rb +15 -0
- data/spec/dummy/app/controllers/twitter_example_controller.rb +307 -0
- data/spec/dummy/app/controllers/users_controller.rb +310 -0
- data/spec/dummy/app/helpers/random_param_group.rb +8 -0
- data/spec/dummy/app/views/layouts/application.html.erb +21 -0
- data/spec/dummy/components/test_engine/Gemfile +6 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/application_controller.rb +4 -0
- data/spec/dummy/components/test_engine/app/controllers/test_engine/memes_controller.rb +37 -0
- data/spec/dummy/components/test_engine/config/routes.rb +3 -0
- data/spec/dummy/components/test_engine/db/.gitkeep +0 -0
- data/spec/dummy/components/test_engine/lib/test_engine.rb +7 -0
- data/spec/dummy/components/test_engine/test_engine.gemspec +11 -0
- data/spec/dummy/config/application.rb +47 -0
- data/spec/dummy/config/boot.rb +12 -0
- data/spec/dummy/config/database.yml +21 -0
- data/spec/dummy/config/environment.rb +8 -0
- data/spec/dummy/config/environments/development.rb +25 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +33 -0
- data/spec/dummy/config/initializers/apipie.rb +110 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +8 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +61 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/.gitkeep +0 -0
- data/spec/dummy/doc/apipie_examples.json +1 -0
- data/spec/dummy/doc/users/desc_from_file.md +1 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/lib/apipie/apipies_controller_spec.rb +345 -0
- 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/middleware_spec.rb +44 -0
- data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
- data/spec/lib/apipie/extractor/writer_spec.rb +112 -0
- data/spec/lib/apipie/extractor_spec.rb +9 -0
- data/spec/lib/apipie/file_handler_spec.rb +25 -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/method_description/response_service_spec.rb +62 -0
- data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +245 -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 +210 -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/apipie/param_description_spec.rb +671 -0
- data/spec/lib/apipie/param_group_spec.rb +61 -0
- data/spec/lib/apipie/resource_description_spec.rb +91 -0
- data/spec/lib/apipie/response_description/response_object_spec.rb +22 -0
- data/spec/lib/apipie/response_description_spec.rb +56 -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/apipie/validator_spec.rb +149 -0
- data/spec/lib/rake_spec.rb +69 -0
- data/spec/lib/swagger/openapi_2_0_schema.json +1614 -0
- data/spec/lib/swagger/rake_swagger_spec.rb +159 -0
- data/spec/lib/swagger/swagger_dsl_spec.rb +664 -0
- data/spec/lib/validators/array_validator_spec.rb +85 -0
- data/spec/spec_helper.rb +92 -0
- data/spec/support/custom_bool_validator.rb +17 -0
- data/spec/support/rake.rb +21 -0
- data/spec/test_engine/memes_controller_spec.rb +10 -0
- metadata +499 -0
@@ -0,0 +1,345 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require "json-schema"
|
4
|
+
|
5
|
+
describe Apipie::ApipiesController, type: :controller do
|
6
|
+
|
7
|
+
describe "GET index" do
|
8
|
+
|
9
|
+
it "succeeds on index" do
|
10
|
+
get :index
|
11
|
+
|
12
|
+
assert_response :success
|
13
|
+
end
|
14
|
+
|
15
|
+
it "succeeds on version details" do
|
16
|
+
get :index, :params => { :version => "2.0" }
|
17
|
+
|
18
|
+
assert_response :success
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns not_found on wrong version" do
|
22
|
+
get :index, :params => { :version => "wrong_version" }
|
23
|
+
|
24
|
+
assert_response :not_found
|
25
|
+
end
|
26
|
+
|
27
|
+
it "succeeds on resource details" do
|
28
|
+
get :index, :params => { :version => "2.0", :resource => "architectures" }
|
29
|
+
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns not_found on wrong resource" do
|
34
|
+
get :index, :params => { :version => "2.0", :resource => "wrong_resource" }
|
35
|
+
|
36
|
+
assert_response :not_found
|
37
|
+
end
|
38
|
+
|
39
|
+
it "succeeds on method details" do
|
40
|
+
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index" }
|
41
|
+
|
42
|
+
assert_response :success
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns not_found on wrong method" do
|
46
|
+
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "wrong_method" }
|
47
|
+
|
48
|
+
assert_response :not_found
|
49
|
+
end
|
50
|
+
|
51
|
+
it "succeeds on method details with a supported language" do
|
52
|
+
allow(Apipie.configuration).to receive(:languages).and_return(%w[en es])
|
53
|
+
|
54
|
+
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.es" }
|
55
|
+
|
56
|
+
assert_response :success
|
57
|
+
end
|
58
|
+
|
59
|
+
it "succeeds on method details with the default language" do
|
60
|
+
allow(Apipie.configuration).to receive_messages(default_locale: "en", languages: [])
|
61
|
+
|
62
|
+
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.en" }
|
63
|
+
|
64
|
+
assert_response :success
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns not_found on a method with an unsupported language" do
|
68
|
+
allow(Apipie.configuration).to receive(:languages).and_return(%w[en es])
|
69
|
+
|
70
|
+
get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index.jp" }
|
71
|
+
|
72
|
+
assert_response :not_found
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "reload_controllers" do
|
77
|
+
|
78
|
+
RSpec::Matchers.define :reload_documentation do
|
79
|
+
match do |actual|
|
80
|
+
expect(Apipie).to receive(:reload_documentation)
|
81
|
+
get :index
|
82
|
+
end
|
83
|
+
|
84
|
+
match_when_negated do |actual|
|
85
|
+
expect(Apipie).not_to receive(:reload_documentation)
|
86
|
+
get :index
|
87
|
+
end
|
88
|
+
|
89
|
+
failure_message { "the documentation expected to be reloaded but it was not" }
|
90
|
+
failure_message_when_negated { "the documentation expected not to be reloaded but it was" }
|
91
|
+
end
|
92
|
+
|
93
|
+
before do
|
94
|
+
Apipie.configuration.api_controllers_matcher = File.join(Rails.root, "app", "controllers", "**","*.rb")
|
95
|
+
if Apipie.configuration.send :instance_variable_defined?, "@reload_controllers"
|
96
|
+
Apipie.configuration.send :remove_instance_variable, "@reload_controllers"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "it's not specified explicitly" do
|
101
|
+
context "and it's in development environment" do
|
102
|
+
before do
|
103
|
+
allow(Rails).to receive_messages(:env => double(:development? => true))
|
104
|
+
end
|
105
|
+
it { is_expected.to reload_documentation }
|
106
|
+
end
|
107
|
+
|
108
|
+
context "and it's not development environment" do
|
109
|
+
it { is_expected.not_to reload_documentation }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
context "it's explicitly enabled" do
|
115
|
+
before do
|
116
|
+
Apipie.configuration.reload_controllers = true
|
117
|
+
end
|
118
|
+
|
119
|
+
context "and it's in development environment" do
|
120
|
+
before do
|
121
|
+
allow(Rails).to receive_messages(:env => double(:development? => true))
|
122
|
+
end
|
123
|
+
it { is_expected.to reload_documentation }
|
124
|
+
end
|
125
|
+
|
126
|
+
context "and it's not development environment" do
|
127
|
+
it { is_expected.to reload_documentation }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "it's explicitly enabled" do
|
132
|
+
before do
|
133
|
+
Apipie.configuration.reload_controllers = false
|
134
|
+
end
|
135
|
+
|
136
|
+
context "and it's in development environment" do
|
137
|
+
before do
|
138
|
+
allow(Rails).to receive_messages(:env => double(:development? => true))
|
139
|
+
end
|
140
|
+
it { is_expected.not_to reload_documentation }
|
141
|
+
end
|
142
|
+
|
143
|
+
context "and it's not development environment" do
|
144
|
+
it { is_expected.not_to reload_documentation }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "api_controllers_matcher is specified" do
|
149
|
+
before do
|
150
|
+
Apipie.configuration.reload_controllers = true
|
151
|
+
Apipie.configuration.api_controllers_matcher = nil
|
152
|
+
end
|
153
|
+
|
154
|
+
it { is_expected.not_to reload_documentation }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "GET index as swagger" do
|
159
|
+
|
160
|
+
let(:swagger_schema) do
|
161
|
+
File.read("#{Rails.root.parent}/lib/swagger/openapi_2_0_schema.json")
|
162
|
+
end
|
163
|
+
|
164
|
+
it "outputs swagger when format is json and type is swagger" do
|
165
|
+
get :index, :params => { :format => "json", :type => "swagger"}
|
166
|
+
|
167
|
+
assert_response :success
|
168
|
+
expect(response.body).to match(/"swagger":"2.0"/)
|
169
|
+
# puts response.body
|
170
|
+
|
171
|
+
expect(JSON::Validator.validate(swagger_schema, response.body)).to be_truthy
|
172
|
+
end
|
173
|
+
|
174
|
+
it "does not output swagger when format is not json even if type is swagger" do
|
175
|
+
get :index, :params => { :type => "swagger"}
|
176
|
+
|
177
|
+
assert_response :success
|
178
|
+
expect(response.body).not_to match(/"swagger":"2.0"/)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "does not output swagger when format is json even but type is not swagger" do
|
182
|
+
get :index, :params => { :format => "json"}
|
183
|
+
|
184
|
+
assert_response :success
|
185
|
+
expect(response.body).not_to match(/"swagger":"2.0"/)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
describe "authenticate user" do
|
191
|
+
it "authenticate user if an authentication method is set" do
|
192
|
+
test = false
|
193
|
+
Apipie.configuration.authenticate = Proc.new do
|
194
|
+
test = true
|
195
|
+
end
|
196
|
+
get :index
|
197
|
+
expect(test).to eq(true)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "authorize document" do
|
202
|
+
it "if an authroize method is set" do
|
203
|
+
test = false
|
204
|
+
Apipie.configuration.authorize = Proc.new do |controller, method, doc|
|
205
|
+
test = true
|
206
|
+
true
|
207
|
+
end
|
208
|
+
get :index
|
209
|
+
expect(test).to eq(true)
|
210
|
+
end
|
211
|
+
|
212
|
+
it "remove all resources" do
|
213
|
+
Apipie.configuration.authorize = Proc.new do |&args|
|
214
|
+
false
|
215
|
+
end
|
216
|
+
get :index
|
217
|
+
expect(assigns(:doc)[:resources]).to eq({})
|
218
|
+
end
|
219
|
+
|
220
|
+
it "remove all methods" do
|
221
|
+
Apipie.configuration.authorize = Proc.new do |controller, method, doc|
|
222
|
+
!method
|
223
|
+
end
|
224
|
+
get :index
|
225
|
+
expect(assigns(:doc)[:resources]["concern_resources"][:methods]).to eq([])
|
226
|
+
expect(assigns(:doc)[:resources]["twitter_example"][:methods]).to eq([])
|
227
|
+
expect(assigns(:doc)[:resources]["users"][:methods]).to eq([])
|
228
|
+
end
|
229
|
+
|
230
|
+
it "remove specific method" do
|
231
|
+
Apipie.configuration.authorize = nil
|
232
|
+
get :index
|
233
|
+
|
234
|
+
users_methods = assigns(:doc)[:resources]["users"][:methods].size
|
235
|
+
twitter_example_methods = assigns(:doc)[:resources]["twitter_example"][:methods].size
|
236
|
+
|
237
|
+
Apipie.configuration.authorize = Proc.new do |controller, method, doc|
|
238
|
+
controller == "users" ? method != "index" : true
|
239
|
+
end
|
240
|
+
|
241
|
+
get :index
|
242
|
+
|
243
|
+
expect(assigns(:doc)[:resources]["users"][:methods].size).to eq(users_methods - 1)
|
244
|
+
expect(assigns(:doc)[:resources]["twitter_example"][:methods].size).to eq(twitter_example_methods)
|
245
|
+
end
|
246
|
+
|
247
|
+
it "does not allow access to swagger when authorization is set" do
|
248
|
+
get :index, :params => { :format => "json", :type => "swagger"}
|
249
|
+
|
250
|
+
assert_response :forbidden
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "documentation cache" do
|
255
|
+
|
256
|
+
let(:cache_dir) { File.join(Rails.root, "tmp", "apipie-cache") }
|
257
|
+
|
258
|
+
before do
|
259
|
+
FileUtils.rm_r(cache_dir) if File.exist?(cache_dir)
|
260
|
+
FileUtils.mkdir_p(File.join(cache_dir, "apidoc", "v1", "resource-with-namespace"))
|
261
|
+
File.open(File.join(cache_dir, "apidoc", "v1.html"), "w") { |f| f << "apidoc.html cache v1" }
|
262
|
+
File.open(File.join(cache_dir, "apidoc", "v2.html"), "w") { |f| f << "apidoc.html cache v2" }
|
263
|
+
File.open(File.join(cache_dir, "apidoc", "v1.json"), "w") { |f| f << "apidoc.json cache" }
|
264
|
+
File.open(File.join(cache_dir, "apidoc", "v1", "resource-with-namespace.html"), "w") { |f| f << "resource-with-namespace.html cache" }
|
265
|
+
File.open(File.join(cache_dir, "apidoc", "v1", "resource-with-namespace", "method.html"), "w") { |f| f << "method.html cache" }
|
266
|
+
|
267
|
+
Apipie.configuration.use_cache = true
|
268
|
+
@orig_cache_dir = Apipie.configuration.cache_dir
|
269
|
+
Apipie.configuration.cache_dir = cache_dir
|
270
|
+
@orig_version = Apipie.configuration.default_version
|
271
|
+
Apipie.configuration.default_version = 'v1'
|
272
|
+
end
|
273
|
+
|
274
|
+
after do
|
275
|
+
Apipie.configuration.use_cache = false
|
276
|
+
Apipie.configuration.default_version = @orig_version
|
277
|
+
Apipie.configuration.cache_dir = @orig_cache_dir
|
278
|
+
# FileUtils.rm_r(cache_dir) if File.exist?(cache_dir)
|
279
|
+
end
|
280
|
+
|
281
|
+
context 'when the file exists' do
|
282
|
+
it "uses the file in cache dir instead of generating the content on runtime" do
|
283
|
+
get :index
|
284
|
+
expect(response.body).to eq("apidoc.html cache v1")
|
285
|
+
|
286
|
+
get :index, :params => { :version => 'v1' }
|
287
|
+
expect(response.body).to eq("apidoc.html cache v1")
|
288
|
+
|
289
|
+
get :index, :params => { :version => 'v2' }
|
290
|
+
expect(response.body).to eq("apidoc.html cache v2")
|
291
|
+
|
292
|
+
get :index, :params => { :version => 'v1', :format => "html" }
|
293
|
+
expect(response.body).to eq("apidoc.html cache v1")
|
294
|
+
|
295
|
+
get :index, :params => { :version => 'v1', :format => "json" }
|
296
|
+
expect(response.body).to eq("apidoc.json cache")
|
297
|
+
|
298
|
+
get :index, :params => { :version => 'v1', :format => "html", :resource => "resource-with-namespace" }
|
299
|
+
expect(response.body).to eq("resource-with-namespace.html cache")
|
300
|
+
|
301
|
+
get :index, :params => { :version => 'v1', :format => "html", :resource => "resource-with-namespace", :method => "method" }
|
302
|
+
expect(response.body).to eq("method.html cache")
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context 'when the file does not exist' do
|
307
|
+
it 'returns a not found' do
|
308
|
+
get :index, :params => { :version => 'v3-does-not-exist' }
|
309
|
+
expect(response).to have_http_status(:not_found)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
context 'preventing path traversal' do
|
314
|
+
context 'when resource contains ..' do
|
315
|
+
it "returns a not found" do
|
316
|
+
get :index, :params => { :version => 'v1', :format => "html", :resource => "../resource-with-namespace", :method => "method" }
|
317
|
+
expect(response).to have_http_status(:not_found)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
context 'when method contains ..' do
|
322
|
+
it "returns a not found" do
|
323
|
+
get :index, :params => { :version => 'v1', :format => "html", :resource => "resource-with-namespace", :method => "../method" }
|
324
|
+
expect(response).to have_http_status(:not_found)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
context 'when version contains ..' do
|
329
|
+
it "returns a not found" do
|
330
|
+
get :index, :params => { :version => '../v1', :format => "html", :resource => "resource-with-namespace", :method => "method" }
|
331
|
+
expect(response).to have_http_status(:not_found)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
context 'when format contains ..' do
|
336
|
+
it "returns a not found" do
|
337
|
+
get :index, :params => { :version => 'v1', :format => "../html", :resource => "resource-with-namespace", :method => "method" }
|
338
|
+
expect(response).to have_http_status(:not_found)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::Application do
|
4
|
+
|
5
|
+
describe "api_controllers_paths" do
|
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
|
10
|
+
|
11
|
+
it "supports receiving array as parameter" do
|
12
|
+
expect { Apipie.api_controllers_paths}.
|
13
|
+
not_to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
shared_examples 'resource id' do
|
20
|
+
let(:resource_class) { Api::V2::Nested::ArchitecturesController }
|
21
|
+
let(:base_url) { '/some-api' }
|
22
|
+
|
23
|
+
before { allow(described_class).to receive(:get_base_url).and_return(base_url) }
|
24
|
+
|
25
|
+
context "with namespaced_resources enabled" do
|
26
|
+
before { Apipie.configuration.namespaced_resources = true }
|
27
|
+
after { Apipie.configuration.namespaced_resources = false }
|
28
|
+
|
29
|
+
it "returns the namespaces" do
|
30
|
+
is_expected.to eq('api-v2-nested-architectures')
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with an undefined base url" do
|
34
|
+
let(:base_url) { nil }
|
35
|
+
|
36
|
+
it "does not raise an error" do
|
37
|
+
expect { method_call }.not_to raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with namespaced_resources disabled" do
|
43
|
+
before { Apipie.configuration.namespaced_resources = false }
|
44
|
+
|
45
|
+
it "returns the controller name" do
|
46
|
+
is_expected.to eq('architectures')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.get_resource_id' do
|
52
|
+
subject(:method_call) { Apipie.get_resource_id(resource_class) }
|
53
|
+
|
54
|
+
it_behaves_like 'resource id'
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.get_resource_name' do
|
58
|
+
subject(:method_call) { Apipie.get_resource_name(resource_class) }
|
59
|
+
|
60
|
+
it_behaves_like 'resource id'
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
|
24
|
+
describe 'generator configuration' do
|
25
|
+
let(:generator_config) { configuration.generator }
|
26
|
+
|
27
|
+
describe '#swagger' do
|
28
|
+
subject(:setter) { generator_config.swagger.include_warning_tags = true }
|
29
|
+
|
30
|
+
it 'assigns the correct value' do
|
31
|
+
expect { setter }
|
32
|
+
.to change(configuration.generator.swagger, :include_warning_tags?)
|
33
|
+
.from(false)
|
34
|
+
.to(true)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Apipie::Extractor::Collector do
|
6
|
+
let(:recorder) { described_class.new }
|
7
|
+
|
8
|
+
describe '#ignore_call?' do
|
9
|
+
subject { recorder.ignore_call?(record) }
|
10
|
+
|
11
|
+
let(:record) { { controller: controller, action: action } }
|
12
|
+
let(:controller) { ActionController::Base }
|
13
|
+
let(:action) { nil }
|
14
|
+
|
15
|
+
context 'when controller is nil' do
|
16
|
+
let(:controller) { nil }
|
17
|
+
|
18
|
+
it { is_expected.to be true }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when controller is ignored' do
|
22
|
+
before do
|
23
|
+
allow(Apipie.configuration).to receive(:ignored_by_recorder).and_return(['ActionController::Bas'])
|
24
|
+
end
|
25
|
+
|
26
|
+
it { is_expected.to be true }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when resource#method is ignored' do
|
30
|
+
let(:action) { 'ignored_action' }
|
31
|
+
|
32
|
+
before do
|
33
|
+
allow(Apipie.configuration).to receive(:ignored_by_recorder).and_return(['ActionController::Bas#ignored_action'])
|
34
|
+
end
|
35
|
+
|
36
|
+
it { is_expected.to be true }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when controller is not an API controller' do
|
40
|
+
before do
|
41
|
+
allow(Apipie::Extractor).to receive(:controller_path).with('action_controller/base').and_return('foo')
|
42
|
+
allow(Apipie).to receive(:api_controllers_paths).and_return([])
|
43
|
+
end
|
44
|
+
|
45
|
+
it { is_expected.to be true }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when controller is an API controller' do
|
49
|
+
before do
|
50
|
+
allow(Apipie::Extractor).to receive(:controller_path).with('action_controller/base').and_return('foo')
|
51
|
+
allow(Apipie).to receive(:api_controllers_paths).and_return(['foo'])
|
52
|
+
end
|
53
|
+
|
54
|
+
it { is_expected.to be_falsey }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::Extractor::Recorder::Middleware do
|
4
|
+
let(:app) { lambda { |env| [200, env, "app"] } }
|
5
|
+
let(:stack) { Apipie::Extractor::Recorder::Middleware.new(app) }
|
6
|
+
let(:request) { Rack::MockRequest.new(stack) }
|
7
|
+
let(:response) { request.get('/') }
|
8
|
+
|
9
|
+
it 'correctly process request without recording' do
|
10
|
+
expect(stack).not_to receive(:analyze)
|
11
|
+
response
|
12
|
+
end
|
13
|
+
|
14
|
+
it "analyze request if recording is set" do
|
15
|
+
Apipie.configuration.record = true
|
16
|
+
expect(Apipie::Extractor.call_recorder).to receive(:analyse_env)
|
17
|
+
expect(Apipie::Extractor.call_recorder).to receive(:analyse_response)
|
18
|
+
expect(Apipie::Extractor).to receive(:clean_call_recorder)
|
19
|
+
response
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'with a multipart post' do
|
23
|
+
let(:form_hash) do
|
24
|
+
{
|
25
|
+
'stringbody' => 'this is a string body',
|
26
|
+
'filebody' => {:head => 'X-Fake-Header: fake1\r\n'},
|
27
|
+
'files' => {
|
28
|
+
'0' => {:head => 'X-Fake-Header: fake2\r\n'}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:response) do
|
34
|
+
request.post('/', 'rack.request.form_hash' => form_hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'reformats form parts' do
|
38
|
+
Apipie.configuration.record = true
|
39
|
+
# expect reformat_multipart_data to invoke content_disposition
|
40
|
+
expect(Apipie::Extractor.call_recorder).to receive(:content_disposition)
|
41
|
+
response
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,77 @@
|
|
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
|
+
let(:controller) do
|
8
|
+
controller = ActionController::Metal.new
|
9
|
+
controller.set_request!(request)
|
10
|
+
controller
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#analyse_controller' do
|
14
|
+
subject do
|
15
|
+
recorder.analyse_controller(controller)
|
16
|
+
recorder.record[:action]
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:action) { :show }
|
20
|
+
|
21
|
+
let(:request) do
|
22
|
+
request = ActionDispatch::Request.new({})
|
23
|
+
request.request_parameters = { action: action }
|
24
|
+
request
|
25
|
+
end
|
26
|
+
|
27
|
+
it { is_expected.to eq(action) }
|
28
|
+
|
29
|
+
context 'when a api_action_matcher is configured' do
|
30
|
+
let(:matcher_action) { "#{action}_from_new_matcher" }
|
31
|
+
|
32
|
+
before do
|
33
|
+
Apipie.configuration.api_action_matcher = proc { |_| matcher_action }
|
34
|
+
end
|
35
|
+
|
36
|
+
it { is_expected.to eq(matcher_action) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#analyse_functional_test' do
|
41
|
+
context 'with multipart-form data' do
|
42
|
+
subject do
|
43
|
+
recorder.analyse_controller(controller)
|
44
|
+
recorder.analyze_functional_test(test_context)
|
45
|
+
recorder.record[:request_data]
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:test_context) do
|
49
|
+
double(controller: controller, request: request, response: ActionDispatch::Response.new(200))
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:file) do
|
53
|
+
instance_double(
|
54
|
+
ActionDispatch::Http::UploadedFile,
|
55
|
+
original_filename: 'file.txt',
|
56
|
+
content_type: 'text/plain',
|
57
|
+
size: '1MB'
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:request) do
|
62
|
+
request = ActionDispatch::Request.new({})
|
63
|
+
request.request_method = 'POST'
|
64
|
+
request.headers['Content-Type'] = 'multipart/form-data'
|
65
|
+
request.request_parameters = { file: file }
|
66
|
+
request
|
67
|
+
end
|
68
|
+
|
69
|
+
before do
|
70
|
+
allow(file).to receive(:is_a?).and_return(false)
|
71
|
+
allow(file).to receive(:is_a?).with(ActionDispatch::Http::UploadedFile).and_return(true)
|
72
|
+
end
|
73
|
+
|
74
|
+
it { is_expected.to include("filename=\"#{file.original_filename}\"") }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|