apipie-rails 0.9.1 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop-challenger.yml +1 -1
- data/.github/workflows/rubocop.yml +20 -0
- data/.rubocop.yml +81 -0
- data/.rubocop_todo.yml +815 -351
- data/CHANGELOG.md +17 -0
- data/README.rst +20 -0
- data/apipie-rails.gemspec +4 -0
- data/app/controllers/apipie/apipies_controller.rb +5 -6
- 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 +7 -0
- data/lib/apipie/apipie_module.rb +2 -2
- data/lib/apipie/application.rb +10 -12
- data/lib/apipie/configuration.rb +24 -13
- data/lib/apipie/dsl_definition.rb +13 -12
- data/lib/apipie/error_description.rb +2 -2
- data/lib/apipie/extractor/recorder.rb +1 -1
- data/lib/apipie/extractor/writer.rb +11 -11
- data/lib/apipie/extractor.rb +1 -1
- data/lib/apipie/generator/swagger/context.rb +27 -0
- data/lib/apipie/generator/swagger/operation_id.rb +51 -0
- data/lib/apipie/generator/swagger/param_description/builder.rb +105 -0
- data/lib/apipie/generator/swagger/param_description/composite.rb +111 -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/type.rb +108 -0
- data/lib/apipie/generator/swagger/param_description.rb +18 -0
- data/lib/apipie/generator/swagger/type_extractor.rb +2 -2
- data/lib/apipie/markup.rb +9 -8
- data/lib/apipie/method_description.rb +4 -5
- data/lib/apipie/param_description/deprecation.rb +24 -0
- data/lib/apipie/param_description.rb +45 -18
- data/lib/apipie/resource_description.rb +4 -4
- data/lib/apipie/response_description.rb +2 -2
- data/lib/apipie/response_description_adapter.rb +7 -5
- data/lib/apipie/swagger_generator.rb +54 -202
- data/lib/apipie/validator.rb +8 -9
- data/lib/apipie/version.rb +1 -1
- data/lib/apipie-rails.rb +10 -0
- data/lib/tasks/apipie.rake +6 -6
- data/spec/controllers/users_controller_spec.rb +11 -3
- data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +2 -2
- data/spec/lib/{application_spec.rb → apipie/application_spec.rb} +6 -3
- data/spec/lib/apipie/configuration_spec.rb +23 -0
- data/spec/lib/apipie/extractor/recorder_spec.rb +40 -0
- data/spec/lib/apipie/generator/swagger/context_spec.rb +35 -0
- data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
- data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +163 -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 +178 -0
- data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
- data/spec/lib/{generator → apipie/generator}/swagger/type_extractor_spec.rb +38 -18
- data/spec/lib/{method_description_spec.rb → apipie/method_description_spec.rb} +4 -4
- data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
- data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +81 -1
- data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +5 -5
- data/spec/lib/{resource_description_spec.rb → apipie/resource_description_spec.rb} +2 -2
- data/spec/lib/swagger/swagger_dsl_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +85 -19
- /data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +0 -0
- /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
- /data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +0 -0
- /data/spec/lib/{extractor → apipie}/extractor_spec.rb +0 -0
- /data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/warning_spec.rb +0 -0
- /data/spec/lib/{generator → apipie/generator}/swagger/warning_writer_spec.rb +0 -0
- /data/spec/lib/{method_description → apipie/method_description}/apis_service_spec.rb +0 -0
- /data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +0 -0
- /data/spec/{controllers → test_engine}/memes_controller_spec.rb +0 -0
@@ -107,9 +107,10 @@ module Apipie
|
|
107
107
|
|
108
108
|
def add_sub_property(prop_desc)
|
109
109
|
raise "Only properties with expected_type 'object' can have sub-properties" unless @expected_type == 'object'
|
110
|
-
|
110
|
+
case prop_desc
|
111
|
+
when PropDesc
|
111
112
|
@sub_properties << prop_desc
|
112
|
-
|
113
|
+
when Modifier
|
113
114
|
prop_desc.apply(self)
|
114
115
|
else
|
115
116
|
raise "Unrecognized prop_desc type (#{prop_desc.class})"
|
@@ -130,7 +131,7 @@ module Apipie
|
|
130
131
|
attr_reader :name, :required, :expected_type, :options, :description
|
131
132
|
attr_accessor :additional_properties
|
132
133
|
|
133
|
-
|
134
|
+
alias desc description
|
134
135
|
|
135
136
|
def is_array?
|
136
137
|
@is_array
|
@@ -170,9 +171,10 @@ module Apipie
|
|
170
171
|
end
|
171
172
|
|
172
173
|
def add(prop_desc)
|
173
|
-
|
174
|
+
case prop_desc
|
175
|
+
when PropDesc
|
174
176
|
@property_descs << prop_desc
|
175
|
-
|
177
|
+
when Modifier
|
176
178
|
prop_desc.apply(self)
|
177
179
|
else
|
178
180
|
raise "Unrecognized prop_desc type (#{prop_desc.class})"
|
@@ -36,7 +36,6 @@ module Apipie
|
|
36
36
|
def generate_from_resources(version, resources, method_name, lang, clear_warnings=false)
|
37
37
|
init_swagger_vars(version, lang, clear_warnings)
|
38
38
|
|
39
|
-
@lang = lang
|
40
39
|
@only_method = method_name
|
41
40
|
add_resources(resources)
|
42
41
|
|
@@ -143,13 +142,6 @@ module Apipie
|
|
143
142
|
warn(Apipie::Generator::Swagger::Warning::NO_RETURN_CODES_SPECIFIED_CODE)
|
144
143
|
end
|
145
144
|
|
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
145
|
def warn_optional_param_in_path(param_name)
|
154
146
|
warn(
|
155
147
|
Apipie::Generator::Swagger::Warning::OPTIONAL_PARAM_IN_PATH_CODE,
|
@@ -261,7 +253,7 @@ module Apipie
|
|
261
253
|
warning_tags = []
|
262
254
|
end
|
263
255
|
|
264
|
-
op_id =
|
256
|
+
op_id = Apipie::Generator::Swagger::OperationId.from(api).to_s
|
265
257
|
|
266
258
|
include_op_id_in_computed_interface_id(op_id)
|
267
259
|
|
@@ -275,7 +267,7 @@ module Apipie
|
|
275
267
|
summary: Apipie.app.translate(api.short_description, @current_lang),
|
276
268
|
parameters: swagger_params_array_for_method(ruby_method, api.path),
|
277
269
|
responses: responses,
|
278
|
-
description: ruby_method.full_description
|
270
|
+
description: Apipie.app.translate(ruby_method.full_description, @current_lang)
|
279
271
|
}
|
280
272
|
|
281
273
|
if methods[method_key][:summary].nil?
|
@@ -283,6 +275,7 @@ module Apipie
|
|
283
275
|
warn_missing_method_summary
|
284
276
|
end
|
285
277
|
end
|
278
|
+
|
286
279
|
end
|
287
280
|
|
288
281
|
#--------------------------------------------------------------------------
|
@@ -308,16 +301,6 @@ module Apipie
|
|
308
301
|
remove_colons method.resource.controller.name + "::" + method.method
|
309
302
|
end
|
310
303
|
|
311
|
-
def swagger_id_for_typename(typename)
|
312
|
-
typename
|
313
|
-
end
|
314
|
-
|
315
|
-
def swagger_op_id_for_path(http_method, path)
|
316
|
-
# using lowercase http method, because the 'swagger-codegen' tool outputs
|
317
|
-
# strange method names if the http method is in uppercase
|
318
|
-
http_method.downcase + path.gsub(/\//,'_').gsub(/:(\w+)/, '\1').gsub(/_$/,'')
|
319
|
-
end
|
320
|
-
|
321
304
|
def swagger_param_type(param_desc)
|
322
305
|
if param_desc.blank?
|
323
306
|
raise ArgumentError, 'param_desc is required'
|
@@ -343,11 +326,10 @@ module Apipie
|
|
343
326
|
def json_schema_for_method_response(method, return_code, allow_nulls)
|
344
327
|
@definitions = {}
|
345
328
|
for response in method.returns
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
end
|
329
|
+
next unless response.code.to_s == return_code.to_s
|
330
|
+
schema = response_schema(response, allow_nulls)
|
331
|
+
schema[:definitions] = @definitions if @definitions != {}
|
332
|
+
return schema
|
351
333
|
end
|
352
334
|
nil
|
353
335
|
end
|
@@ -364,9 +346,22 @@ module Apipie
|
|
364
346
|
@disable_default_value_warning = true
|
365
347
|
|
366
348
|
if responses_use_reference? && response.typename
|
367
|
-
schema = {
|
349
|
+
schema = {
|
350
|
+
"$ref" => gen_referenced_block_from_params_array(
|
351
|
+
response.typename,
|
352
|
+
response.params_ordered,
|
353
|
+
allow_nulls
|
354
|
+
)
|
355
|
+
}
|
368
356
|
else
|
369
|
-
schema =
|
357
|
+
schema = Apipie::Generator::Swagger::ParamDescription::Composite.new(
|
358
|
+
response.params_ordered,
|
359
|
+
Apipie::Generator::Swagger::Context.new(
|
360
|
+
allow_null: allow_nulls,
|
361
|
+
http_method: @current_http_method,
|
362
|
+
controller_method: @current_method
|
363
|
+
)
|
364
|
+
).to_swagger
|
370
365
|
end
|
371
366
|
|
372
367
|
ensure
|
@@ -397,7 +392,7 @@ module Apipie
|
|
397
392
|
|
398
393
|
for response in method.returns
|
399
394
|
swagger_response_block = {
|
400
|
-
description: response.description
|
395
|
+
description: Apipie.app.translate(response.description, @current_lang)
|
401
396
|
}
|
402
397
|
|
403
398
|
schema = response_schema(response)
|
@@ -434,105 +429,14 @@ module Apipie
|
|
434
429
|
|
435
430
|
missing.each do |name|
|
436
431
|
warn_path_parameter_not_described(name, path)
|
437
|
-
result[name.to_sym] = OpenStruct.new({
|
438
|
-
required: true,
|
439
|
-
_gen_added_from_path: true,
|
440
|
-
name: name,
|
441
|
-
validator: Apipie::Validator::NumberValidator.new(nil),
|
442
|
-
options: {
|
443
|
-
in: "path"
|
444
|
-
}
|
445
|
-
})
|
446
|
-
end
|
447
|
-
|
448
|
-
result
|
449
|
-
end
|
450
|
-
|
451
|
-
#--------------------------------------------------------------------------
|
452
|
-
# The core routine for creating a swagger parameter definition block.
|
453
|
-
# The output is slightly different when the parameter is inside a schema block.
|
454
|
-
#--------------------------------------------------------------------------
|
455
|
-
def swagger_atomic_param(param_desc, in_schema, name, allow_nulls)
|
456
|
-
def save_field(entry, openapi_key, v, apipie_key=openapi_key, translate=false)
|
457
|
-
if v.key?(apipie_key)
|
458
|
-
if translate
|
459
|
-
entry[openapi_key] = Apipie.app.translate(v[apipie_key], @current_lang)
|
460
|
-
else
|
461
|
-
entry[openapi_key] = v[apipie_key]
|
462
|
-
end
|
463
|
-
end
|
464
|
-
end
|
465
|
-
|
466
|
-
swagger_def = {}
|
467
|
-
swagger_def[:name] = name if !name.nil?
|
468
|
-
|
469
|
-
swg_param_type = swagger_param_type(param_desc)
|
470
|
-
swagger_def[:type] = swg_param_type.to_s
|
471
|
-
if (swg_param_type.is_a? Apipie::Generator::Swagger::Type) && !swg_param_type.str_format.nil?
|
472
|
-
swagger_def[:format] = swg_param_type.str_format
|
473
|
-
end
|
474
|
-
|
475
|
-
if swagger_def[:type] == "array"
|
476
|
-
array_of_validator_opts = param_desc.validator.param_description.options
|
477
|
-
items_type = array_of_validator_opts[:of].to_s || array_of_validator_opts[:array_of].to_s
|
478
|
-
if items_type == "Hash"
|
479
|
-
ref_name = "#{swagger_op_id_for_path(param_desc.method_description.apis.first.http_method, param_desc.method_description.apis.first.path)}_param_#{param_desc.name}"
|
480
|
-
swagger_def[:items] = {"$ref" => gen_referenced_block_from_params_array(ref_name, param_desc.validator.param_description.validator.params_ordered, allow_nulls)}
|
481
|
-
else
|
482
|
-
swagger_def[:items] = {type: "string"}
|
483
|
-
end
|
484
|
-
|
485
|
-
enum = param_desc.options.fetch(:in, [])
|
486
|
-
swagger_def[:items][:enum] = enum if enum.any?
|
487
|
-
end
|
488
|
-
|
489
|
-
if swagger_def[:type] == "enum"
|
490
|
-
swagger_def[:type] = "string"
|
491
|
-
swagger_def[:enum] = param_desc.validator.values
|
492
|
-
end
|
493
432
|
|
494
|
-
|
495
|
-
|
496
|
-
warn_hash_without_internal_typespec(param_desc.name)
|
433
|
+
result[name.to_sym] = Apipie::Generator::Swagger::ParamDescription.
|
434
|
+
create_for_missing_param(method, name)
|
497
435
|
end
|
498
436
|
|
499
|
-
|
500
|
-
new_swagger_def = {
|
501
|
-
items: swagger_def,
|
502
|
-
type: 'array'
|
503
|
-
}
|
504
|
-
swagger_def = new_swagger_def
|
505
|
-
if allow_nulls
|
506
|
-
swagger_def[:type] = [swagger_def[:type], "null"]
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
|
-
if allow_nulls
|
511
|
-
swagger_def[:type] = [swagger_def[:type], "null"]
|
512
|
-
end
|
513
|
-
|
514
|
-
if !in_schema
|
515
|
-
# the "name" and "in" keys can only be set on root parameters (non-nested)
|
516
|
-
swagger_def[:in] = @default_value_for_param_in if name.present?
|
517
|
-
swagger_def[:required] = param_desc.required if param_desc.required
|
518
|
-
end
|
519
|
-
|
520
|
-
save_field(swagger_def, :description, param_desc.options, :desc, true) unless param_desc.options[:desc].nil?
|
521
|
-
save_field(swagger_def, :default, param_desc.options, :default_value)
|
522
|
-
|
523
|
-
if param_desc.respond_to?(:_gen_added_from_path) && !param_desc.required
|
524
|
-
warn_optional_param_in_path(param_desc.name)
|
525
|
-
swagger_def[:required] = true
|
526
|
-
end
|
527
|
-
|
528
|
-
if !swagger_def[:required] && !swagger_def.key?(:default)
|
529
|
-
warn_optional_without_default_value(param_desc.name) unless @disable_default_value_warning
|
530
|
-
end
|
531
|
-
|
532
|
-
swagger_def
|
437
|
+
result
|
533
438
|
end
|
534
439
|
|
535
|
-
|
536
440
|
#--------------------------------------------------------------------------
|
537
441
|
# JSON schema and referenced-object generation
|
538
442
|
#--------------------------------------------------------------------------
|
@@ -541,79 +445,24 @@ module Apipie
|
|
541
445
|
"#/definitions/#{name}"
|
542
446
|
end
|
543
447
|
|
544
|
-
|
545
|
-
def json_schema_obj_from_params_array(params_array, allow_nulls = false)
|
546
|
-
(param_defs, required_params) = json_schema_param_defs_from_params_array(params_array, allow_nulls)
|
547
|
-
|
548
|
-
result = {type: "object"}
|
549
|
-
result[:properties] = param_defs
|
550
|
-
result[:additionalProperties] = false unless Apipie.configuration.swagger_allow_additional_properties_in_response
|
551
|
-
result[:required] = required_params if required_params.length > 0
|
552
|
-
|
553
|
-
param_defs.length > 0 ? result : nil
|
554
|
-
end
|
555
|
-
|
556
448
|
def gen_referenced_block_from_params_array(name, params_array, allow_nulls=false)
|
557
449
|
return ref_to(:name) if @definitions.key(:name)
|
558
450
|
|
559
|
-
schema_obj =
|
451
|
+
schema_obj = Apipie::Generator::Swagger::ParamDescription::Composite.new(
|
452
|
+
params_array,
|
453
|
+
Apipie::Generator::Swagger::Context.new(
|
454
|
+
allow_null: allow_nulls,
|
455
|
+
http_method: @current_http_method,
|
456
|
+
controller_method: @current_method
|
457
|
+
)
|
458
|
+
).to_swagger
|
459
|
+
|
560
460
|
return nil if schema_obj.nil?
|
561
461
|
|
562
462
|
@definitions[name.to_sym] = schema_obj
|
563
463
|
ref_to(name.to_sym)
|
564
464
|
end
|
565
465
|
|
566
|
-
def json_schema_param_defs_from_params_array(params_array, allow_nulls = false)
|
567
|
-
param_defs = {}
|
568
|
-
required_params = []
|
569
|
-
|
570
|
-
params_array ||= []
|
571
|
-
|
572
|
-
|
573
|
-
for param_desc in params_array
|
574
|
-
if !param_desc.respond_to?(:required)
|
575
|
-
# pp param_desc
|
576
|
-
raise ("unexpected param_desc format")
|
577
|
-
end
|
578
|
-
|
579
|
-
required_params.push(param_desc.name.to_sym) if param_desc.required
|
580
|
-
|
581
|
-
param_type = swagger_param_type(param_desc)
|
582
|
-
|
583
|
-
if param_type == "object" && param_desc.validator.params_ordered
|
584
|
-
schema = json_schema_obj_from_params_array(param_desc.validator.params_ordered, allow_nulls)
|
585
|
-
if param_desc.additional_properties
|
586
|
-
schema[:additionalProperties] = true
|
587
|
-
end
|
588
|
-
|
589
|
-
if param_desc.is_array?
|
590
|
-
new_schema = {
|
591
|
-
type: 'array',
|
592
|
-
items: schema
|
593
|
-
}
|
594
|
-
schema = new_schema
|
595
|
-
end
|
596
|
-
|
597
|
-
if allow_nulls
|
598
|
-
# ideally we would write schema[:type] = ["object", "null"]
|
599
|
-
# but due to a bug in the json-schema gem, we need to use anyOf
|
600
|
-
# see https://github.com/ruby-json-schema/json-schema/issues/404
|
601
|
-
new_schema = {
|
602
|
-
anyOf: [schema, {type: "null"}]
|
603
|
-
}
|
604
|
-
schema = new_schema
|
605
|
-
end
|
606
|
-
param_defs[param_desc.name.to_sym] = schema if !schema.nil?
|
607
|
-
else
|
608
|
-
param_defs[param_desc.name.to_sym] = swagger_atomic_param(param_desc, true, nil, allow_nulls)
|
609
|
-
end
|
610
|
-
end
|
611
|
-
|
612
|
-
[param_defs, required_params]
|
613
|
-
end
|
614
|
-
|
615
|
-
|
616
|
-
|
617
466
|
#--------------------------------------------------------------------------
|
618
467
|
# swagger "Params" block generation
|
619
468
|
#--------------------------------------------------------------------------
|
@@ -638,7 +487,15 @@ module Apipie
|
|
638
487
|
if params_in_body_use_reference?
|
639
488
|
swagger_schema_for_body = {"$ref" => gen_referenced_block_from_params_array("#{swagger_op_id_for_method(method)}_input", body_param_defs_array)}
|
640
489
|
else
|
641
|
-
swagger_schema_for_body =
|
490
|
+
swagger_schema_for_body =
|
491
|
+
Apipie::Generator::Swagger::ParamDescription::Composite.new(
|
492
|
+
body_param_defs_array,
|
493
|
+
Apipie::Generator::Swagger::Context.new(
|
494
|
+
allow_null: false,
|
495
|
+
http_method: @current_http_method,
|
496
|
+
controller_method: @current_method
|
497
|
+
)
|
498
|
+
).to_swagger
|
642
499
|
end
|
643
500
|
|
644
501
|
swagger_body_param = {
|
@@ -675,20 +532,7 @@ module Apipie
|
|
675
532
|
|
676
533
|
|
677
534
|
def add_params_from_hash(swagger_params_array, param_defs, prefix=nil, default_value_for_in=nil)
|
678
|
-
|
679
|
-
if default_value_for_in
|
680
|
-
@default_value_for_param_in = default_value_for_in
|
681
|
-
else
|
682
|
-
if body_allowed_for_current_method
|
683
|
-
@default_value_for_param_in = "formData"
|
684
|
-
else
|
685
|
-
@default_value_for_param_in = "query"
|
686
|
-
end
|
687
|
-
end
|
688
|
-
|
689
|
-
|
690
535
|
param_defs.each do |name, desc|
|
691
|
-
|
692
536
|
if !prefix.nil?
|
693
537
|
name = "#{prefix}[#{name}]"
|
694
538
|
end
|
@@ -701,13 +545,21 @@ module Apipie
|
|
701
545
|
warn_param_ignored_in_form_data(desc.name)
|
702
546
|
end
|
703
547
|
else
|
704
|
-
param_entry =
|
548
|
+
param_entry = Apipie::Generator::Swagger::ParamDescription::Builder.
|
549
|
+
new(desc, in_schema: false, controller_method: @current_method).
|
550
|
+
with_description(language: @current_lang).
|
551
|
+
with_name(prefix: prefix).
|
552
|
+
with_type(with_null: @allow_null).
|
553
|
+
with_in(
|
554
|
+
http_method: @current_http_method,
|
555
|
+
default_in_value: default_value_for_in
|
556
|
+
).to_swagger
|
557
|
+
|
705
558
|
if param_entry[:required]
|
706
559
|
swagger_params_array.unshift(param_entry)
|
707
560
|
else
|
708
561
|
swagger_params_array.push(param_entry)
|
709
562
|
end
|
710
|
-
|
711
563
|
end
|
712
564
|
end
|
713
565
|
end
|
data/lib/apipie/validator.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
|
2
3
|
module Apipie
|
3
4
|
|
4
5
|
module Validator
|
@@ -344,14 +345,12 @@ module Apipie
|
|
344
345
|
|
345
346
|
def validate(value)
|
346
347
|
return false if !value.is_a? Hash
|
347
|
-
|
348
|
-
|
349
|
-
if
|
350
|
-
|
351
|
-
|
352
|
-
if
|
353
|
-
p.validate(value[k]) if value.has_key?(k)
|
354
|
-
end
|
348
|
+
@hash_params&.each do |k, p|
|
349
|
+
if Apipie.configuration.validate_presence?
|
350
|
+
raise ParamMissing.new(p) if p.required && !value.key?(k)
|
351
|
+
end
|
352
|
+
if Apipie.configuration.validate_value?
|
353
|
+
p.validate(value[k]) if value.key?(k)
|
355
354
|
end
|
356
355
|
end
|
357
356
|
return true
|
@@ -360,7 +359,7 @@ module Apipie
|
|
360
359
|
def process_value(value)
|
361
360
|
if @hash_params && value
|
362
361
|
return @hash_params.each_with_object({}) do |(key, param), api_params|
|
363
|
-
if value.
|
362
|
+
if value.key?(key)
|
364
363
|
api_params[param.as] = param.process_value(value[key])
|
365
364
|
end
|
366
365
|
end
|
data/lib/apipie/version.rb
CHANGED
data/lib/apipie-rails.rb
CHANGED
@@ -12,6 +12,7 @@ require "apipie/configuration"
|
|
12
12
|
require "apipie/method_description"
|
13
13
|
require "apipie/resource_description"
|
14
14
|
require "apipie/param_description"
|
15
|
+
require "apipie/param_description/deprecation"
|
15
16
|
require "apipie/method_description/api"
|
16
17
|
require "apipie/method_description/apis_service"
|
17
18
|
require "apipie/errors"
|
@@ -27,7 +28,16 @@ require "apipie/version"
|
|
27
28
|
require "apipie/swagger_generator"
|
28
29
|
require "apipie/generator/generator"
|
29
30
|
require "apipie/generator/swagger/swagger"
|
31
|
+
require "apipie/generator/swagger/operation_id"
|
30
32
|
require "apipie/generator/swagger/warning"
|
31
33
|
require "apipie/generator/swagger/warning_writer"
|
32
34
|
require "apipie/generator/swagger/type"
|
33
35
|
require "apipie/generator/swagger/type_extractor"
|
36
|
+
require "apipie/generator/swagger/context"
|
37
|
+
require "apipie/generator/swagger/param_description"
|
38
|
+
require "apipie/generator/swagger/param_description/builder"
|
39
|
+
require "apipie/generator/swagger/param_description/composite"
|
40
|
+
require "apipie/generator/swagger/param_description/description"
|
41
|
+
require "apipie/generator/swagger/param_description/in"
|
42
|
+
require "apipie/generator/swagger/param_description/name"
|
43
|
+
require "apipie/generator/swagger/param_description/type"
|
data/lib/tasks/apipie.rake
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
|
2
3
|
require 'fileutils'
|
3
4
|
|
4
5
|
namespace :apipie do
|
@@ -150,12 +151,11 @@ namespace :apipie do
|
|
150
151
|
doc[:docs][:link_extension] = (lang ? ".#{lang}.html" : ".html")
|
151
152
|
|
152
153
|
generate_index_page(file_base_version, doc, true, true, lang) if generate_index
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
154
|
+
next unless generate_resources
|
155
|
+
Apipie.url_prefix = "../#{subdir_traversal_prefix}#{subdir}"
|
156
|
+
generate_resource_pages(version, file_base_version, doc, true, lang)
|
157
|
+
Apipie.url_prefix = "../../#{subdir_traversal_prefix}#{subdir}"
|
158
|
+
generate_method_pages(version, file_base_version, doc, true, lang)
|
159
159
|
end
|
160
160
|
end
|
161
161
|
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
|
@@ -268,6 +269,7 @@ describe UsersController do
|
|
268
269
|
:allow_blank => false,
|
269
270
|
:metadata => nil,
|
270
271
|
:show => true,
|
272
|
+
:deprecated => false,
|
271
273
|
:expected_type => "hash",
|
272
274
|
:validations => [])
|
273
275
|
end
|
@@ -584,6 +586,7 @@ describe UsersController do
|
|
584
586
|
:description=>"\n<p>Authorization</p>\n",
|
585
587
|
:name=>"oauth",
|
586
588
|
:show=>true,
|
589
|
+
:deprecated=>false,
|
587
590
|
:expected_type=>"string"},
|
588
591
|
{:validator=>"Must be a Hash",
|
589
592
|
:description=>"\n<p>Deprecated parameter not documented</p>\n",
|
@@ -594,15 +597,17 @@ describe UsersController do
|
|
594
597
|
:required=>false,
|
595
598
|
:full_name=>"legacy_param",
|
596
599
|
:show=>false,
|
600
|
+
:deprecated=>false,
|
597
601
|
:params=>
|
598
602
|
[{:validator=>"Must be a Hash",
|
599
603
|
:description=>"\n<p>Param description for all methods</p>\n",
|
600
604
|
:expected_type=>"hash",
|
601
605
|
:allow_nil=>false,
|
602
|
-
|
606
|
+
:allow_blank => false,
|
603
607
|
:name=>"resource_param",
|
604
608
|
:required=>false,
|
605
609
|
:full_name=>"resource_param",
|
610
|
+
:deprecated=>false,
|
606
611
|
:show=>true,
|
607
612
|
:params=>
|
608
613
|
[{:required=>true,
|
@@ -612,6 +617,7 @@ describe UsersController do
|
|
612
617
|
:description=>"\n<p>Username for login</p>\n",
|
613
618
|
:name=>"ausername", :full_name=>"resource_param[ausername]",
|
614
619
|
:show=>true,
|
620
|
+
:deprecated=>false,
|
615
621
|
:expected_type=>"string"},
|
616
622
|
{:required=>true,
|
617
623
|
:allow_nil => false,
|
@@ -620,6 +626,7 @@ describe UsersController do
|
|
620
626
|
:description=>"\n<p>Password for login</p>\n",
|
621
627
|
:name=>"apassword", :full_name=>"resource_param[apassword]",
|
622
628
|
:show=>true,
|
629
|
+
:deprecated=>false,
|
623
630
|
:expected_type=>"string"}
|
624
631
|
]}
|
625
632
|
]
|
@@ -630,6 +637,7 @@ describe UsersController do
|
|
630
637
|
:description=>"\n<p>Company ID</p>\n",
|
631
638
|
:name=>"id", :full_name=>"id",
|
632
639
|
:show=>true,
|
640
|
+
:deprecated=>false,
|
633
641
|
:expected_type=>"numeric"},
|
634
642
|
],
|
635
643
|
:name => 'two_urls',
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'fileutils'
|
3
3
|
require "json-schema"
|
4
4
|
|
5
|
-
describe Apipie::ApipiesController do
|
5
|
+
describe Apipie::ApipiesController, type: :controller do
|
6
6
|
|
7
7
|
describe "GET index" do
|
8
8
|
|
@@ -159,7 +159,7 @@ describe Apipie::ApipiesController do
|
|
159
159
|
describe "GET index as swagger" do
|
160
160
|
|
161
161
|
let(:swagger_schema) do
|
162
|
-
File.read(
|
162
|
+
File.read("#{Rails.root.parent}/lib/swagger/openapi_2_0_schema.json")
|
163
163
|
end
|
164
164
|
|
165
165
|
it "outputs swagger when format is json and type is swagger" do
|
@@ -3,7 +3,10 @@ require "spec_helper"
|
|
3
3
|
describe Apipie::Application do
|
4
4
|
|
5
5
|
describe "api_controllers_paths" do
|
6
|
-
before
|
6
|
+
before do
|
7
|
+
Apipie.configuration.api_controllers_matcher = [File.join(Rails.root, "app", "controllers", "**","*.rb"),
|
8
|
+
File.join(Rails.root, "lib", "**","*.rb")]
|
9
|
+
end
|
7
10
|
|
8
11
|
it "should support receiving array as parameter" do
|
9
12
|
expect { Apipie.api_controllers_paths}.
|
@@ -19,11 +22,11 @@ describe Apipie::Application do
|
|
19
22
|
context "with namespaced_resources enabled" do
|
20
23
|
before { Apipie.configuration.namespaced_resources = true }
|
21
24
|
context "with a defined base url" do
|
22
|
-
|
25
|
+
|
23
26
|
it "should not overwrite the parent resource" do
|
24
27
|
is_expected.not_to eq(Apipie.get_resource_name(Api::V2::ArchitecturesController))
|
25
28
|
end
|
26
|
-
|
29
|
+
|
27
30
|
end
|
28
31
|
|
29
32
|
context "with an undefined base url" do
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'Apipie::Configuration' do
|
6
|
+
let(:configuration) { Apipie::Configuration.new }
|
7
|
+
|
8
|
+
describe '#api_action_matcher=' do
|
9
|
+
subject(:setter) { configuration.api_action_matcher = matcher }
|
10
|
+
|
11
|
+
let(:matcher) { proc { |_| :some_action } }
|
12
|
+
|
13
|
+
it { is_expected.to eq(matcher) }
|
14
|
+
|
15
|
+
context 'when matcher does not implement .call method' do
|
16
|
+
let(:matcher) { 'I do not implement .call' }
|
17
|
+
|
18
|
+
it 'raises and exception' do
|
19
|
+
expect { setter }.to raise_error('Must implement .call method')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'Apipie::Extractor::Recorder' do
|
6
|
+
let(:recorder) { Apipie::Extractor::Recorder.new }
|
7
|
+
|
8
|
+
describe '#analyse_controller' do
|
9
|
+
subject do
|
10
|
+
recorder.analyse_controller(controller)
|
11
|
+
recorder.record[:action]
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:action) { :show }
|
15
|
+
|
16
|
+
let(:request) do
|
17
|
+
request = ActionDispatch::Request.new({})
|
18
|
+
request.request_parameters = { action: action }
|
19
|
+
request
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:controller) do
|
23
|
+
controller = ActionController::Metal.new
|
24
|
+
controller.set_request!(request)
|
25
|
+
controller
|
26
|
+
end
|
27
|
+
|
28
|
+
it { is_expected.to eq(action) }
|
29
|
+
|
30
|
+
context 'when a api_action_matcher is configured' do
|
31
|
+
let(:matcher_action) { "#{action}_from_new_matcher" }
|
32
|
+
|
33
|
+
before do
|
34
|
+
Apipie.configuration.api_action_matcher = proc { |_| matcher_action }
|
35
|
+
end
|
36
|
+
|
37
|
+
it { is_expected.to eq(matcher_action) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|