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,671 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::ParamDescription 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
|
+
describe "metadata" do
|
16
|
+
|
17
|
+
it "returns nil when no metadata is provided" do
|
18
|
+
param = Apipie::ParamDescription.new(method_desc, :some_param, String)
|
19
|
+
expect(param.to_json[:metadata]).to eq(nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns the metadata" do
|
23
|
+
meta = {
|
24
|
+
:length => 32,
|
25
|
+
:weight => '830g'
|
26
|
+
}
|
27
|
+
param = Apipie::ParamDescription.new(method_desc, :some_param, String, :meta => meta)
|
28
|
+
expect(param.to_json[:metadata]).to eq(meta)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "show option" do
|
34
|
+
|
35
|
+
it "returns true when show option is not provided" do
|
36
|
+
param = Apipie::ParamDescription.new(method_desc, :some_param, String)
|
37
|
+
expect(param.to_json[:show]).to eq(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns the show option" do
|
41
|
+
param = Apipie::ParamDescription.new(method_desc, :some_param, String, :show => true)
|
42
|
+
expect(param.to_json[:show]).to eq(true)
|
43
|
+
|
44
|
+
param = Apipie::ParamDescription.new(method_desc, :some_param, String, :show => false)
|
45
|
+
expect(param.to_json[:show]).to eq(false)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "full_name" do
|
51
|
+
context "with no nested parameters" do
|
52
|
+
|
53
|
+
it "returns name" do
|
54
|
+
param = Apipie::ParamDescription.new(method_desc, :some_param, String)
|
55
|
+
expect(param.to_json[:full_name]).to eq('some_param')
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with nested parameters" do
|
61
|
+
|
62
|
+
it "returns the parameter's name nested in the parents name" do
|
63
|
+
parent_param = Apipie::ParamDescription.new(method_desc, :parent, String)
|
64
|
+
nested_param = Apipie::ParamDescription.new(method_desc, :nested, String, :parent => parent_param)
|
65
|
+
|
66
|
+
expect(nested_param.to_json[:full_name]).to eq('parent[nested]')
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with the parent parameter set to not show" do
|
70
|
+
|
71
|
+
it "returns just the parameter's name" do
|
72
|
+
parent_param = Apipie::ParamDescription.new(method_desc, :parent, String, :show => false)
|
73
|
+
nested_param = Apipie::ParamDescription.new(method_desc, :nested, String, :parent => parent_param)
|
74
|
+
|
75
|
+
expect(nested_param.to_json[:full_name]).to eq('nested')
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "manual validation text" do
|
83
|
+
it "allows manual text" do
|
84
|
+
param = Apipie::ParamDescription.new(method_desc, :hidden_param, nil, :validations => "must be foo")
|
85
|
+
|
86
|
+
expect(param.validations).to include("\n<p>must be foo</p>\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "allows multiple items" do
|
90
|
+
param = Apipie::ParamDescription.new(method_desc, :hidden_param, nil, :validations => ["> 0", "< 5"])
|
91
|
+
|
92
|
+
expect(param.validations).to include("\n<p>> 0</p>\n")
|
93
|
+
expect(param.validations).to include("\n<p>< 5</p>\n")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "validator selection" do
|
98
|
+
|
99
|
+
it "allows nil validator" do
|
100
|
+
param = Apipie::ParamDescription.new(method_desc, :hidden_param, nil)
|
101
|
+
expect(param.validator).to be_nil
|
102
|
+
end
|
103
|
+
|
104
|
+
it "throws exception on unknown validator" do
|
105
|
+
expect { Apipie::ParamDescription.new(method_desc, :param, :unknown) }.to raise_error(RuntimeError, /Validator.*not found/)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "picks type validator" do
|
109
|
+
expect(Apipie::Validator::BaseValidator).to receive(:find).and_return(:validator_instance)
|
110
|
+
param = Apipie::ParamDescription.new(method_desc, :param, String)
|
111
|
+
expect(param.validator).to eq(:validator_instance)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'validate' do
|
117
|
+
subject { param_description.validate(validation_value) }
|
118
|
+
|
119
|
+
let(:allow_blank) { nil }
|
120
|
+
|
121
|
+
let(:param_description) do
|
122
|
+
Apipie::ParamDescription.new(
|
123
|
+
method_desc,
|
124
|
+
:param,
|
125
|
+
validation_type,
|
126
|
+
allow_blank: allow_blank
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when allow_blank is ignored, as it was before 0.7.0' do
|
131
|
+
before { Apipie.configuration.ignore_allow_blank_false = true }
|
132
|
+
after { Apipie.configuration.ignore_allow_blank_false = false }
|
133
|
+
|
134
|
+
context 'when validation type is :boolean' do
|
135
|
+
let(:validation_type) { :boolean }
|
136
|
+
|
137
|
+
context 'when validation value is false' do
|
138
|
+
let(:validation_value) { false }
|
139
|
+
|
140
|
+
it 'does not raise an error' do
|
141
|
+
expect { subject }.not_to raise_error
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when validation value is an empty string' do
|
146
|
+
let(:validation_value) { '' }
|
147
|
+
|
148
|
+
it 'raises an error' do
|
149
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when validation type is a boolean array' do
|
155
|
+
let(:validation_type) { [true, false] }
|
156
|
+
|
157
|
+
context 'when validation value is false' do
|
158
|
+
let(:validation_value) { false }
|
159
|
+
|
160
|
+
it 'does not raise an error' do
|
161
|
+
expect { subject }.not_to raise_error
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when validation value is true' do
|
166
|
+
let(:validation_value) { true }
|
167
|
+
|
168
|
+
it 'does not raise an error' do
|
169
|
+
expect { subject }.not_to raise_error
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'when validation value is an empty string' do
|
174
|
+
let(:validation_value) { '' }
|
175
|
+
|
176
|
+
it 'raises an error' do
|
177
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when validation type is String' do
|
183
|
+
let(:validation_type) { String }
|
184
|
+
|
185
|
+
context 'when validation value is empty string' do
|
186
|
+
let(:validation_value) { '' }
|
187
|
+
|
188
|
+
it 'does not raise an error' do
|
189
|
+
expect { subject }.not_to raise_error
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when allow_blank is specified as true' do
|
193
|
+
let(:allow_blank) { true }
|
194
|
+
|
195
|
+
it 'does not raise an error' do
|
196
|
+
expect { subject }.not_to raise_error
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'when the validation type is :boolean' do
|
204
|
+
let(:validation_type) { :boolean }
|
205
|
+
|
206
|
+
context 'when validation value' do
|
207
|
+
let(:validation_value) { false }
|
208
|
+
|
209
|
+
it 'does not raise an error' do
|
210
|
+
expect { subject }.not_to raise_error
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'when allow_blank is false' do
|
214
|
+
let(:allow_blank) { false }
|
215
|
+
|
216
|
+
it 'does not raise an error' do
|
217
|
+
expect { subject }.not_to raise_error
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'when allow_blank is true' do
|
222
|
+
let(:allow_blank) { true }
|
223
|
+
|
224
|
+
it 'does not raise an error' do
|
225
|
+
expect { subject }.not_to raise_error
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when validation value is empty string' do
|
231
|
+
let(:validation_value) { '' }
|
232
|
+
|
233
|
+
it 'raises an error' do
|
234
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'when validation type is a boolean array' do
|
240
|
+
let(:validation_type) { [true, false] }
|
241
|
+
|
242
|
+
context 'when validation value is false' do
|
243
|
+
let(:validation_value) { false }
|
244
|
+
|
245
|
+
it 'does not raise an error' do
|
246
|
+
expect { subject }.not_to raise_error
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context 'when validation value is true' do
|
251
|
+
let(:validation_value) { true }
|
252
|
+
|
253
|
+
it 'does not raise an error' do
|
254
|
+
expect { subject }.not_to raise_error
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'when validation value is an empty string' do
|
259
|
+
let(:validation_value) { '' }
|
260
|
+
|
261
|
+
it 'raises an error' do
|
262
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'when the validation type is a custom one' do
|
268
|
+
let(:validation_type) { :custom_bool }
|
269
|
+
|
270
|
+
context 'when ignore_allow_blank? returning true' do
|
271
|
+
before do
|
272
|
+
allow(CustomBoolValidator).to receive(:ignore_allow_blank?).and_return(true)
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'when a blank but valid value is passed' do
|
276
|
+
let(:validation_value) { false }
|
277
|
+
|
278
|
+
it 'does not raise an error' do
|
279
|
+
expect { subject }.not_to raise_error
|
280
|
+
end
|
281
|
+
|
282
|
+
context 'when allow_blank is false' do
|
283
|
+
let(:allow_blank) { false }
|
284
|
+
|
285
|
+
it 'does not raise an error' do
|
286
|
+
expect { subject }.not_to raise_error
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
context 'when a blank but invalid value is passed' do
|
292
|
+
let(:validation_value) { '' }
|
293
|
+
|
294
|
+
it 'raises an error' do
|
295
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context 'when validation type is String' do
|
302
|
+
let(:validation_type) { String }
|
303
|
+
|
304
|
+
context 'when a blank but invalid value is passed' do
|
305
|
+
let(:validation_value) { '' }
|
306
|
+
|
307
|
+
it 'raises an error' do
|
308
|
+
expect { subject }.to raise_error(Apipie::ParamInvalid)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
context 'when allow_blank is specified as true' do
|
313
|
+
let(:allow_blank) { true }
|
314
|
+
|
315
|
+
context 'when and empty string is given' do
|
316
|
+
let(:validation_value) { '' }
|
317
|
+
|
318
|
+
it 'does not raise an error' do
|
319
|
+
expect { subject }.not_to raise_error
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
describe "concern substitution" do
|
327
|
+
|
328
|
+
let(:concern_dsl_data) { dsl_data.merge(:from_concern => true) }
|
329
|
+
|
330
|
+
let(:concern_resource_desc) do
|
331
|
+
Apipie::ResourceDescription.new(ConcernsController, "concerns")
|
332
|
+
end
|
333
|
+
|
334
|
+
let(:concern_method_desc) do
|
335
|
+
Apipie::MethodDescription.new(:show, concern_resource_desc, concern_dsl_data)
|
336
|
+
end
|
337
|
+
|
338
|
+
it "replaces string parameter name with colon prefix" do
|
339
|
+
param = Apipie::ParamDescription.new(concern_method_desc, ":string_subst", String)
|
340
|
+
expect(param.name).to eq("string")
|
341
|
+
end
|
342
|
+
|
343
|
+
it "replaces symbol parameter name" do
|
344
|
+
param = Apipie::ParamDescription.new(concern_method_desc, :concern, String)
|
345
|
+
expect(param.name).to eq(:user)
|
346
|
+
end
|
347
|
+
|
348
|
+
it "keeps original value for strings without colon prefixes" do
|
349
|
+
param = Apipie::ParamDescription.new(concern_method_desc, "string_subst", String)
|
350
|
+
expect(param.name).to eq("string_subst")
|
351
|
+
end
|
352
|
+
|
353
|
+
it "keeps the original value when a string can't be replaced" do
|
354
|
+
param = Apipie::ParamDescription.new(concern_method_desc, ":param", String)
|
355
|
+
expect(param.name).to eq(":param")
|
356
|
+
end
|
357
|
+
|
358
|
+
it "keeps the original value when a symbol can't be replaced" do
|
359
|
+
param = Apipie::ParamDescription.new(concern_method_desc, :param, String)
|
360
|
+
expect(param.name).to eq(:param)
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
describe "required_by_default config option" do
|
365
|
+
context "parameters required by default" do
|
366
|
+
|
367
|
+
before { Apipie.configuration.required_by_default = true }
|
368
|
+
|
369
|
+
it "sets param as required by default" do
|
370
|
+
param = Apipie::ParamDescription.new(method_desc, :required_by_default, String)
|
371
|
+
expect(param.required).to be true
|
372
|
+
end
|
373
|
+
|
374
|
+
it "is possible to set param as optional" do
|
375
|
+
param = Apipie::ParamDescription.new(method_desc, :optional, String, :required => false)
|
376
|
+
expect(param.required).to be false
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
context "parameters optional by default" do
|
382
|
+
|
383
|
+
before { Apipie.configuration.required_by_default = false }
|
384
|
+
|
385
|
+
it "sets param as optional by default" do
|
386
|
+
param = Apipie::ParamDescription.new(method_desc, :optional_by_default, String)
|
387
|
+
expect(param.required).to be false
|
388
|
+
end
|
389
|
+
|
390
|
+
it "is possible to set param as required" do
|
391
|
+
param = Apipie::ParamDescription.new(method_desc, :required, String, 'description','required' => true)
|
392
|
+
expect(param.required).to be true
|
393
|
+
end
|
394
|
+
|
395
|
+
end
|
396
|
+
|
397
|
+
end
|
398
|
+
|
399
|
+
describe "required params on given actions" do
|
400
|
+
let(:method_desc) do
|
401
|
+
Apipie::MethodDescription.new(:create, resource_desc, dsl_data)
|
402
|
+
end
|
403
|
+
|
404
|
+
context "when the param is required for current action" do
|
405
|
+
it "sets param as required" do
|
406
|
+
param = Apipie::ParamDescription.new(method_desc, :required, String, 'description','required' => :create)
|
407
|
+
expect(param.required).to be true
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
context "when the param is required for multiple actions" do
|
412
|
+
it "sets param as required if it match current action" do
|
413
|
+
param = Apipie::ParamDescription.new(method_desc, :required, String, 'description','required' => [:update, :create])
|
414
|
+
expect(param.required).to be true
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
context "when the param is not required for current action" do
|
419
|
+
it "sets param as not required" do
|
420
|
+
param = Apipie::ParamDescription.new(method_desc, :required, String, 'description','required' => :update)
|
421
|
+
expect(param.required).to be false
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
describe "required params in action aware validator" do
|
427
|
+
|
428
|
+
subject { method_description.params[:user].validator.params_ordered }
|
429
|
+
|
430
|
+
let(:required) do
|
431
|
+
subject.find_all(&:required).map(&:name)
|
432
|
+
end
|
433
|
+
|
434
|
+
let(:allowed_nil) do
|
435
|
+
subject.find_all(&:allow_nil).map(&:name)
|
436
|
+
end
|
437
|
+
|
438
|
+
context "with resource creation" do
|
439
|
+
|
440
|
+
let(:method_description) do
|
441
|
+
Apipie.get_method_description(UsersController, :create)
|
442
|
+
end
|
443
|
+
|
444
|
+
it "makes the param required" do
|
445
|
+
expect(required).to include :name
|
446
|
+
expect(required).to include :pass
|
447
|
+
end
|
448
|
+
|
449
|
+
it "doesn't allow nil" do
|
450
|
+
expect(allowed_nil).not_to include :name
|
451
|
+
expect(allowed_nil).not_to include :pass
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
context "with resource update" do
|
456
|
+
|
457
|
+
let(:method_description) do
|
458
|
+
Apipie.get_method_description(UsersController, :update)
|
459
|
+
end
|
460
|
+
|
461
|
+
it "doesn't make the param required" do
|
462
|
+
expect(required).not_to include :name
|
463
|
+
expect(required).not_to include :pass
|
464
|
+
end
|
465
|
+
|
466
|
+
it "doesn't allow nil" do
|
467
|
+
expect(allowed_nil).not_to include :name
|
468
|
+
expect(allowed_nil).not_to include :pass
|
469
|
+
end
|
470
|
+
|
471
|
+
it "doesn't touch params with explicitly set allow_nil" do
|
472
|
+
expect(allowed_nil).not_to include :membership
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
context "with explicitly setting action type in param group" do
|
477
|
+
let(:method_description) do
|
478
|
+
Apipie.get_method_description(UsersController, :admin_create)
|
479
|
+
end
|
480
|
+
|
481
|
+
it "makes the param required" do
|
482
|
+
expect(required).to include :name
|
483
|
+
expect(required).to include :pass
|
484
|
+
end
|
485
|
+
|
486
|
+
it "doesn't allow nil" do
|
487
|
+
expect(allowed_nil).not_to include :name
|
488
|
+
expect(allowed_nil).not_to include :pass
|
489
|
+
end
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
describe 'sub params' do
|
494
|
+
|
495
|
+
context 'with HashValidator' do
|
496
|
+
|
497
|
+
subject do
|
498
|
+
Apipie::ParamDescription.new(method_desc, :param, Hash) do
|
499
|
+
param :answer, Integer
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
it "includes the nested params in the json" do
|
504
|
+
sub_params = subject.to_json[:params]
|
505
|
+
expect(sub_params.size).to eq(1)
|
506
|
+
sub_param = sub_params.first
|
507
|
+
expect(sub_param[:name]).to eq("answer")
|
508
|
+
expect(sub_param[:full_name]).to eq("param[answer]")
|
509
|
+
end
|
510
|
+
|
511
|
+
end
|
512
|
+
|
513
|
+
context 'with NestedValidator' do
|
514
|
+
|
515
|
+
subject do
|
516
|
+
Apipie::ParamDescription.new(method_desc, :param, Array) do
|
517
|
+
param :answer, Integer
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
it "includes the nested params in the json" do
|
522
|
+
sub_params = subject.to_json[:params]
|
523
|
+
expect(sub_params.size).to eq(1)
|
524
|
+
sub_param = sub_params.first
|
525
|
+
expect(sub_param[:name]).to eq("answer")
|
526
|
+
expect(sub_param[:full_name]).to eq("param[answer]")
|
527
|
+
end
|
528
|
+
|
529
|
+
end
|
530
|
+
|
531
|
+
context 'with flat validator' do
|
532
|
+
|
533
|
+
subject do
|
534
|
+
Apipie::ParamDescription.new(method_desc, :param, String)
|
535
|
+
end
|
536
|
+
|
537
|
+
it "includes the nested params in the json" do
|
538
|
+
expect(subject.to_json[:params]).to be_nil
|
539
|
+
end
|
540
|
+
|
541
|
+
end
|
542
|
+
|
543
|
+
end
|
544
|
+
|
545
|
+
describe "Array with classes" do
|
546
|
+
it "is valid for objects included in class array" do
|
547
|
+
param = Apipie::ParamDescription.new(method_desc, :param, [Integer, String])
|
548
|
+
expect { param.validate("1") }.not_to raise_error
|
549
|
+
expect { param.validate(Integer) }.to raise_error(Apipie::ParamInvalid)
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
553
|
+
describe '#deprecated?' do
|
554
|
+
subject do
|
555
|
+
Apipie::ParamDescription.new(method_desc, :param, Integer, options)
|
556
|
+
end
|
557
|
+
|
558
|
+
let(:options) { {} }
|
559
|
+
|
560
|
+
it { is_expected.not_to be_deprecated }
|
561
|
+
|
562
|
+
context 'when deprecated option is passed' do
|
563
|
+
context 'and is true' do
|
564
|
+
let(:options) { { deprecated: true } }
|
565
|
+
|
566
|
+
it { is_expected.to be_deprecated }
|
567
|
+
end
|
568
|
+
|
569
|
+
context 'and is false' do
|
570
|
+
let(:options) { { deprecated: false } }
|
571
|
+
|
572
|
+
it { is_expected.not_to be_deprecated }
|
573
|
+
end
|
574
|
+
|
575
|
+
context 'and is a string' do
|
576
|
+
let(:options) { { deprecated: 'Some description' } }
|
577
|
+
|
578
|
+
it { is_expected.to be_deprecated }
|
579
|
+
end
|
580
|
+
|
581
|
+
context 'and deprecation options are given' do
|
582
|
+
let(:options) do
|
583
|
+
{ deprecated: { in: '2.3', info: 'Something', sunset: '3.0' } }
|
584
|
+
end
|
585
|
+
|
586
|
+
it { is_expected.to be_deprecated }
|
587
|
+
end
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
describe '#deprecation' do
|
592
|
+
subject { param_description.deprecation }
|
593
|
+
|
594
|
+
let(:options) { {} }
|
595
|
+
|
596
|
+
let(:param_description) do
|
597
|
+
Apipie::ParamDescription.new(method_desc, :param, Integer, options)
|
598
|
+
end
|
599
|
+
|
600
|
+
it { is_expected.to be_blank }
|
601
|
+
|
602
|
+
context 'when deprecated option is passed' do
|
603
|
+
context 'and is true' do
|
604
|
+
let(:options) { { deprecated: true } }
|
605
|
+
|
606
|
+
it { is_expected.to be_blank }
|
607
|
+
end
|
608
|
+
|
609
|
+
context 'and is false' do
|
610
|
+
let(:options) { { deprecated: false } }
|
611
|
+
|
612
|
+
it { is_expected.to be_blank }
|
613
|
+
end
|
614
|
+
|
615
|
+
context 'and is a string' do
|
616
|
+
let(:options) { { deprecated: 'Some description' } }
|
617
|
+
|
618
|
+
it { is_expected.to be_an_instance_of(Apipie::ParamDescription::Deprecation) }
|
619
|
+
end
|
620
|
+
|
621
|
+
context 'and deprecation options are given' do
|
622
|
+
let(:options) do
|
623
|
+
{ deprecated: { in: '2.3', info: 'Something', sunset: '3.0' } }
|
624
|
+
end
|
625
|
+
|
626
|
+
it { is_expected.to be_an_instance_of(Apipie::ParamDescription::Deprecation) }
|
627
|
+
end
|
628
|
+
end
|
629
|
+
end
|
630
|
+
|
631
|
+
describe '#required' do
|
632
|
+
subject { param_description.required }
|
633
|
+
|
634
|
+
let(:param_description) do
|
635
|
+
Apipie::ParamDescription.new(method_desc, :param, validator, options)
|
636
|
+
end
|
637
|
+
|
638
|
+
context 'when is passed in options' do
|
639
|
+
let(:validator) { String }
|
640
|
+
|
641
|
+
context 'when is false' do
|
642
|
+
let(:options) { { required: false } }
|
643
|
+
|
644
|
+
it { is_expected.to eq(false) }
|
645
|
+
end
|
646
|
+
|
647
|
+
context 'when is true' do
|
648
|
+
let(:options) { { required: true } }
|
649
|
+
|
650
|
+
it { is_expected.to eq(true) }
|
651
|
+
end
|
652
|
+
end
|
653
|
+
|
654
|
+
context 'when validator options are passed' do
|
655
|
+
let(:options) { { only_in: :response } }
|
656
|
+
let(:validator) { { array_of: String, required: required } }
|
657
|
+
|
658
|
+
context 'when required is false' do
|
659
|
+
let(:required) { false }
|
660
|
+
|
661
|
+
it { is_expected.to eq(false) }
|
662
|
+
end
|
663
|
+
|
664
|
+
context 'when required is true' do
|
665
|
+
let(:required) { true }
|
666
|
+
|
667
|
+
it { is_expected.to eq(true) }
|
668
|
+
end
|
669
|
+
end
|
670
|
+
end
|
671
|
+
end
|