apipie-rails 0.5.19 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +31 -0
- data/.github/workflows/rubocop-challenger.yml +28 -0
- data/.github/workflows/rubocop.yml +18 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +128 -0
- data/.rubocop_todo.yml +2056 -0
- data/.vscode/settings.json +3 -0
- data/CHANGELOG.md +161 -0
- data/Gemfile +20 -0
- data/README.rst +117 -23
- data/Rakefile +0 -5
- data/apipie-rails.gemspec +18 -9
- data/app/controllers/apipie/apipies_controller.rb +14 -29
- data/app/helpers/apipie_helper.rb +1 -1
- data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
- data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
- data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
- data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
- data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
- data/app/views/apipie/apipies/_deprecation.html.erb +16 -0
- data/app/views/apipie/apipies/_params.html.erb +7 -1
- data/config/locales/en.yml +8 -0
- data/config/locales/ko.yml +31 -0
- data/gemfiles/Gemfile.tools +9 -0
- data/lib/apipie/apipie_module.rb +7 -7
- data/lib/apipie/application.rb +132 -97
- data/lib/apipie/configuration.rb +43 -33
- data/lib/apipie/dsl_definition.rb +44 -33
- data/lib/apipie/error_description.rb +3 -3
- data/lib/apipie/errors.rb +17 -17
- data/lib/apipie/extractor/collector.rb +5 -6
- data/lib/apipie/extractor/recorder.rb +35 -8
- data/lib/apipie/extractor/writer.rb +15 -15
- data/lib/apipie/extractor.rb +6 -9
- 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 +58 -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 +128 -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 +3 -3
- data/lib/apipie/markup.rb +9 -8
- 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 +12 -56
- data/lib/apipie/param_description/deprecation.rb +24 -0
- data/lib/apipie/param_description.rb +57 -24
- data/lib/apipie/resource_description.rb +42 -14
- data/lib/apipie/response_description.rb +3 -3
- data/lib/apipie/response_description_adapter.rb +12 -10
- data/lib/apipie/routing.rb +1 -1
- data/lib/apipie/rspec/response_validation_helper.rb +3 -3
- data/lib/apipie/static_dispatcher.rb +10 -2
- data/lib/apipie/swagger_generator.rb +28 -691
- data/lib/apipie/validator.rb +41 -11
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +36 -5
- data/lib/generators/apipie/install/install_generator.rb +1 -1
- data/lib/generators/apipie/views_generator.rb +1 -1
- data/lib/tasks/apipie.rake +37 -32
- data/rel-eng/gem_release.ipynb +41 -9
- data/spec/controllers/api/v2/architectures_controller_spec.rb +10 -3
- data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
- data/spec/controllers/api/v2/nested/resources_controller_spec.rb +18 -2
- data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
- data/spec/controllers/included_param_group_controller_spec.rb +13 -0
- data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +26 -32
- data/spec/controllers/users_controller_spec.rb +47 -6
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +2 -1
- data/spec/dummy/app/controllers/api/v2/base_controller.rb +6 -0
- data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
- data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +2 -2
- data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
- data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
- data/spec/dummy/app/controllers/{concerns/extending_concern.rb → extending_concern.rb} +0 -2
- data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
- data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
- data/spec/dummy/app/controllers/pets_controller.rb +5 -5
- data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
- data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +0 -2
- data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
- data/spec/dummy/app/controllers/users_controller.rb +17 -5
- data/spec/dummy/app/helpers/random_param_group.rb +8 -0
- data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
- data/spec/dummy/config/application.rb +2 -5
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +0 -3
- data/spec/dummy/config/environments/production.rb +0 -3
- data/spec/dummy/config/environments/test.rb +0 -5
- data/spec/dummy/config/initializers/apipie.rb +2 -2
- data/spec/dummy/config/routes.rb +8 -0
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/script/rails +2 -2
- data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +95 -23
- 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_spec.rb +77 -0
- data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +8 -6
- data/spec/lib/{extractor → apipie}/extractor_spec.rb +1 -1
- data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +7 -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/operation_id_spec.rb +63 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +215 -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 +183 -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/{param_description_spec.rb → apipie/param_description_spec.rb} +332 -6
- data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +6 -5
- data/spec/lib/apipie/resource_description_spec.rb +91 -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/{validator_spec.rb → apipie/validator_spec.rb} +48 -12
- data/spec/lib/rake_spec.rb +3 -5
- data/spec/lib/swagger/openapi_2_0_schema.json +8 -1
- data/spec/lib/swagger/rake_swagger_spec.rb +30 -10
- data/spec/lib/swagger/swagger_dsl_spec.rb +18 -12
- data/spec/lib/validators/array_validator_spec.rb +1 -1
- data/spec/spec_helper.rb +10 -32
- data/spec/support/custom_bool_validator.rb +17 -0
- data/spec/{controllers → test_engine}/memes_controller_spec.rb +1 -1
- metadata +173 -125
- data/.travis.yml +0 -41
- data/Gemfile +0 -1
- data/Gemfile.rails41 +0 -7
- data/Gemfile.rails42 +0 -14
- data/Gemfile.rails50 +0 -9
- data/Gemfile.rails51 +0 -9
- data/Gemfile.rails60 +0 -10
- data/Gemfile.rails61 +0 -10
- data/spec/lib/application_spec.rb +0 -49
- data/spec/lib/method_description_spec.rb +0 -98
- data/spec/lib/resource_description_spec.rb +0 -48
- /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
@@ -5,100 +5,94 @@ require 'apipie/rspec/response_validation_helper'
|
|
5
5
|
require "json-schema"
|
6
6
|
|
7
7
|
RSpec.describe PetsController, :type => :controller do
|
8
|
-
before :each do
|
9
|
-
Apipie.configuration.swagger_allow_additional_properties_in_response = false
|
10
|
-
end
|
11
|
-
|
12
8
|
it "does not raise error when rendered output matches the described response" do
|
13
|
-
response = get :return_and_validate_expected_response,
|
9
|
+
response = get :return_and_validate_expected_response, format: :json
|
14
10
|
expect(response).to match_declared_responses
|
15
11
|
end
|
16
12
|
|
17
13
|
it "does not raise error when rendered output (array) matches the described response" do
|
18
|
-
response = get :return_and_validate_expected_array_response,
|
14
|
+
response = get :return_and_validate_expected_array_response, format: :json
|
19
15
|
expect(response).to match_declared_responses
|
20
16
|
end
|
21
17
|
|
22
18
|
it "does not raises error when rendered output includes null in the response" do
|
23
|
-
response = get :return_and_validate_expected_response_with_null,
|
19
|
+
response = get :return_and_validate_expected_response_with_null, format: :json
|
24
20
|
expect(response).to match_declared_responses
|
25
21
|
end
|
26
22
|
|
27
23
|
it "does not raise error when rendered output includes null (instead of an object) in the response" do
|
28
|
-
response = get :return_and_validate_expected_response_with_null_object,
|
24
|
+
response = get :return_and_validate_expected_response_with_null_object, format: :json
|
29
25
|
expect(response).to match_declared_responses
|
30
26
|
end
|
31
27
|
|
32
28
|
it "raises error when a response field has the wrong type" do
|
33
|
-
response = get :return_and_validate_type_mismatch,
|
29
|
+
response = get :return_and_validate_type_mismatch, format: :json
|
34
30
|
expect(response).not_to match_declared_responses
|
35
31
|
end
|
36
32
|
|
37
33
|
it "raises error when a response has a missing field" do
|
38
|
-
response = get :return_and_validate_missing_field,
|
34
|
+
response = get :return_and_validate_missing_field, format: :json
|
39
35
|
expect(response).not_to match_declared_responses
|
40
36
|
end
|
41
37
|
|
42
|
-
it "raises error when a response has an extra property and '
|
43
|
-
response = get :return_and_validate_extra_property,
|
38
|
+
it "raises error when a response has an extra property and 'swagger.allow_additional_properties_in_response' is false" do
|
39
|
+
response = get :return_and_validate_extra_property, format: :json
|
44
40
|
expect(response).not_to match_declared_responses
|
45
41
|
end
|
46
42
|
|
47
43
|
it "raises error when a response has is array instead of object" do
|
48
44
|
# note: this action returns HTTP 201, not HTTP 200!
|
49
|
-
response = get :return_and_validate_unexpected_array_response,
|
45
|
+
response = get :return_and_validate_unexpected_array_response, format: :json
|
50
46
|
expect(response).not_to match_declared_responses
|
51
47
|
end
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
context "when allow_additional_properties_in_response is true'" do
|
50
|
+
before do
|
51
|
+
Apipie.configuration.generator.swagger.allow_additional_properties_in_response = true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "does not raise error when a response has an extra property" do
|
55
|
+
response = get :return_and_validate_extra_property, format: :json
|
56
|
+
expect(response).to match_declared_responses
|
57
|
+
end
|
57
58
|
end
|
58
59
|
|
59
60
|
it "does not raise error when a response has an extra field and 'additional_properties' is specified in the response" do
|
60
|
-
|
61
|
-
response = get :return_and_validate_allowed_extra_property, {format: :json}
|
61
|
+
response = get :return_and_validate_allowed_extra_property, format: :json
|
62
62
|
expect(response).to match_declared_responses
|
63
63
|
end
|
64
64
|
|
65
65
|
it "raises error when a response sub-object has an extra field and 'additional_properties' is not specified on it, but specified on the top level of the response" do
|
66
|
-
|
67
|
-
response = get :sub_object_invalid_extra_property, {format: :json}
|
66
|
+
response = get :sub_object_invalid_extra_property, format: :json
|
68
67
|
expect(response).not_to match_declared_responses
|
69
68
|
end
|
70
69
|
|
71
|
-
it "does not
|
72
|
-
|
73
|
-
response = get :sub_object_allowed_extra_property, {format: :json}
|
70
|
+
it "does not raise error when a response sub-object has an extra field and 'additional_properties' is specified on it" do
|
71
|
+
response = get :sub_object_allowed_extra_property, format: :json
|
74
72
|
expect(response).to match_declared_responses
|
75
73
|
end
|
76
74
|
|
77
75
|
describe "auto validation" do
|
78
76
|
auto_validate_rendered_views
|
79
77
|
it "raises exception when a response field has the wrong type and auto validation is turned on" do
|
80
|
-
expect { get :return_and_validate_type_mismatch,
|
78
|
+
expect { get :return_and_validate_type_mismatch, format: :json }.to raise_error(Apipie::ResponseDoesNotMatchSwaggerSchema)
|
81
79
|
end
|
82
80
|
|
83
81
|
it "does not raise an exception when calling an undocumented method" do
|
84
|
-
expect { get :undocumented_method,
|
82
|
+
expect { get :undocumented_method, format: :json }.not_to raise_error
|
85
83
|
end
|
86
84
|
|
87
85
|
end
|
88
86
|
|
89
|
-
|
90
87
|
describe "with array field" do
|
91
88
|
it "no error for valid response" do
|
92
|
-
response = get :returns_response_with_valid_array,
|
89
|
+
response = get :returns_response_with_valid_array, format: :json
|
93
90
|
expect(response).to match_declared_responses
|
94
91
|
end
|
95
92
|
|
96
93
|
it "error if type of element in the array is wrong" do
|
97
|
-
response = get :returns_response_with_invalid_array,
|
94
|
+
response = get :returns_response_with_invalid_array, format: :json
|
98
95
|
expect(response).not_to match_declared_responses
|
99
96
|
end
|
100
97
|
end
|
101
|
-
|
102
|
-
|
103
|
-
|
104
98
|
end
|
@@ -5,9 +5,10 @@ def compare_hashes(h1, h2)
|
|
5
5
|
expect(h1).to eq(h2)
|
6
6
|
else
|
7
7
|
h1.each do |key, val|
|
8
|
-
|
8
|
+
case val
|
9
|
+
when Hash
|
9
10
|
compare_hashes val, h2[key]
|
10
|
-
|
11
|
+
when Array
|
11
12
|
val.each_with_index do |v, i|
|
12
13
|
compare_hashes val[i], h2[key][i]
|
13
14
|
end
|
@@ -36,6 +37,7 @@ describe UsersController do
|
|
36
37
|
expect(methods.keys).to include(:update)
|
37
38
|
expect(methods.keys).to include(:two_urls)
|
38
39
|
expect(methods.keys).to include(:action_with_headers)
|
40
|
+
expect(methods.keys).to include(:multiple_required_params)
|
39
41
|
end
|
40
42
|
|
41
43
|
it "should contain info about resource" do
|
@@ -51,7 +53,7 @@ describe UsersController do
|
|
51
53
|
expect(subject._params_args.count).to eq(2)
|
52
54
|
name, type, options = subject._params_args.first
|
53
55
|
expect(name).to eq(:id)
|
54
|
-
expect(type).to eq(
|
56
|
+
expect(type).to eq(Integer)
|
55
57
|
expect(options).to eq({:required=>false, :desc=>"User ID"})
|
56
58
|
end
|
57
59
|
end
|
@@ -100,6 +102,10 @@ describe UsersController do
|
|
100
102
|
expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
|
101
103
|
end
|
102
104
|
|
105
|
+
it "should fail if multiple required parameters are missing" do
|
106
|
+
expect { get :multiple_required_params }.to raise_error(Apipie::ParamMultipleMissing, /required_param1.*\n.*required_param2|required_param2.*\n.*required_parameter1/)
|
107
|
+
end
|
108
|
+
|
103
109
|
it "should pass if required parameter has wrong type" do
|
104
110
|
expect { get :show, :params => { :id => 5 , :session => "secret_hash" }}.not_to raise_error
|
105
111
|
expect { get :show, :params => { :id => "ten" , :session => "secret_hash" }}.not_to raise_error
|
@@ -124,6 +130,29 @@ describe UsersController do
|
|
124
130
|
end
|
125
131
|
end
|
126
132
|
|
133
|
+
context "key validations are enabled and skip on non-validated keys" do
|
134
|
+
before do
|
135
|
+
Apipie.configuration.validate_value = false
|
136
|
+
Apipie.configuration.validate_presence = true
|
137
|
+
Apipie.configuration.validate_key = true
|
138
|
+
Apipie.configuration.action_on_non_validated_keys = :skip
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should reply to valid request" do
|
142
|
+
expect { get :show, :params => { :id => 5, :session => 'secret_hash' }}.not_to raise_error
|
143
|
+
assert_response :success
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should delete the param and not fail if an extra parameter is passed." do
|
147
|
+
expect { get :show, :params => { :id => 5 , :badparam => 'badfoo', :session => "secret_hash" }}.not_to raise_error
|
148
|
+
expect(controller.params.as_json).to eq({"session"=>"secret_hash", "id"=>"5", "controller"=>"users", "action"=>"show"})
|
149
|
+
end
|
150
|
+
|
151
|
+
after do
|
152
|
+
Apipie.configuration.action_on_non_validated_keys = :raise
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
127
156
|
context "presence and value validations are enabled" do
|
128
157
|
before do
|
129
158
|
Apipie.configuration.validate_value = true
|
@@ -222,6 +251,11 @@ describe UsersController do
|
|
222
251
|
post :create, :params => { :user => { :name => "root", :pass => "12345", :membership => "____" } }
|
223
252
|
}.to raise_error(Apipie::ParamInvalid, /membership/)
|
224
253
|
|
254
|
+
# Should include both pass and name
|
255
|
+
expect {
|
256
|
+
post :create, :params => { :user => { :membership => "standard" } }
|
257
|
+
}.to raise_error(Apipie::ParamMultipleMissing, /pass.*\n.*name|name.*\n.*pass/)
|
258
|
+
|
225
259
|
expect {
|
226
260
|
post :create, :params => { :user => { :name => "root" } }
|
227
261
|
}.to raise_error(Apipie::ParamMissing, /pass/)
|
@@ -245,6 +279,7 @@ describe UsersController do
|
|
245
279
|
:allow_blank => false,
|
246
280
|
:metadata => nil,
|
247
281
|
:show => true,
|
282
|
+
:deprecated => false,
|
248
283
|
:expected_type => "hash",
|
249
284
|
:validations => [])
|
250
285
|
end
|
@@ -387,7 +422,7 @@ describe UsersController do
|
|
387
422
|
expect(b.resource._id).to eq('users')
|
388
423
|
|
389
424
|
expect(b.apis.count).to eq(1)
|
390
|
-
expect(b.formats).to eq([
|
425
|
+
expect(b.formats).to eq(%w[json jsonp])
|
391
426
|
api = b.apis.first
|
392
427
|
expect(api.short_description).to eq("Show user profile")
|
393
428
|
expect(api.path).to eq("/users/:id")
|
@@ -561,6 +596,7 @@ describe UsersController do
|
|
561
596
|
:description=>"\n<p>Authorization</p>\n",
|
562
597
|
:name=>"oauth",
|
563
598
|
:show=>true,
|
599
|
+
:deprecated=>false,
|
564
600
|
:expected_type=>"string"},
|
565
601
|
{:validator=>"Must be a Hash",
|
566
602
|
:description=>"\n<p>Deprecated parameter not documented</p>\n",
|
@@ -571,15 +607,17 @@ describe UsersController do
|
|
571
607
|
:required=>false,
|
572
608
|
:full_name=>"legacy_param",
|
573
609
|
:show=>false,
|
610
|
+
:deprecated=>false,
|
574
611
|
:params=>
|
575
612
|
[{:validator=>"Must be a Hash",
|
576
613
|
:description=>"\n<p>Param description for all methods</p>\n",
|
577
614
|
:expected_type=>"hash",
|
578
615
|
:allow_nil=>false,
|
579
|
-
|
616
|
+
:allow_blank => false,
|
580
617
|
:name=>"resource_param",
|
581
618
|
:required=>false,
|
582
619
|
:full_name=>"resource_param",
|
620
|
+
:deprecated=>false,
|
583
621
|
:show=>true,
|
584
622
|
:params=>
|
585
623
|
[{:required=>true,
|
@@ -589,6 +627,7 @@ describe UsersController do
|
|
589
627
|
:description=>"\n<p>Username for login</p>\n",
|
590
628
|
:name=>"ausername", :full_name=>"resource_param[ausername]",
|
591
629
|
:show=>true,
|
630
|
+
:deprecated=>false,
|
592
631
|
:expected_type=>"string"},
|
593
632
|
{:required=>true,
|
594
633
|
:allow_nil => false,
|
@@ -597,6 +636,7 @@ describe UsersController do
|
|
597
636
|
:description=>"\n<p>Password for login</p>\n",
|
598
637
|
:name=>"apassword", :full_name=>"resource_param[apassword]",
|
599
638
|
:show=>true,
|
639
|
+
:deprecated=>false,
|
600
640
|
:expected_type=>"string"}
|
601
641
|
]}
|
602
642
|
]
|
@@ -607,6 +647,7 @@ describe UsersController do
|
|
607
647
|
:description=>"\n<p>Company ID</p>\n",
|
608
648
|
:name=>"id", :full_name=>"id",
|
609
649
|
:show=>true,
|
650
|
+
:deprecated=>false,
|
610
651
|
:expected_type=>"numeric"},
|
611
652
|
],
|
612
653
|
:name => 'two_urls',
|
@@ -677,7 +718,7 @@ EOS2
|
|
677
718
|
param = a.params[:array_param]
|
678
719
|
expect(param.desc).to eq("\n<p>array validator</p>\n")
|
679
720
|
expect(param.validator.class).to be(Apipie::Validator::EnumValidator)
|
680
|
-
expect(param.validator.instance_variable_get("@array")).to eq([
|
721
|
+
expect(param.validator.instance_variable_get("@array")).to eq(%w[100 one two 1 2])
|
681
722
|
|
682
723
|
param = a.params[:proc_param]
|
683
724
|
expect(param.desc).to eq("\n<p>proc validator</p>\n")
|
data/spec/dummy/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
2
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
3
|
|
4
|
-
require File.expand_path('
|
4
|
+
require File.expand_path('config/application', __dir__)
|
5
5
|
require 'rake'
|
6
6
|
|
7
7
|
Dummy::Application.load_tasks
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Api
|
2
|
+
module V2
|
3
|
+
class EmptyMiddleController < V2::BaseController
|
4
|
+
# This is an empty controller, used to test cases where controllers
|
5
|
+
# may inherit from a middle controler that does not define a resource_description,
|
6
|
+
# but the middle controller's parent does.
|
7
|
+
|
8
|
+
def inconsequential_method
|
9
|
+
# This method is here to ensure that the controller is not empty.
|
10
|
+
# It triggers method_added, which is used to add the resource description.
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Api
|
2
2
|
module V2
|
3
3
|
class Nested::ResourcesController < V2::BaseController
|
4
|
-
resource_description do
|
5
|
-
name '
|
4
|
+
resource_description do
|
5
|
+
name ->(controller) { controller.controller_name.delete('aeiou').capitalize }
|
6
6
|
resource_id "resource"
|
7
7
|
end
|
8
8
|
api :GET, "/nested/resources/", "List all nested resources."
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Api
|
2
|
+
module V2
|
3
|
+
module Sub
|
4
|
+
class FootgunsController < V2::EmptyMiddleController
|
5
|
+
resource_description do
|
6
|
+
short 'Footguns are bad'
|
7
|
+
end
|
8
|
+
|
9
|
+
api :GET, '/footguns/', 'List all footguns.'
|
10
|
+
def index; end
|
11
|
+
|
12
|
+
api :GET, '/footguns/:id/', 'Show a footgun.'
|
13
|
+
def show; end
|
14
|
+
|
15
|
+
api :POST, '/footguns/', 'Create a footgun.'
|
16
|
+
def create; end
|
17
|
+
|
18
|
+
api :PUT, '/footguns/:id/', 'Update a footgun.'
|
19
|
+
param :footgun, Hash, :required => true do
|
20
|
+
param :name, String
|
21
|
+
end
|
22
|
+
def update; end
|
23
|
+
|
24
|
+
api! 'Delete a footgun.'
|
25
|
+
api_version '2.0' # forces removal of the method description
|
26
|
+
def destroy; end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -3,6 +3,6 @@ class ConcernsController < ApplicationController
|
|
3
3
|
resource_description { resource_id 'concern_resources' }
|
4
4
|
|
5
5
|
apipie_concern_subst(:concern => 'user', :custom_subst => 'custom', 'string_subst' => 'string')
|
6
|
-
include
|
6
|
+
include SampleController
|
7
7
|
|
8
8
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class IncludedParamGroupController < ApplicationController
|
2
|
+
include RandomParamGroup
|
3
|
+
|
4
|
+
api :GET, '/included-param-group'
|
5
|
+
returns code:200 do
|
6
|
+
property :top_level, Array, of: Hash do
|
7
|
+
param_group :random_param_group
|
8
|
+
end
|
9
|
+
property :nested, Hash do
|
10
|
+
property :random_array, Array, of: Hash do
|
11
|
+
param_group :random_param_group
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
@@ -3,7 +3,7 @@ class OverriddenConcernsController < ApplicationController
|
|
3
3
|
resource_description { resource_id 'overridden_concern_resources' }
|
4
4
|
|
5
5
|
apipie_concern_subst(:concern => 'user')
|
6
|
-
include
|
6
|
+
include SampleController
|
7
7
|
|
8
8
|
def_param_group :concern do
|
9
9
|
param :concern, String
|
@@ -11,7 +11,7 @@ class OverriddenConcernsController < ApplicationController
|
|
11
11
|
|
12
12
|
api :PUT, '/:resource_id/:id'
|
13
13
|
param :custom_parameter, String, "New parameter added by the overriding method"
|
14
|
-
param_group :concern,
|
14
|
+
param_group :concern, SampleController
|
15
15
|
def update
|
16
16
|
super
|
17
17
|
end
|
@@ -23,8 +23,8 @@ class PetsController < ApplicationController
|
|
23
23
|
#-----------------------------------------------------------
|
24
24
|
api :GET, "/pets/:id/as_properties", "Get a pet record"
|
25
25
|
returns :code => 200 do
|
26
|
-
property :pet_name, String, :desc => "Name of pet", :required => false
|
27
|
-
property :animal_type, [
|
26
|
+
property :pet_name, String, :desc => "Name of pet", :required => false, :example => 'mypet'
|
27
|
+
property :animal_type, %w[dog cat iguana kangaroo], :desc => "Type of pet" # required by default, because this is a 'property'
|
28
28
|
end
|
29
29
|
returns :code => 404 do
|
30
30
|
property :another_error_message, String, :desc => "Overriding the response description from the Pets resource"
|
@@ -40,7 +40,7 @@ class PetsController < ApplicationController
|
|
40
40
|
#-----------------------------------------------------------
|
41
41
|
def_param_group :pet do
|
42
42
|
property :pet_name, String, :desc => "Name of pet", :required => false
|
43
|
-
property :animal_type, [
|
43
|
+
property :animal_type, %w[dog cat iguana kangaroo], :desc => "Type of pet" # required by default, because this is a 'property'
|
44
44
|
end
|
45
45
|
|
46
46
|
api :GET, "/pets/:id/as_param_group_of_properties", "Get a pet record"
|
@@ -70,7 +70,7 @@ class PetsController < ApplicationController
|
|
70
70
|
param :pet_id, Integer, :desc => "id of pet", :required => true
|
71
71
|
param :pet_name, String, :desc => "Name of pet", :required => false, :only_in => :response
|
72
72
|
param :partial_match_allowed, [true, false], :desc => "Partial match allowed?", :required => false, :only_in => :request
|
73
|
-
property :animal_type, [
|
73
|
+
property :animal_type, %w[dog cat iguana kangaroo], :desc => "Type of pet" # this is implicitly :only_in => :response
|
74
74
|
end
|
75
75
|
|
76
76
|
api :GET, "/pets/pet_by_id", "Get a pet record with the pet id in the body of the request"
|
@@ -142,7 +142,7 @@ class PetsController < ApplicationController
|
|
142
142
|
end
|
143
143
|
returns :code => 204 do
|
144
144
|
property :int_array, :array_of => Integer
|
145
|
-
property :enum_array, :array_of => [
|
145
|
+
property :enum_array, :array_of => %w[v1 v2 v3]
|
146
146
|
end
|
147
147
|
returns :code => :unprocessable_entity, :desc => "Fleas were discovered on the pet" do
|
148
148
|
param_group :pet
|
@@ -14,7 +14,7 @@ class Pet
|
|
14
14
|
def self.describe_own_properties
|
15
15
|
[
|
16
16
|
Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
|
17
|
-
Apipie::prop(:animal_type, 'string', {:description => 'Type of pet', :values => [
|
17
|
+
Apipie::prop(:animal_type, 'string', {:description => 'Type of pet', :values => %w[dog cat iguana kangaroo]}),
|
18
18
|
Apipie::additional_properties(false)
|
19
19
|
]
|
20
20
|
end
|
@@ -27,7 +27,7 @@ class PetWithMeasurements
|
|
27
27
|
def self.describe_own_properties
|
28
28
|
[
|
29
29
|
Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
|
30
|
-
Apipie::prop('animal_type', 'string', {:description => 'Type of pet', :values => [
|
30
|
+
Apipie::prop('animal_type', 'string', {:description => 'Type of pet', :values => %w[dog cat iguana kangaroo]}),
|
31
31
|
Apipie::prop(:pet_measurements, 'object', {}, [
|
32
32
|
Apipie::prop(:weight, 'number', {:description => "Weight in pounds" }),
|
33
33
|
Apipie::prop(:height, 'number', {:description => "Height in inches" }),
|
@@ -31,7 +31,7 @@ class TwitterExampleController < ApplicationController
|
|
31
31
|
|
32
32
|
api :GET, '/twitter_example/profile_image/:screen_name', 'Access the profile image in various sizes for the user with the indicated screen_name.'
|
33
33
|
param :screen_name, String, :required => true, :desc => 'The screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.'
|
34
|
-
param :size, [
|
34
|
+
param :size, %w[bigger normal mini original], :desc => <<-EOS
|
35
35
|
Specifies the size of image to fetch. Not specifying a size will give the default, normal size of 48px by 48px. Valid options include:
|
36
36
|
|
37
37
|
* bigger - 73px by 73px
|
@@ -166,7 +166,7 @@ class TwitterExampleController < ApplicationController
|
|
166
166
|
param :user_id, Integer, :desc => 'The ID of the user for whom to return results for. Helpful for disambiguating when a valid user ID is also a valid screen name.'
|
167
167
|
param :screen_name, String, :desc => 'The screen name of the user for whom to return results for. Helpful for disambiguating when a valid screen name is also a user ID.'
|
168
168
|
param :include_entities, String
|
169
|
-
param :skip_status, [
|
169
|
+
param :skip_status, %w[t true 1],
|
170
170
|
:description => 'When set to either true, t or 1 statuses will not be included in the returned user objects.'
|
171
171
|
|
172
172
|
description "Look at examples."
|
@@ -4,7 +4,7 @@ class UsersController < ApplicationController
|
|
4
4
|
short 'Site members'
|
5
5
|
path '/users'
|
6
6
|
formats ['json']
|
7
|
-
param :id,
|
7
|
+
param :id, Integer, :desc => "User ID", :required => false
|
8
8
|
param :legacy_param, Hash, :desc => 'Deprecated parameter not documented', :show => false, :required => false do
|
9
9
|
param :resource_param, Hash, :desc => 'Param description for all methods' do
|
10
10
|
param :ausername, String, :desc => "Username for login", :required => true
|
@@ -170,14 +170,14 @@ class UsersController < ApplicationController
|
|
170
170
|
eos
|
171
171
|
api :GET, "/users/:id", "Show user profile"
|
172
172
|
show false
|
173
|
-
formats [
|
173
|
+
formats %w[json jsonp]
|
174
174
|
error 401, "Unauthorized"
|
175
175
|
error :code => 404, :description => "Not Found"
|
176
176
|
param :id, Integer, :desc => "user id", :required => true
|
177
177
|
param :session, String, :desc => "user is logged in", :required => true, :missing_message => lambda { "session_parameter_is_required" }
|
178
178
|
param :regexp_param, /^[0-9]* years/, :desc => "regexp param"
|
179
179
|
param :regexp2, /\b[A-Z0-9._%+-=]+@[A-Z0-9.-]+.[A-Z]{2,}\b/i, :desc => "email regexp"
|
180
|
-
param :array_param, [
|
180
|
+
param :array_param, %w[100 one two 1 2], :desc => "array validator"
|
181
181
|
param :boolean_param, [true, false], :desc => "array validator with boolean"
|
182
182
|
param :proc_param, lambda { |val|
|
183
183
|
val == "param value" ? true : "The only good value is 'param value'."
|
@@ -211,7 +211,7 @@ class UsersController < ApplicationController
|
|
211
211
|
def_param_group :user do
|
212
212
|
param :user, Hash, :desc => "User info", :required => true, :action_aware => true do
|
213
213
|
param_group :credentials
|
214
|
-
param :membership, [
|
214
|
+
param :membership, %w[standard premium], :desc => "User membership", :allow_nil => false
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -269,11 +269,17 @@ class UsersController < ApplicationController
|
|
269
269
|
end
|
270
270
|
|
271
271
|
api :GET, '/users/by_department', 'show users from a specific department'
|
272
|
-
param :department, [
|
272
|
+
param :department, %w[finance operations sales marketing HR], required: false, default_value: "sales"
|
273
273
|
def get_by_department
|
274
274
|
render :plain => 'nothing to see here'
|
275
275
|
end
|
276
276
|
|
277
|
+
api :GET, '/users/in_departments', 'show users from specific departments'
|
278
|
+
param :departments, Array, in: %w[finance operations sales marketing HR], default_value: ['sales']
|
279
|
+
def get_in_departments
|
280
|
+
render :plain => 'nothing to see here'
|
281
|
+
end
|
282
|
+
|
277
283
|
api :GET, '/users/desc_from_file', 'desc from file'
|
278
284
|
document 'users/desc_from_file.md'
|
279
285
|
def desc_from_file
|
@@ -295,4 +301,10 @@ class UsersController < ApplicationController
|
|
295
301
|
header :HeaderNameWithDefaultValue, 'Header with default value', required: true, default: 'default value'
|
296
302
|
def action_with_headers
|
297
303
|
end
|
304
|
+
|
305
|
+
api :GET, '/users/multiple_required_params'
|
306
|
+
param :required_param1, String, required: true
|
307
|
+
param :required_param2, String, required: true
|
308
|
+
def multiple_required_params
|
309
|
+
end
|
298
310
|
end
|
@@ -1,10 +1,7 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('boot', __dir__)
|
2
2
|
|
3
|
-
require "active_model/railtie"
|
4
|
-
require "active_record/railtie"
|
5
3
|
require "action_controller/railtie"
|
6
4
|
require "action_view/railtie"
|
7
|
-
require "action_mailer/railtie"
|
8
5
|
|
9
6
|
Bundler.require
|
10
7
|
require "apipie-rails"
|
@@ -44,7 +41,7 @@ module Dummy
|
|
44
41
|
config.filter_parameters += [:password]
|
45
42
|
|
46
43
|
config.to_prepare do
|
47
|
-
ExtendedController.send(:include,
|
44
|
+
ExtendedController.send(:include, ExtendingConcern)
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
gemfile = File.expand_path('
|
2
|
+
gemfile = File.expand_path('../../../Gemfile', __dir__)
|
3
3
|
|
4
4
|
if File.exist?(gemfile)
|
5
5
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
@@ -7,4 +7,4 @@ if File.exist?(gemfile)
|
|
7
7
|
Bundler.setup
|
8
8
|
end
|
9
9
|
|
10
|
-
$:.unshift File.expand_path('
|
10
|
+
$:.unshift File.expand_path('../../../lib', __dir__)
|