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
data/spec/lib/rake_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe 'rake tasks' do
|
4
4
|
include_context "rake"
|
5
5
|
|
6
|
-
let(:doc_path) {
|
6
|
+
let(:doc_path) { 'tmp/user_specified_doc_path' }
|
7
7
|
|
8
8
|
before do
|
9
9
|
Apipie.configuration.doc_path = doc_path
|
@@ -18,7 +18,7 @@ describe 'rake tasks' do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
let(:doc_output) do
|
21
|
-
File.join(
|
21
|
+
File.join(Rails.root, doc_path, 'apidoc')
|
22
22
|
end
|
23
23
|
|
24
24
|
after do
|
@@ -49,9 +49,7 @@ describe 'rake tasks' do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe 'apipie:cache' do
|
52
|
-
let(:cache_output)
|
53
|
-
File.join(::Rails.root, 'public', 'apipie-cache')
|
54
|
-
end
|
52
|
+
let(:cache_output) { Apipie.configuration.cache_dir }
|
55
53
|
|
56
54
|
let(:apidoc_html) do
|
57
55
|
File.read("#{cache_output}.html")
|
@@ -996,7 +996,14 @@
|
|
996
996
|
"$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0"
|
997
997
|
},
|
998
998
|
"required": {
|
999
|
-
"
|
999
|
+
"anyOf": [
|
1000
|
+
{
|
1001
|
+
"$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
|
1002
|
+
},
|
1003
|
+
{
|
1004
|
+
"type": "boolean"
|
1005
|
+
}
|
1006
|
+
]
|
1000
1007
|
},
|
1001
1008
|
"enum": {
|
1002
1009
|
"$ref": "http://json-schema.org/draft-04/schema#/properties/enum"
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require "json-schema"
|
3
3
|
|
4
|
-
require File.expand_path(
|
5
|
-
require File.expand_path(
|
6
|
-
require File.expand_path(
|
4
|
+
require File.expand_path('../../dummy/app/controllers/twitter_example_controller.rb', __dir__)
|
5
|
+
require File.expand_path('../../dummy/app/controllers/users_controller.rb', __dir__)
|
6
|
+
require File.expand_path('../../dummy/app/controllers/pets_controller.rb', __dir__)
|
7
7
|
|
8
8
|
describe 'rake tasks' do
|
9
9
|
include_context "rake"
|
10
10
|
|
11
|
-
let(:doc_path) {
|
11
|
+
let(:doc_path) { 'tmp/user_specified_doc_path' }
|
12
12
|
|
13
13
|
before do
|
14
14
|
Apipie.configuration.doc_path = doc_path
|
15
|
-
Apipie.configuration.
|
15
|
+
Apipie.configuration.generator.swagger.suppress_warnings = true
|
16
16
|
allow(Apipie).to receive(:reload_documentation)
|
17
17
|
subject.invoke(*task_args)
|
18
18
|
end
|
@@ -37,11 +37,11 @@ describe 'rake tasks' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
let(:doc_output) do
|
40
|
-
File.join(
|
40
|
+
File.join(Rails.root, doc_path, 'apidoc')
|
41
41
|
end
|
42
42
|
|
43
43
|
let(:ref_output) do
|
44
|
-
File.join(
|
44
|
+
File.join(Rails.root, doc_path, 'apidoc_ref')
|
45
45
|
end
|
46
46
|
|
47
47
|
|
@@ -51,6 +51,17 @@ describe 'rake tasks' do
|
|
51
51
|
expect(param[field]).to eq(value)
|
52
52
|
end
|
53
53
|
|
54
|
+
def expect_array_param_def(http_method, path, param_name, value)
|
55
|
+
params = apidoc_swagger["paths"][path][http_method]["parameters"]
|
56
|
+
param = params.select { |p| p if p["name"] == param_name }[0]
|
57
|
+
|
58
|
+
expect(param['type']).to eq('array')
|
59
|
+
expect(param['items']).to eq(
|
60
|
+
'type' => 'string',
|
61
|
+
'enum' => value
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
54
65
|
def expect_tags_def(http_method, path, value)
|
55
66
|
params = apidoc_swagger["paths"][path][http_method]["tags"]
|
56
67
|
expect(params).to eq(value)
|
@@ -71,6 +82,10 @@ describe 'rake tasks' do
|
|
71
82
|
expect(param[field]).to eq(value)
|
72
83
|
end
|
73
84
|
|
85
|
+
def expect_response_params_def(http_method, path, response_code, param_name, field, value)
|
86
|
+
param = apidoc_swagger["paths"][path][http_method]["responses"][response_code.to_s]["schema"]["properties"][param_name]
|
87
|
+
expect(param[field]).to eq(value)
|
88
|
+
end
|
74
89
|
|
75
90
|
describe 'apipie:static_swagger_json[development,json,_tmp]' do
|
76
91
|
it "generates static swagger files for the default version of apipie docs" do
|
@@ -91,9 +106,10 @@ describe 'rake tasks' do
|
|
91
106
|
|
92
107
|
expect_param_def("get", "/users/by_department", "department", "in", "query")
|
93
108
|
expect_param_def("get", "/users/by_department", "department", "enum",
|
94
|
-
[
|
109
|
+
%w[finance operations sales marketing HR])
|
95
110
|
|
96
111
|
expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
|
112
|
+
expect_response_params_def("get", "/pets/{id}/as_properties", 200, "pet_name", "example", "mypet")
|
97
113
|
end
|
98
114
|
|
99
115
|
it "generates a valid swagger file" do
|
@@ -117,7 +133,11 @@ describe 'rake tasks' do
|
|
117
133
|
expect_param_def("put", "/users/{id}", "oauth", "in", "formData")
|
118
134
|
expect_param_def("get", "/users/by_department", "department", "in", "query")
|
119
135
|
expect_param_def("get", "/users/by_department", "department", "enum",
|
120
|
-
[
|
136
|
+
%w[finance operations sales marketing HR])
|
137
|
+
|
138
|
+
expect_param_def("get", "/users/in_departments", "departments", "in", "query")
|
139
|
+
expect_array_param_def("get", "/users/in_departments", "departments",
|
140
|
+
%w[finance operations sales marketing HR])
|
121
141
|
|
122
142
|
expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
|
123
143
|
|
@@ -131,7 +151,7 @@ describe 'rake tasks' do
|
|
131
151
|
|
132
152
|
describe 'apipie:did_swagger_change[development,form_data,_tmp]' do
|
133
153
|
it "keeps a reference file" do
|
134
|
-
expect(Pathname(ref_output).children.count).to eq(2)
|
154
|
+
expect(Pathname(ref_output).children.count).to eq(2) # one file for each language
|
135
155
|
end
|
136
156
|
end
|
137
157
|
end
|
@@ -6,7 +6,7 @@ describe "Swagger Responses" do
|
|
6
6
|
let(:desc) { Apipie.get_resource_description(controller_class, Apipie.configuration.default_version) }
|
7
7
|
|
8
8
|
let(:swagger) {
|
9
|
-
Apipie.configuration.
|
9
|
+
Apipie.configuration.generator.swagger.suppress_warnings = true
|
10
10
|
Apipie.to_swagger_json(Apipie.configuration.default_version, controller_class.to_s.underscore.sub("_controller", ""))
|
11
11
|
}
|
12
12
|
|
@@ -24,20 +24,20 @@ describe "Swagger Responses" do
|
|
24
24
|
schema
|
25
25
|
end
|
26
26
|
|
27
|
-
def swagger_response_for(path, code=200, method='get')
|
27
|
+
def swagger_response_for(path, code = 200, method = 'get')
|
28
28
|
response = swagger[:paths][path][method][:responses][code]
|
29
29
|
response[:schema] = resolve_refs(response[:schema])
|
30
30
|
response
|
31
31
|
end
|
32
32
|
|
33
|
-
def swagger_params_for(path, method='get')
|
33
|
+
def swagger_params_for(path, method = 'get')
|
34
34
|
swagger[:paths][path][method][:parameters]
|
35
35
|
end
|
36
36
|
|
37
|
-
def swagger_param_by_name(param_name, path, method='get')
|
37
|
+
def swagger_param_by_name(param_name, path, method = 'get')
|
38
38
|
params = swagger_params_for(path, method)
|
39
39
|
matching = params.select{|p| p[:name] == param_name }
|
40
|
-
raise "multiple params named [#{param_name}] in swagger definition for [#{method
|
40
|
+
raise "multiple params named [#{param_name}] in swagger definition for [#{method} #{path}]" if matching.length > 1
|
41
41
|
|
42
42
|
nil if matching.length == 0
|
43
43
|
|
@@ -72,7 +72,7 @@ describe "Swagger Responses" do
|
|
72
72
|
deep_match?(actual, expected)
|
73
73
|
end
|
74
74
|
|
75
|
-
def deep_match?(actual, expected, breadcrumb=[])
|
75
|
+
def deep_match?(actual, expected, breadcrumb = [])
|
76
76
|
pending_params = actual.params_ordered.dup
|
77
77
|
expected.each do |expected_param|
|
78
78
|
expected_param_name = expected_param.is_a?(Hash) ? expected_param.keys.first : expected_param
|
@@ -141,7 +141,7 @@ describe "Swagger Responses" do
|
|
141
141
|
|
142
142
|
a_schema = resolve_refs(schema[:items])
|
143
143
|
expect(a_schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
144
|
-
expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => [
|
144
|
+
expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
145
145
|
end
|
146
146
|
|
147
147
|
|
@@ -210,7 +210,7 @@ describe "Swagger Responses" do
|
|
210
210
|
|
211
211
|
schema = response[:schema]
|
212
212
|
expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
213
|
-
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => [
|
213
|
+
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
214
214
|
end
|
215
215
|
|
216
216
|
it 'should have the 404 response description overridden' do
|
@@ -247,7 +247,7 @@ describe "Swagger Responses" do
|
|
247
247
|
|
248
248
|
schema = response[:schema]
|
249
249
|
expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
250
|
-
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => [
|
250
|
+
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
@@ -282,7 +282,7 @@ describe "Swagger Responses" do
|
|
282
282
|
schema = response[:schema]
|
283
283
|
expect(schema).to have_field(:pet_id, 'number', {:description => 'id of pet'})
|
284
284
|
expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
285
|
-
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => [
|
285
|
+
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
286
286
|
expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false})
|
287
287
|
end
|
288
288
|
|
@@ -338,6 +338,7 @@ describe "Swagger Responses" do
|
|
338
338
|
|
339
339
|
expect(returns_obj).to match_field_structure([:pet_name, :animal_type])
|
340
340
|
end
|
341
|
+
|
341
342
|
it 'should have the 201 response described in the swagger' do
|
342
343
|
response = swagger_response_for('/pets/{id}/extra_info', 201)
|
343
344
|
expect(response[:description]).to eq("Found a pet")
|
@@ -359,6 +360,7 @@ describe "Swagger Responses" do
|
|
359
360
|
{:pet_measurements => [:weight, :height, :num_legs]}
|
360
361
|
])
|
361
362
|
end
|
363
|
+
|
362
364
|
it 'should have the 202 response described in the swagger' do
|
363
365
|
response = swagger_response_for('/pets/{id}/extra_info', 202)
|
364
366
|
expect(response[:description]).to eq('Accepted')
|
@@ -388,6 +390,7 @@ describe "Swagger Responses" do
|
|
388
390
|
{:additional_histories => [:did_visit_vet, :avg_meals_per_day]}
|
389
391
|
])
|
390
392
|
end
|
393
|
+
|
391
394
|
it 'should have the 203 response described in the swagger' do
|
392
395
|
response = swagger_response_for('/pets/{id}/extra_info', 203)
|
393
396
|
expect(response[:description]).to eq('Non-Authoritative Information')
|
@@ -424,12 +427,13 @@ describe "Swagger Responses" do
|
|
424
427
|
|
425
428
|
expect(returns_obj).to match_field_structure([:int_array, :enum_array])
|
426
429
|
end
|
430
|
+
|
427
431
|
it 'should have the 204 response described in the swagger' do
|
428
432
|
response = swagger_response_for('/pets/{id}/extra_info', 204)
|
429
433
|
|
430
434
|
schema = response[:schema]
|
431
435
|
expect(schema).to have_field(:int_array, 'array', {items: {type: 'number'}})
|
432
|
-
expect(schema).to have_field(:enum_array, 'array', {items: {type: 'string', enum: [
|
436
|
+
expect(schema).to have_field(:enum_array, 'array', {items: {type: 'string', enum: %w[v1 v2 v3]}})
|
433
437
|
end
|
434
438
|
|
435
439
|
|
@@ -444,6 +448,7 @@ describe "Swagger Responses" do
|
|
444
448
|
:num_fleas
|
445
449
|
])
|
446
450
|
end
|
451
|
+
|
447
452
|
it 'should have the 422 response described in the swagger' do
|
448
453
|
response = swagger_response_for('/pets/{id}/extra_info', 422)
|
449
454
|
expect(response[:description]).to eq('Fleas were discovered on the pet')
|
@@ -546,7 +551,7 @@ describe "Swagger Responses" do
|
|
546
551
|
|
547
552
|
a_schema = schema[:items]
|
548
553
|
expect(a_schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
|
549
|
-
expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => [
|
554
|
+
expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
|
550
555
|
end
|
551
556
|
end
|
552
557
|
|
@@ -568,6 +573,7 @@ describe "Swagger Responses" do
|
|
568
573
|
{:pet_measurements => [:weight, :height, :num_legs]}
|
569
574
|
])
|
570
575
|
end
|
576
|
+
|
571
577
|
it 'should have the 200 response described in the swagger' do
|
572
578
|
response = swagger_response_for('/pets_with_measurements_described_as_class/{id}', 200)
|
573
579
|
expect(response[:description]).to eq('measurements of the pet')
|
@@ -30,7 +30,7 @@ module Apipie::Validator
|
|
30
30
|
let(:type) { String }
|
31
31
|
|
32
32
|
it "accepts array of specified type" do
|
33
|
-
expect(validator.validate([
|
33
|
+
expect(validator.validate(%w[string1 string2])).to eq(true)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "accepts empty array" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,40 +1,19 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.minimum_coverage 91
|
6
|
+
SimpleCov.start
|
7
|
+
|
4
8
|
ENV["RAILS_ENV"] ||= 'test'
|
5
|
-
APIPIE_ROOT = File.expand_path('
|
6
|
-
require File.expand_path(
|
9
|
+
APIPIE_ROOT = File.expand_path('..', __dir__)
|
10
|
+
require File.expand_path('dummy/config/environment', __dir__)
|
7
11
|
|
8
12
|
require 'rspec/rails'
|
9
13
|
|
10
14
|
require 'apipie-rails'
|
11
15
|
require 'test_engine'
|
12
16
|
|
13
|
-
module Rails4Compatibility
|
14
|
-
module Testing
|
15
|
-
def process(*args)
|
16
|
-
compatible_request(*args) { |*new_args| super(*new_args) }
|
17
|
-
end
|
18
|
-
|
19
|
-
def compatible_request(method, action, hash = {})
|
20
|
-
if hash.is_a?(Hash)
|
21
|
-
if Gem::Version.new(Rails.version) < Gem::Version.new('5.0.0')
|
22
|
-
hash = hash.dup
|
23
|
-
hash.merge!(hash.delete(:params) || {})
|
24
|
-
elsif hash.key?(:params)
|
25
|
-
hash = { :params => hash }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
if hash.empty?
|
29
|
-
yield method, action
|
30
|
-
else
|
31
|
-
yield method, action, hash
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
17
|
#
|
39
18
|
# Matcher to validate the properties (name, type and options) of a single field in the
|
40
19
|
# internal representation of a swagger schema
|
@@ -45,7 +24,7 @@ end
|
|
45
24
|
#
|
46
25
|
# will verify that the selected response schema includes a required string field called 'pet_name'
|
47
26
|
#
|
48
|
-
RSpec::Matchers.define :have_field do |name, type, opts={}|
|
27
|
+
RSpec::Matchers.define :have_field do |name, type, opts = {}|
|
49
28
|
def fail(msg)
|
50
29
|
@fail_message = msg
|
51
30
|
false
|
@@ -76,14 +55,14 @@ end
|
|
76
55
|
|
77
56
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
78
57
|
# in spec/support/ and its subdirectories.
|
79
|
-
Dir[File.expand_path(
|
58
|
+
Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each {|f| require f}
|
80
59
|
|
81
60
|
RSpec.configure do |config|
|
82
61
|
|
83
62
|
config.mock_with :rspec
|
84
63
|
|
85
64
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
86
|
-
config.fixture_path = "#{
|
65
|
+
config.fixture_path = "#{Rails.root}/spec/fixtures"
|
87
66
|
|
88
67
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
89
68
|
# examples within a transaction, remove the following line or assign false
|
@@ -107,5 +86,4 @@ RSpec.configure do |config|
|
|
107
86
|
config.infer_spec_type_from_file_location!
|
108
87
|
end
|
109
88
|
|
110
|
-
require 'action_controller/test_case
|
111
|
-
ActionController::TestCase::Behavior.send(:prepend, Rails4Compatibility::Testing)
|
89
|
+
require 'action_controller/test_case'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CustomBoolValidator < Apipie::Validator::BaseValidator
|
2
|
+
def validate(value)
|
3
|
+
value.in?([true, false])
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.build(param_description, argument, options, block)
|
7
|
+
new(param_description) if argument == :custom_bool
|
8
|
+
end
|
9
|
+
|
10
|
+
def description
|
11
|
+
"Must be a boolean."
|
12
|
+
end
|
13
|
+
|
14
|
+
def ignore_allow_blank?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
@@ -4,7 +4,7 @@ describe TestEngine::MemesController do
|
|
4
4
|
|
5
5
|
describe "#index" do
|
6
6
|
it "should have the full mounted path of engine" do
|
7
|
-
Apipie.routes_for_action(TestEngine::MemesController, :index, {}).first[:path].
|
7
|
+
expect(Apipie.routes_for_action(TestEngine::MemesController, :index, {}).first[:path]).to eq("/test/memes")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|