apipie-rails 0.8.2 → 0.9.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 +4 -4
- data/.github/workflows/build.yml +7 -0
- data/.github/workflows/rubocop-challenger.yml +28 -0
- data/.rubocop.yml +37 -0
- data/.rubocop_todo.yml +1991 -0
- data/CHANGELOG.md +19 -0
- data/README.rst +4 -4
- data/Rakefile +0 -5
- data/apipie-rails.gemspec +10 -7
- data/app/controllers/apipie/apipies_controller.rb +1 -1
- data/lib/apipie/application.rb +4 -4
- data/lib/apipie/dsl_definition.rb +4 -4
- data/lib/apipie/extractor/writer.rb +4 -4
- data/lib/apipie/generator/generator.rb +2 -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 +70 -0
- data/lib/apipie/generator/swagger/warning.rb +77 -0
- data/lib/apipie/generator/swagger/warning_writer.rb +48 -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 +3 -48
- data/lib/apipie/resource_description.rb +1 -1
- data/lib/apipie/swagger_generator.rb +76 -81
- data/lib/apipie/validator.rb +4 -0
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +9 -1
- data/lib/generators/apipie/install/install_generator.rb +1 -1
- data/lib/generators/apipie/views_generator.rb +1 -1
- data/lib/tasks/apipie.rake +4 -4
- data/spec/controllers/apipies_controller_spec.rb +2 -2
- data/spec/controllers/users_controller_spec.rb +1 -1
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/controllers/users_controller.rb +1 -1
- data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/initializers/apipie.rb +2 -2
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/script/rails +2 -2
- data/spec/lib/application_spec.rb +1 -1
- data/spec/lib/extractor/writer_spec.rb +8 -6
- data/spec/lib/generator/swagger/type_extractor_spec.rb +61 -0
- data/spec/lib/generator/swagger/warning_spec.rb +51 -0
- data/spec/lib/generator/swagger/warning_writer_spec.rb +59 -0
- data/spec/lib/method_description/apis_service_spec.rb +60 -0
- data/spec/lib/param_description_spec.rb +4 -4
- data/spec/lib/rake_spec.rb +2 -4
- data/spec/lib/swagger/rake_swagger_spec.rb +4 -4
- data/spec/lib/validator_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -4
- metadata +39 -38
@@ -128,33 +128,75 @@ module Apipie
|
|
128
128
|
method.resource.controller.name + "#" + method.method
|
129
129
|
end
|
130
130
|
|
131
|
+
def warn_missing_method_summary
|
132
|
+
warn(Apipie::Generator::Swagger::Warning::MISSING_METHOD_SUMMARY_CODE)
|
133
|
+
end
|
131
134
|
|
132
|
-
def
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
def warn_param_ignored_in_form_data(param_name) warn 106,"ignoring param :#{param_name} -- cannot include Hash without fields in a formData specification"; end
|
139
|
-
def warn_path_parameter_not_described(name,path) warn 107,"the parameter :#{name} appears in the path #{path} but is not described"; end
|
140
|
-
def warn_inferring_boolean(name) warn 108,"the parameter [#{name}] is Enum with [true,false] values. Inferring 'boolean'"; end
|
141
|
-
|
142
|
-
def warn(warning_num, msg)
|
143
|
-
suppress = Apipie.configuration.swagger_suppress_warnings
|
144
|
-
return if suppress == true
|
145
|
-
return if suppress.is_a?(Array) && suppress.include?(warning_num)
|
135
|
+
def warn_added_missing_slash(path)
|
136
|
+
warn(
|
137
|
+
Apipie::Generator::Swagger::Warning::ADDED_MISSING_SLASH_CODE,
|
138
|
+
{ path: path }
|
139
|
+
)
|
140
|
+
end
|
146
141
|
|
147
|
-
|
148
|
-
|
142
|
+
def warn_no_return_codes_specified
|
143
|
+
warn(Apipie::Generator::Swagger::Warning::NO_RETURN_CODES_SPECIFIED_CODE)
|
144
|
+
end
|
149
145
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
146
|
+
def warn_hash_without_internal_typespec(param_name)
|
147
|
+
warn(
|
148
|
+
Apipie::Generator::Swagger::Warning::HASH_WITHOUT_INTERNAL_TYPESPEC_CODE,
|
149
|
+
{ parameter: param_name }
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
def warn_optional_param_in_path(param_name)
|
154
|
+
warn(
|
155
|
+
Apipie::Generator::Swagger::Warning::OPTIONAL_PARAM_IN_PATH_CODE,
|
156
|
+
{ parameter: param_name }
|
157
|
+
)
|
158
|
+
end
|
159
|
+
|
160
|
+
def warn_optional_without_default_value(param_name)
|
161
|
+
warn(
|
162
|
+
Apipie::Generator::Swagger::Warning::OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE,
|
163
|
+
{ parameter: param_name }
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
def warn_param_ignored_in_form_data(param_name)
|
168
|
+
warn(
|
169
|
+
Apipie::Generator::Swagger::Warning::PARAM_IGNORED_IN_FORM_DATA_CODE,
|
170
|
+
{ parameter: param_name }
|
171
|
+
)
|
172
|
+
end
|
173
|
+
|
174
|
+
def warn_path_parameter_not_described(name, path)
|
175
|
+
warn(
|
176
|
+
Apipie::Generator::Swagger::Warning::PATH_PARAM_NOT_DESCRIBED_CODE,
|
177
|
+
{ name: name, path: path }
|
178
|
+
)
|
179
|
+
end
|
154
180
|
|
155
|
-
|
156
|
-
|
157
|
-
|
181
|
+
def warn_inferring_boolean(name)
|
182
|
+
warn(
|
183
|
+
Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
|
184
|
+
{ name: name }
|
185
|
+
)
|
186
|
+
end
|
187
|
+
|
188
|
+
# @param [Integer] warning_code
|
189
|
+
# @param [Hash] message_attributes
|
190
|
+
def warn(warning_code, message_attributes = {})
|
191
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
192
|
+
warning_code,
|
193
|
+
ruby_name_for_method(@current_method),
|
194
|
+
message_attributes
|
195
|
+
).warn_through_writer
|
196
|
+
|
197
|
+
@warnings_issued = Apipie::Generator::Swagger::WarningWriter.
|
198
|
+
instance.
|
199
|
+
issued_warnings?
|
158
200
|
end
|
159
201
|
|
160
202
|
def info(msg)
|
@@ -276,68 +318,21 @@ module Apipie
|
|
276
318
|
http_method.downcase + path.gsub(/\//,'_').gsub(/:(\w+)/, '\1').gsub(/_$/,'')
|
277
319
|
end
|
278
320
|
|
279
|
-
class SwaggerTypeWithFormat
|
280
|
-
attr_reader :str_format
|
281
|
-
def initialize(type, str_format)
|
282
|
-
@type = type
|
283
|
-
@str_format = str_format
|
284
|
-
end
|
285
|
-
|
286
|
-
def to_s
|
287
|
-
@type
|
288
|
-
end
|
289
|
-
|
290
|
-
def ==(other)
|
291
|
-
other.to_s == self.to_s
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
def lookup
|
296
|
-
@lookup ||= {
|
297
|
-
numeric: "number",
|
298
|
-
hash: "object",
|
299
|
-
array: "array",
|
300
|
-
|
301
|
-
# see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
|
302
|
-
integer: SwaggerTypeWithFormat.new("integer", "int32"),
|
303
|
-
long: SwaggerTypeWithFormat.new("integer", "int64"),
|
304
|
-
number: SwaggerTypeWithFormat.new("number", nil), # here just for completeness
|
305
|
-
float: SwaggerTypeWithFormat.new("number", "float"),
|
306
|
-
double: SwaggerTypeWithFormat.new("number", "double"),
|
307
|
-
string: SwaggerTypeWithFormat.new("string", nil), # here just for completeness
|
308
|
-
byte: SwaggerTypeWithFormat.new("string", "byte"),
|
309
|
-
binary: SwaggerTypeWithFormat.new("string", "binary"),
|
310
|
-
boolean: SwaggerTypeWithFormat.new("boolean", nil), # here just for completeness
|
311
|
-
date: SwaggerTypeWithFormat.new("string", "date"),
|
312
|
-
dateTime: SwaggerTypeWithFormat.new("string", "date-time"),
|
313
|
-
password: SwaggerTypeWithFormat.new("string", "password"),
|
314
|
-
}
|
315
|
-
end
|
316
|
-
|
317
|
-
|
318
321
|
def swagger_param_type(param_desc)
|
319
|
-
if param_desc.
|
320
|
-
raise
|
321
|
-
end
|
322
|
-
|
323
|
-
v = param_desc.validator
|
324
|
-
if v.nil?
|
325
|
-
return "string"
|
322
|
+
if param_desc.blank?
|
323
|
+
raise ArgumentError, 'param_desc is required'
|
326
324
|
end
|
327
325
|
|
328
|
-
|
329
|
-
if v.values - [true, false] == [] && [true, false] - v.values == []
|
330
|
-
warn_inferring_boolean(param_desc.name)
|
331
|
-
return "boolean"
|
332
|
-
else
|
333
|
-
return "enum"
|
334
|
-
end
|
335
|
-
elsif v.class == Apipie::Validator::HashValidator
|
336
|
-
# pp v
|
337
|
-
end
|
326
|
+
method_id = ruby_name_for_method(@current_method)
|
338
327
|
|
328
|
+
warning = Apipie::Generator::Swagger::Warning.for_code(
|
329
|
+
Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
|
330
|
+
method_id,
|
331
|
+
{ parameter: param_desc.name }
|
332
|
+
)
|
339
333
|
|
340
|
-
|
334
|
+
Apipie::Generator::Swagger::TypeExtractor.new(param_desc.validator).
|
335
|
+
extract_with_warnings({ boolean: warning })
|
341
336
|
end
|
342
337
|
|
343
338
|
|
@@ -473,7 +468,7 @@ module Apipie
|
|
473
468
|
|
474
469
|
swg_param_type = swagger_param_type(param_desc)
|
475
470
|
swagger_def[:type] = swg_param_type.to_s
|
476
|
-
if (swg_param_type.is_a?
|
471
|
+
if (swg_param_type.is_a? Apipie::Generator::Swagger::Type) && !swg_param_type.str_format.nil?
|
477
472
|
swagger_def[:format] = swg_param_type.str_format
|
478
473
|
end
|
479
474
|
|
data/lib/apipie/validator.rb
CHANGED
data/lib/apipie/version.rb
CHANGED
data/lib/apipie-rails.rb
CHANGED
@@ -2,7 +2,7 @@ require 'i18n'
|
|
2
2
|
require 'json'
|
3
3
|
require 'active_support/hash_with_indifferent_access'
|
4
4
|
|
5
|
-
require 'apipie/core_ext/route
|
5
|
+
require 'apipie/core_ext/route'
|
6
6
|
|
7
7
|
require "apipie/routing"
|
8
8
|
require "apipie/markup"
|
@@ -12,6 +12,8 @@ require "apipie/configuration"
|
|
12
12
|
require "apipie/method_description"
|
13
13
|
require "apipie/resource_description"
|
14
14
|
require "apipie/param_description"
|
15
|
+
require "apipie/method_description/api"
|
16
|
+
require "apipie/method_description/apis_service"
|
15
17
|
require "apipie/errors"
|
16
18
|
require "apipie/error_description"
|
17
19
|
require "apipie/response_description"
|
@@ -23,3 +25,9 @@ require "apipie/railtie"
|
|
23
25
|
require 'apipie/extractor'
|
24
26
|
require "apipie/version"
|
25
27
|
require "apipie/swagger_generator"
|
28
|
+
require "apipie/generator/generator"
|
29
|
+
require "apipie/generator/swagger/swagger"
|
30
|
+
require "apipie/generator/swagger/warning"
|
31
|
+
require "apipie/generator/swagger/warning_writer"
|
32
|
+
require "apipie/generator/swagger/type"
|
33
|
+
require "apipie/generator/swagger/type_extractor"
|
data/lib/tasks/apipie.rake
CHANGED
@@ -85,7 +85,7 @@ namespace :apipie do
|
|
85
85
|
counter = 1
|
86
86
|
make_reference = true
|
87
87
|
else
|
88
|
-
reference_files.sort_by!
|
88
|
+
reference_files.sort_by!(&:ctime)
|
89
89
|
last_ref = reference_files[-1]
|
90
90
|
print "Comparing [#{path}] to reference file: [#{last_ref.basename}]: "
|
91
91
|
if !FileUtils.compare_file(path, last_ref)
|
@@ -108,7 +108,7 @@ namespace :apipie do
|
|
108
108
|
|
109
109
|
num_refs_to_keep = 3
|
110
110
|
if reference_files.length > num_refs_to_keep
|
111
|
-
(reference_files - reference_files[-num_refs_to_keep..-1]).each
|
111
|
+
(reference_files - reference_files[-num_refs_to_keep..-1]).each(&:delete)
|
112
112
|
end
|
113
113
|
}
|
114
114
|
end
|
@@ -166,10 +166,10 @@ namespace :apipie do
|
|
166
166
|
def renderer
|
167
167
|
return @apipie_renderer if @apipie_renderer
|
168
168
|
|
169
|
-
base_paths = [File.expand_path(
|
169
|
+
base_paths = [File.expand_path('../../app/views/apipie/apipies', __dir__)]
|
170
170
|
base_paths.unshift("#{Rails.root}/app/views/apipie/apipies") if File.directory?("#{Rails.root}/app/views/apipie/apipies")
|
171
171
|
|
172
|
-
layouts_paths = [File.expand_path(
|
172
|
+
layouts_paths = [File.expand_path('../../app/views/layouts', __dir__)]
|
173
173
|
layouts_paths.unshift("#{Rails.root}/app/views/layouts") if File.directory?("#{Rails.root}/app/views/layouts/apipie")
|
174
174
|
|
175
175
|
if ActionView::Base.respond_to?(:with_empty_template_cache) && ActionView::Base.respond_to?(:with_view_paths)
|
@@ -253,7 +253,7 @@ describe Apipie::ApipiesController do
|
|
253
253
|
let(:cache_dir) { File.join(Rails.root, "tmp", "apipie-cache") }
|
254
254
|
|
255
255
|
before do
|
256
|
-
FileUtils.rm_r(cache_dir) if File.
|
256
|
+
FileUtils.rm_r(cache_dir) if File.exist?(cache_dir)
|
257
257
|
FileUtils.mkdir_p(File.join(cache_dir, "apidoc", "v1", "resource"))
|
258
258
|
File.open(File.join(cache_dir, "apidoc", "v1.html"), "w") { |f| f << "apidoc.html cache v1" }
|
259
259
|
File.open(File.join(cache_dir, "apidoc", "v2.html"), "w") { |f| f << "apidoc.html cache v2" }
|
@@ -272,7 +272,7 @@ describe Apipie::ApipiesController do
|
|
272
272
|
Apipie.configuration.use_cache = false
|
273
273
|
Apipie.configuration.default_version = @orig_version
|
274
274
|
Apipie.configuration.cache_dir = @orig_cache_dir
|
275
|
-
# FileUtils.rm_r(cache_dir) if File.
|
275
|
+
# FileUtils.rm_r(cache_dir) if File.exist?(cache_dir)
|
276
276
|
end
|
277
277
|
|
278
278
|
it "uses the file in cache dir instead of generating the content on runtime" do
|
@@ -51,7 +51,7 @@ describe UsersController do
|
|
51
51
|
expect(subject._params_args.count).to eq(2)
|
52
52
|
name, type, options = subject._params_args.first
|
53
53
|
expect(name).to eq(:id)
|
54
|
-
expect(type).to eq(
|
54
|
+
expect(type).to eq(Integer)
|
55
55
|
expect(options).to eq({:required=>false, :desc=>"User ID"})
|
56
56
|
end
|
57
57
|
end
|
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
|
@@ -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
|
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__)
|
@@ -23,7 +23,7 @@ Apipie.configure do |config|
|
|
23
23
|
# rake apipie:cache
|
24
24
|
#
|
25
25
|
config.use_cache = Rails.env.production?
|
26
|
-
|
26
|
+
config.cache_dir = File.join(Rails.root, "tmp", "apipie-cache") # optional
|
27
27
|
|
28
28
|
# set to enable/disable reloading controllers (and the documentation with it),
|
29
29
|
# by default enabled in development
|
@@ -89,7 +89,7 @@ class Apipie::Validator::IntegerValidator < Apipie::Validator::BaseValidator
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def self.build(param_description, argument, options, block)
|
92
|
-
if argument == Integer
|
92
|
+
if argument == Integer
|
93
93
|
self.new(param_description, argument)
|
94
94
|
end
|
95
95
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
data/spec/dummy/config.ru
CHANGED
data/spec/dummy/script/rails
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
3
|
|
4
|
-
APP_PATH = File.expand_path('
|
5
|
-
require File.expand_path('
|
4
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
5
|
+
require File.expand_path('../config/boot', __dir__)
|
6
6
|
require 'rails/commands'
|
@@ -27,7 +27,7 @@ describe Apipie::Application do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
context "with an undefined base url" do
|
30
|
-
before {allow(Apipie.app).to receive(:get_base_url)
|
30
|
+
before {allow(Apipie.app).to receive(:get_base_url).and_return(nil)}
|
31
31
|
|
32
32
|
it "should not raise an error" do
|
33
33
|
expect { Apipie.get_resource_name(Api::V2::ArchitecturesController) }.
|
@@ -6,7 +6,8 @@ describe Apipie::Extractor::Writer do
|
|
6
6
|
let(:writer_class) { Apipie::Extractor::Writer }
|
7
7
|
let(:writer) { writer_class.new(collector) }
|
8
8
|
let(:test_examples_file) { File.join(Rails.root, "doc", "apipie_examples_test.json") }
|
9
|
-
let(:records) {
|
9
|
+
let(:records) {
|
10
|
+
{
|
10
11
|
"concern_resources#show" =>
|
11
12
|
[{
|
12
13
|
:controller=>ConcernsController,
|
@@ -31,7 +32,8 @@ describe Apipie::Extractor::Writer do
|
|
31
32
|
}]
|
32
33
|
}
|
33
34
|
}
|
34
|
-
let(:loaded_records) {
|
35
|
+
let(:loaded_records) {
|
36
|
+
{
|
35
37
|
"concern_resources#show" =>
|
36
38
|
[{
|
37
39
|
"verb"=>:GET,
|
@@ -57,16 +59,16 @@ describe Apipie::Extractor::Writer do
|
|
57
59
|
}
|
58
60
|
}
|
59
61
|
|
60
|
-
context 'with doc_path
|
62
|
+
context 'with doc_path overridden in configuration' do
|
61
63
|
around(:each) do |example|
|
62
64
|
standard_path = Apipie.configuration.doc_path
|
63
|
-
Apipie.configuration.doc_path = 'user_specified_doc_path'
|
65
|
+
Apipie.configuration.doc_path = 'tmp/user_specified_doc_path'
|
64
66
|
example.run
|
65
67
|
Apipie.configuration.doc_path = standard_path
|
66
68
|
end
|
67
69
|
|
68
70
|
it 'should use the doc_path specified in configuration' do
|
69
|
-
expect(writer_class.examples_file).to eql(File.join(Rails.root, 'user_specified_doc_path', 'apipie_examples.json'))
|
71
|
+
expect(writer_class.examples_file).to eql(File.join(Rails.root, 'tmp', 'user_specified_doc_path', 'apipie_examples.json'))
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
@@ -104,7 +106,7 @@ describe Apipie::Extractor::Writer do
|
|
104
106
|
end
|
105
107
|
|
106
108
|
after do
|
107
|
-
File.unlink(test_examples_file) if File.
|
109
|
+
File.unlink(test_examples_file) if File.exist?(test_examples_file)
|
108
110
|
end
|
109
111
|
end
|
110
112
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apipie::Generator::Swagger::TypeExtractor do
|
4
|
+
let(:validator) {}
|
5
|
+
let(:extractor) { described_class.new(validator) }
|
6
|
+
|
7
|
+
describe '#extarct_with_warnings' do
|
8
|
+
let(:warnings) { {} }
|
9
|
+
|
10
|
+
before { Apipie.configuration.swagger_suppress_warnings = false }
|
11
|
+
|
12
|
+
subject { extractor.extract_with_warnings(warnings) }
|
13
|
+
|
14
|
+
it { is_expected.to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:string]) }
|
15
|
+
|
16
|
+
context "when enum validator is used" do
|
17
|
+
let(:enum_values) { ["Name"] }
|
18
|
+
|
19
|
+
context "of type Apipie::Validator::EnumValidator" do
|
20
|
+
let(:validator) { Apipie::Validator::EnumValidator.new(nil, enum_values) }
|
21
|
+
|
22
|
+
it { is_expected.to eq("enum") }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "that responds to is_enum?" do
|
26
|
+
let(:validator) do
|
27
|
+
Apipie::ResponseDescriptionAdapter::PropDesc::Validator.new('some-type', enum_values)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns an enum type' do
|
31
|
+
expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:enum])
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'and has `true`, `false` as values' do
|
35
|
+
let(:param_description_name) { :visible }
|
36
|
+
let(:enum_values) { [true, false] }
|
37
|
+
|
38
|
+
it 'returns a boolean type' do
|
39
|
+
expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:boolean])
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'and a boolean warning is passed' do
|
43
|
+
let(:boolean_warning) do
|
44
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
45
|
+
Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
|
46
|
+
'SampleController#action',
|
47
|
+
{ parameter: 'some-param' }
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:warnings) { { boolean: boolean_warning } }
|
52
|
+
|
53
|
+
it 'outputs the warning' do
|
54
|
+
expect { subject }.to output(boolean_warning.warning_message).to_stderr
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Apipie::Generator::Swagger::Warning do
|
4
|
+
let(:code) { Apipie::Generator::Swagger::Warning::MISSING_METHOD_SUMMARY_CODE }
|
5
|
+
let(:method_id) { 'Examples#index' }
|
6
|
+
let(:info_message) { 'Something went wrong' }
|
7
|
+
|
8
|
+
let(:warning) { described_class.new(code, info_message, method_id) }
|
9
|
+
|
10
|
+
describe '#id' do
|
11
|
+
subject { warning.id }
|
12
|
+
|
13
|
+
it { is_expected.to eq("#{method_id}#{code}#{info_message}") }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#warning_message' do
|
17
|
+
subject { warning.warning_message }
|
18
|
+
|
19
|
+
it { is_expected.to eq("WARNING (#{code}): [#{method_id}] -- #{info_message}") }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#warn' do
|
23
|
+
subject { warning.warn }
|
24
|
+
|
25
|
+
it 'outputs the warning' do
|
26
|
+
expect { subject }.to output(warning.warning_message).to_stderr
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#warn_through_writer' do
|
31
|
+
subject { warning.warn }
|
32
|
+
|
33
|
+
it 'outputs the warning' do
|
34
|
+
expect { subject }.to output(warning.warning_message).to_stderr
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.for_code' do
|
39
|
+
subject { described_class.for_code(code, method_id) }
|
40
|
+
|
41
|
+
it { is_expected.to be_an_instance_of(described_class)}
|
42
|
+
|
43
|
+
context 'when code is invalid' do
|
44
|
+
let(:code) { 12345 }
|
45
|
+
|
46
|
+
it 'raises an argument error' do
|
47
|
+
expect { subject }.to raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apipie::Generator::Swagger::WarningWriter do
|
4
|
+
let(:writer) { described_class.clone.instance }
|
5
|
+
|
6
|
+
let(:warning) do
|
7
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
8
|
+
Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
|
9
|
+
'SampleController#action',
|
10
|
+
{ parameter: 'some-param' }
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
Apipie.configuration.swagger_suppress_warnings = false
|
16
|
+
Singleton.__init__(described_class)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#warn' do
|
20
|
+
subject { writer.warn(warning) }
|
21
|
+
|
22
|
+
it 'outputs the warning' do
|
23
|
+
expect { subject }.to output(warning.warning_message).to_stderr
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when Apipie.configuration.swagger_suppress_warnings is true' do
|
27
|
+
before { Apipie.configuration.swagger_suppress_warnings = true }
|
28
|
+
|
29
|
+
it { is_expected.to be_falsey }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when Apipie.configuration.swagger_suppress_warnings includes warning code' do
|
33
|
+
before do
|
34
|
+
Apipie.configuration.swagger_suppress_warnings =
|
35
|
+
Array(Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE)
|
36
|
+
end
|
37
|
+
|
38
|
+
it { is_expected.to be_falsey }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when a warning already been logged' do
|
42
|
+
before { writer.warn(warning) }
|
43
|
+
|
44
|
+
it { is_expected.to be_falsey }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#issued_warnings?' do
|
49
|
+
subject { writer.issued_warnings? }
|
50
|
+
|
51
|
+
it { is_expected.to be_falsey }
|
52
|
+
|
53
|
+
context 'when a warning already been logged' do
|
54
|
+
before { writer.warn(warning) }
|
55
|
+
|
56
|
+
it { is_expected.to be_truthy }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|