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,61 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "param groups" do
|
4
|
+
before { Apipie.reload_documentation }
|
5
|
+
|
6
|
+
it "lets reuse the params description in more actions" do
|
7
|
+
user_create_desc = Apipie["users#create"].params[:user]
|
8
|
+
user_create_params = user_create_desc.validator.params_ordered.map(&:name)
|
9
|
+
|
10
|
+
user_update_desc = Apipie["users#update"].params[:user]
|
11
|
+
user_update_params = user_update_desc.validator.params_ordered.map(&:name)
|
12
|
+
|
13
|
+
common = user_update_params & user_create_params
|
14
|
+
expect(common.sort_by(&:to_s)).to eq(user_update_params.sort_by(&:to_s))
|
15
|
+
end
|
16
|
+
|
17
|
+
it "allows using groups is nested param descriptions" do
|
18
|
+
user_create_desc = Apipie["users#update"].params[:user]
|
19
|
+
user_create_params = user_create_desc.validator.params_ordered.map(&:name)
|
20
|
+
expect(user_create_params.map(&:to_s).sort).to eq(%w[membership name pass])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "allows adding additional params to group" do
|
24
|
+
user_create_desc = Apipie["users#create"].params[:user]
|
25
|
+
user_create_params = user_create_desc.validator.params_ordered.map(&:name)
|
26
|
+
expect(user_create_params.map(&:to_s).sort).to eq(%w[membership name pass permalink])
|
27
|
+
end
|
28
|
+
|
29
|
+
context "hash param" do
|
30
|
+
it "influences only its childs" do
|
31
|
+
expect(Apipie["users#create"].params[:user].required).to be true
|
32
|
+
expect(Apipie["users#update"].params[:user].required).to be true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "lets you reuse a group definition from different controller" do
|
37
|
+
arch_v1_desc = Apipie["1.0#architectures#create"].params[:architecture]
|
38
|
+
arch_v1_params = arch_v1_desc.validator.params_ordered.map(&:name)
|
39
|
+
|
40
|
+
arch_v2_desc = Apipie["2.0#architectures#create"].params[:architecture]
|
41
|
+
arch_v2_params = arch_v2_desc.validator.params_ordered.map(&:name)
|
42
|
+
|
43
|
+
expect(arch_v1_params.sort_by(&:to_s)).to eq(arch_v2_params.sort_by(&:to_s))
|
44
|
+
end
|
45
|
+
|
46
|
+
it "replaces parameter name in a group when it comes from concern" do
|
47
|
+
expect(Apipie["overridden_concern_resources#update"].params.key?(:user)).to eq(true)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "does not replace parameter name in a group redefined in the controller" do
|
51
|
+
expect(Apipie["overridden_concern_resources#create"].params.key?(:concern)).to eq(true)
|
52
|
+
expect(Apipie["overridden_concern_resources#create"].params.key?(:user)).to eq(false)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "does not replace name of a parameter defined in the controller" do
|
56
|
+
expect(Apipie["overridden_concern_resources#custom"].params.key?(:concern)).to eq(true)
|
57
|
+
expect(Apipie["overridden_concern_resources#custom"].params.key?(:user)).to eq(false)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::ResourceDescription do
|
4
|
+
let(:resource_description) do
|
5
|
+
Apipie::ResourceDescription.new(controller, id, dsl_data)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:controller) { ApplicationController }
|
9
|
+
let(:id) { 'dummy' }
|
10
|
+
let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
|
11
|
+
|
12
|
+
describe '#_methods' do
|
13
|
+
subject(:methods) { resource_description._methods }
|
14
|
+
|
15
|
+
context 'when has method descriptions' do
|
16
|
+
before do
|
17
|
+
resource_description.add_method_description(
|
18
|
+
Apipie::MethodDescription.new(:a, resource_description, dsl_data)
|
19
|
+
)
|
20
|
+
resource_description.add_method_description(
|
21
|
+
Apipie::MethodDescription.new(:b, resource_description, dsl_data)
|
22
|
+
)
|
23
|
+
resource_description.add_method_description(
|
24
|
+
Apipie::MethodDescription.new(:c, resource_description, dsl_data)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'is ordered' do
|
29
|
+
expect(methods.keys).to eq([:a, :b, :c])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#to_json' do
|
35
|
+
let(:json_data) { resource_description.to_json }
|
36
|
+
|
37
|
+
describe 'metadata' do
|
38
|
+
subject { json_data[:metadata] }
|
39
|
+
|
40
|
+
it { is_expected.to be_nil }
|
41
|
+
|
42
|
+
context 'when meta data are provided' do
|
43
|
+
let(:meta) { { length: 32, weight: '830g' } }
|
44
|
+
let(:dsl_data) { super().update({ meta: meta }) }
|
45
|
+
|
46
|
+
it { is_expected.to eq(meta) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'methods' do
|
51
|
+
subject(:methods_as_json) { json_data[:methods] }
|
52
|
+
|
53
|
+
context 'when has method descriptions' do
|
54
|
+
before do
|
55
|
+
resource_description.add_method_description(
|
56
|
+
Apipie::MethodDescription.new(:a, resource_description, dsl_data)
|
57
|
+
)
|
58
|
+
resource_description.add_method_description(
|
59
|
+
Apipie::MethodDescription.new(:b, resource_description, dsl_data)
|
60
|
+
)
|
61
|
+
resource_description.add_method_description(
|
62
|
+
Apipie::MethodDescription.new(:c, resource_description, dsl_data)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'is ordered' do
|
67
|
+
expect(methods_as_json.map { |h| h[:name] }).to eq(%w[a b c])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'name' do
|
74
|
+
subject { resource_description.name }
|
75
|
+
|
76
|
+
it { is_expected.to eq('Dummy') }
|
77
|
+
|
78
|
+
context 'when given id contains dashes' do
|
79
|
+
let(:id) { 'some-nested-resource' }
|
80
|
+
|
81
|
+
it { is_expected.to eq('Some::Nested::Resource') }
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when resource_name is given' do
|
85
|
+
let(:resource_name) { 'Some-Resource' }
|
86
|
+
let(:dsl_data) { super().merge!(resource_name: 'Some-Resource') }
|
87
|
+
|
88
|
+
it { is_expected.to eq(resource_name) }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apipie::ResponseDescription::ResponseObject do
|
4
|
+
describe '#header' do
|
5
|
+
let(:response_object) { described_class.new(nil, nil, nil, nil) }
|
6
|
+
let(:name) { 'Current-Page' }
|
7
|
+
let(:description) { 'The current page in the pagination' }
|
8
|
+
|
9
|
+
before { response_object.header(name, String, description) }
|
10
|
+
|
11
|
+
it 'adds it to the headers' do
|
12
|
+
expect(response_object.headers).to(
|
13
|
+
contain_exactly({
|
14
|
+
name: name,
|
15
|
+
description: description,
|
16
|
+
validator: 'string',
|
17
|
+
options: {}
|
18
|
+
})
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apipie::ResponseDescription do
|
4
|
+
let(:resource_description) do
|
5
|
+
Apipie::ResourceDescription.new(PetsController, 'pets')
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:method_description) do
|
9
|
+
Apipie::MethodDescription.new(
|
10
|
+
'create',
|
11
|
+
resource_description,
|
12
|
+
ActionController::Base.send(:_apipie_dsl_data_init)
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:response_description_dsl) { proc {} }
|
17
|
+
let(:options) { {} }
|
18
|
+
|
19
|
+
let(:response_description) do
|
20
|
+
described_class.new(
|
21
|
+
method_description,
|
22
|
+
204,
|
23
|
+
options,
|
24
|
+
PetsController,
|
25
|
+
response_description_dsl,
|
26
|
+
nil
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#to_json' do
|
31
|
+
let(:to_json) { response_description.to_json }
|
32
|
+
|
33
|
+
describe 'headers' do
|
34
|
+
subject(:headers) { to_json[:headers] }
|
35
|
+
|
36
|
+
it { is_expected.to be_blank }
|
37
|
+
|
38
|
+
context 'when response has headers' do
|
39
|
+
let(:response_description_dsl) do
|
40
|
+
proc do
|
41
|
+
header 'Current-Page', Integer, 'The current page in the pagination', required: true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns the header' do
|
46
|
+
expect(headers).to contain_exactly({
|
47
|
+
name: 'Current-Page',
|
48
|
+
description: 'The current page in the pagination',
|
49
|
+
validator: 'integer',
|
50
|
+
options: { required: true }
|
51
|
+
})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apipie::ResponseDoesNotMatchSwaggerSchema do
|
4
|
+
let(:error) do
|
5
|
+
described_class.new(
|
6
|
+
controller_name,
|
7
|
+
method_name,
|
8
|
+
response_code,
|
9
|
+
error_messages,
|
10
|
+
schema,
|
11
|
+
returned_object
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:controller_name) { 'UserController' }
|
16
|
+
let(:method_name) { 'index' }
|
17
|
+
let(:response_code) { 200 }
|
18
|
+
let(:error_messages) { [] }
|
19
|
+
let(:schema) { {} }
|
20
|
+
let(:returned_object) { {} }
|
21
|
+
|
22
|
+
describe '#to_s' do
|
23
|
+
subject { error.to_s }
|
24
|
+
|
25
|
+
let(:error_message) do
|
26
|
+
<<~HEREDOC.chomp
|
27
|
+
Response does not match swagger schema (#{controller_name}##{method_name} #{response_code}): #{error_messages}
|
28
|
+
Schema: #{JSON(schema)}
|
29
|
+
Returned object: #{returned_object}
|
30
|
+
HEREDOC
|
31
|
+
end
|
32
|
+
|
33
|
+
it { is_expected.to eq(error_message) }
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dummy/app/controllers/pets_using_self_describing_classes_controller'
|
3
|
+
|
4
|
+
describe Apipie::SwaggerGenerator do
|
5
|
+
describe '.json_schema_for_method_response' do
|
6
|
+
subject { json_schema_for_method_response }
|
7
|
+
|
8
|
+
let(:response_description_dsl) do
|
9
|
+
proc do
|
10
|
+
property :a_number, Integer, example: 1
|
11
|
+
property :an_optional_number, Integer, required: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:response_description_options) do
|
16
|
+
[{}, PetsController, response_description_dsl, nil]
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:dsl_data) do
|
20
|
+
ActionController::Base
|
21
|
+
.send(:_apipie_dsl_data_init)
|
22
|
+
.merge(
|
23
|
+
{
|
24
|
+
returns: [[200, response_description_options]],
|
25
|
+
api_args: [
|
26
|
+
['get', '/path', 'Some api description', { deprecated: true }]
|
27
|
+
]
|
28
|
+
}
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:method_description) do
|
33
|
+
Apipie::MethodDescription.new(
|
34
|
+
:show,
|
35
|
+
Apipie::ResourceDescription.new(UsersController, 'users'),
|
36
|
+
dsl_data
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:json_schema_for_method_response) do
|
41
|
+
described_class.json_schema_for_method_response(
|
42
|
+
method_description,
|
43
|
+
return_code,
|
44
|
+
false
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when there is no return code for responses' do
|
49
|
+
let(:return_code) { 3000 }
|
50
|
+
|
51
|
+
it { is_expected.to be_nil }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when return code exists' do
|
55
|
+
let(:return_code) { 200 }
|
56
|
+
|
57
|
+
describe 'properties' do
|
58
|
+
subject(:properties) { json_schema_for_method_response[:properties] }
|
59
|
+
|
60
|
+
it 'returns correct properties' do
|
61
|
+
expect(properties).to eq(
|
62
|
+
{
|
63
|
+
a_number: {
|
64
|
+
type: 'number', required: true, example: 1
|
65
|
+
},
|
66
|
+
an_optional_number: {
|
67
|
+
type: 'number'
|
68
|
+
}
|
69
|
+
}
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.json_schema_for_self_describing_class' do
|
77
|
+
subject(:schema) do
|
78
|
+
described_class.json_schema_for_self_describing_class(
|
79
|
+
self_describing_class,
|
80
|
+
allow_null
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
let(:self_describing_class) { PetWithMeasurements }
|
85
|
+
let(:allow_null) { false }
|
86
|
+
|
87
|
+
before { Apipie.configuration.generator.swagger.responses_use_refs = false }
|
88
|
+
|
89
|
+
it 'returns the self describing class schema' do
|
90
|
+
expect(schema.keys).to include(:type, :properties, :required)
|
91
|
+
expect(schema[:properties].keys).to include(:pet_name, :animal_type, :pet_measurements)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::Validator do
|
4
|
+
|
5
|
+
let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
|
6
|
+
|
7
|
+
let(:resource_desc) do
|
8
|
+
Apipie::ResourceDescription.new(UsersController, "users")
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:method_desc) do
|
12
|
+
Apipie::MethodDescription.new(:show, resource_desc, dsl_data)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:params_desc) do
|
16
|
+
Apipie::ParamDescription.new(method_desc, :param, nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'TypeValidator' do
|
20
|
+
|
21
|
+
context "expected type" do
|
22
|
+
|
23
|
+
it "returns hash for type Hash" do
|
24
|
+
validator = Apipie::Validator::TypeValidator.new(params_desc, Hash)
|
25
|
+
expect(validator.expected_type).to eq('hash')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns array for type Array" do
|
29
|
+
validator = Apipie::Validator::TypeValidator.new(params_desc, Array)
|
30
|
+
expect(validator.expected_type).to eq('array')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns numeric for type Numeric" do
|
34
|
+
validator = Apipie::Validator::TypeValidator.new(params_desc, Numeric)
|
35
|
+
expect(validator.expected_type).to eq('numeric')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns string by default" do
|
39
|
+
validator = Apipie::Validator::TypeValidator.new(params_desc, Symbol)
|
40
|
+
expect(validator.expected_type).to eq('string')
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'NumberValidator' do
|
46
|
+
it 'expects a Numeric type' do
|
47
|
+
validator = Apipie::Validator::BaseValidator.find(params_desc, :number, nil, nil)
|
48
|
+
expect(validator.expected_type).to eq('numeric')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'BooleanValidator' do
|
54
|
+
let(:validator) do
|
55
|
+
Apipie::Validator::BooleanValidator
|
56
|
+
end
|
57
|
+
|
58
|
+
let(:validator_instance) { validator.new(params_desc) }
|
59
|
+
|
60
|
+
describe '.build' do
|
61
|
+
subject { validator.build(params_desc, argument, nil, nil) }
|
62
|
+
|
63
|
+
context 'when argument is [true, false]' do
|
64
|
+
let(:argument) { [true, false] }
|
65
|
+
|
66
|
+
it { is_expected.to be_an_instance_of(Apipie::Validator::BooleanValidator) }
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when argument is :bool' do
|
70
|
+
let(:argument) { :bool }
|
71
|
+
|
72
|
+
it { is_expected.to be_an_instance_of(Apipie::Validator::BooleanValidator) }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when argument :boolean' do
|
76
|
+
let(:argument) { :boolean }
|
77
|
+
|
78
|
+
it { is_expected.to be_an_instance_of(Apipie::Validator::BooleanValidator) }
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when argument :booooooooolean' do
|
82
|
+
let(:argument) { :booooooooolean }
|
83
|
+
|
84
|
+
it { is_expected.to be_nil }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#validate' do
|
89
|
+
it "validates by object class" do
|
90
|
+
expect(validator_instance.validate("1")).to be_truthy
|
91
|
+
expect(validator_instance.validate(1)).to be_truthy
|
92
|
+
expect(validator_instance.validate(true)).to be_truthy
|
93
|
+
expect(validator_instance.validate(0)).to be_truthy
|
94
|
+
expect(validator_instance.validate(false)).to be_truthy
|
95
|
+
expect(validator_instance.validate({ 1 => 1 })).to be_falsey
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#description' do
|
100
|
+
subject { validator_instance.description }
|
101
|
+
|
102
|
+
it { is_expected.to eq('Must be one of: <code>true</code>, <code>false</code>, <code>1</code>, <code>0</code>.') }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'ArrayClassValidator' do
|
107
|
+
it "validates by object class" do
|
108
|
+
validator = Apipie::Validator::ArrayClassValidator.new(params_desc, [Integer, String])
|
109
|
+
expect(validator.validate("1")).to be_truthy
|
110
|
+
expect(validator.validate(1)).to be_truthy
|
111
|
+
expect(validator.validate({ 1 => 1 })).to be_falsey
|
112
|
+
end
|
113
|
+
|
114
|
+
it "has a valid description" do
|
115
|
+
validator = Apipie::Validator::ArrayClassValidator.new(params_desc, [Float, String])
|
116
|
+
expect(validator.description).to eq('Must be one of: <code>Float</code>, <code>String</code>.')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'RegexpValidator' do
|
121
|
+
it "validates by object class" do
|
122
|
+
validator = Apipie::Validator::RegexpValidator.new(params_desc, /^valid( extra)*$/)
|
123
|
+
expect(validator.validate("valid")).to be_truthy
|
124
|
+
expect(validator.validate("valid extra")).to be_truthy
|
125
|
+
expect(validator.validate("valid extra extra")).to be_truthy
|
126
|
+
expect(validator.validate("invalid")).to be_falsey
|
127
|
+
end
|
128
|
+
|
129
|
+
it "has a valid description" do
|
130
|
+
validator = Apipie::Validator::RegexpValidator.new(params_desc, /^valid( extra)*$/)
|
131
|
+
expect(validator.description).to eq('Must match regular expression <code>/^valid( extra)*$/</code>.')
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe 'EnumValidator' do
|
136
|
+
it "validates by object class" do
|
137
|
+
validator = Apipie::Validator::EnumValidator.new(params_desc, ['first', 'second & third'])
|
138
|
+
expect(validator.validate("first")).to be_truthy
|
139
|
+
expect(validator.validate("second & third")).to be_truthy
|
140
|
+
expect(validator.validate(1)).to be_falsey
|
141
|
+
expect(validator.validate({ 1 => 1 })).to be_falsey
|
142
|
+
end
|
143
|
+
|
144
|
+
it "has a valid description" do
|
145
|
+
validator = Apipie::Validator::EnumValidator.new(params_desc, ['first', 'second & third'])
|
146
|
+
expect(validator.description).to eq('Must be one of: <code>first</code>, <code>second & third</code>.')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'rake tasks' do
|
4
|
+
include_context "rake"
|
5
|
+
|
6
|
+
let(:doc_path) { 'tmp/user_specified_doc_path' }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Apipie.configuration.doc_path = doc_path
|
10
|
+
allow(Apipie).to receive(:reload_documentation)
|
11
|
+
subject.invoke(*task_args)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'static pages' do
|
15
|
+
|
16
|
+
let(:apidoc_html) do
|
17
|
+
File.read("#{doc_output}.html")
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:doc_output) do
|
21
|
+
File.join(Rails.root, doc_path, 'apidoc')
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
Dir["#{doc_output}*"].each { |static_file| FileUtils.rm_rf(static_file) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'apipie:static' do
|
29
|
+
it "generates static files for the default version of apipie docs" do
|
30
|
+
expect(apidoc_html).to match(/Test app #{Apipie.configuration.default_version}/)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "includes the stylesheets" do
|
34
|
+
expect(apidoc_html).to include('./apidoc/stylesheets/bundled/bootstrap.min.css')
|
35
|
+
expect(File).to exist(File.join(doc_output, 'stylesheets/bundled/bootstrap.min.css'))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'apipie:static[2.0]' do
|
40
|
+
it "generates static files for the default version of apipie docs" do
|
41
|
+
expect(apidoc_html).to match(/Test app 2.0/)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "includes the stylesheets" do
|
45
|
+
expect(apidoc_html).to include('./apidoc/stylesheets/bundled/bootstrap.min.css')
|
46
|
+
expect(File).to exist(File.join(doc_output, 'stylesheets/bundled/bootstrap.min.css'))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'apipie:cache' do
|
52
|
+
let(:cache_output) { Apipie.configuration.cache_dir }
|
53
|
+
|
54
|
+
let(:apidoc_html) do
|
55
|
+
File.read("#{cache_output}.html")
|
56
|
+
end
|
57
|
+
|
58
|
+
after do
|
59
|
+
Dir["#{cache_output}*"].each { |static_file| FileUtils.rm_rf(static_file) }
|
60
|
+
end
|
61
|
+
|
62
|
+
it "generates cache files" do
|
63
|
+
expect(File).to exist(File.join(cache_output, 'apidoc.html'))
|
64
|
+
expect(File).to exist(File.join(cache_output, 'apidoc/development.html'))
|
65
|
+
expect(File).to exist(File.join(cache_output, 'apidoc/development/users.html'))
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|