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
@@ -0,0 +1,105 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::Builder
|
2
|
+
# @param [Apipie::ParamDescription] param_description
|
3
|
+
# @param [TrueClass, FalseClass] in_schema
|
4
|
+
# @param [String] controller_method
|
5
|
+
def initialize(param_description, in_schema:, controller_method:)
|
6
|
+
@param_description = param_description
|
7
|
+
@in_schema = in_schema
|
8
|
+
@controller_method = controller_method
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param [String, nil] prefix
|
12
|
+
def with_name(prefix: nil)
|
13
|
+
@name = Apipie::Generator::Swagger::ParamDescription::Name.
|
14
|
+
new(@param_description, prefixed_by: prefix)
|
15
|
+
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param [String] language
|
20
|
+
def with_description(language:)
|
21
|
+
@description = Apipie::Generator::Swagger::ParamDescription::Description.
|
22
|
+
new(@param_description, language: language)
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param [TrueClass, FalseClass] with_null
|
28
|
+
def with_type(with_null:)
|
29
|
+
@type = Apipie::Generator::Swagger::ParamDescription::Type.
|
30
|
+
new(@param_description, with_null: with_null, controller_method: @controller_method)
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def with_in(http_method:, default_in_value: nil)
|
36
|
+
@in = Apipie::Generator::Swagger::ParamDescription::In.new(
|
37
|
+
@param_description,
|
38
|
+
in_schema: @in_schema,
|
39
|
+
default_in_value: default_in_value,
|
40
|
+
http_method: http_method
|
41
|
+
)
|
42
|
+
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Hash]
|
47
|
+
def to_swagger
|
48
|
+
definition = {}
|
49
|
+
|
50
|
+
definition.merge!(@name.to_hash) if @name.present?
|
51
|
+
definition.merge!(@type.to_hash) if @type.present?
|
52
|
+
definition.merge!(@in.to_hash) if @in.present?
|
53
|
+
|
54
|
+
definition.merge!(for_default)
|
55
|
+
definition.merge!(for_required)
|
56
|
+
definition.merge!(@description.to_hash) if @description.present?
|
57
|
+
|
58
|
+
warn_optional_without_default_value(definition)
|
59
|
+
|
60
|
+
definition
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def for_required
|
66
|
+
return {} if !required?
|
67
|
+
|
68
|
+
{
|
69
|
+
required: true
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def for_default
|
74
|
+
return {} if @param_description.options[:default_value].blank?
|
75
|
+
|
76
|
+
{
|
77
|
+
default: @param_description.options[:default_value],
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def required?
|
82
|
+
required_from_path? || (!@in_schema && @param_description.required)
|
83
|
+
end
|
84
|
+
|
85
|
+
def required_from_path?
|
86
|
+
@param_description.options[:added_from_path] == true
|
87
|
+
end
|
88
|
+
|
89
|
+
def warn_optional_without_default_value(definition)
|
90
|
+
if !required? && !definition.key?(:default)
|
91
|
+
method =
|
92
|
+
if @param_description.is_a?(Apipie::ResponseDescriptionAdapter::PropDesc)
|
93
|
+
@controller_method
|
94
|
+
else
|
95
|
+
@param_description.method_description.method
|
96
|
+
end
|
97
|
+
|
98
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
99
|
+
Apipie::Generator::Swagger::Warning::OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE,
|
100
|
+
method,
|
101
|
+
{ parameter: @param_description.name }
|
102
|
+
).warn_through_writer
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::Composite
|
2
|
+
# @param [Array<Apipie::ParamDescription>] param_descriptions
|
3
|
+
# @param [Apipie::Generator::Swagger::Context] context
|
4
|
+
def initialize(param_descriptions, context)
|
5
|
+
@param_descriptions = param_descriptions
|
6
|
+
@context = context
|
7
|
+
@schema = {
|
8
|
+
type: 'object',
|
9
|
+
properties: {}
|
10
|
+
}
|
11
|
+
@required_params = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_swagger
|
15
|
+
return if @param_descriptions.blank?
|
16
|
+
|
17
|
+
@param_descriptions.each do |param_description|
|
18
|
+
validate(param_description)
|
19
|
+
|
20
|
+
if param_description.required
|
21
|
+
@required_params.push(param_description.name.to_sym)
|
22
|
+
end
|
23
|
+
|
24
|
+
param_type = Apipie::Generator::Swagger::TypeExtractor.
|
25
|
+
new(param_description.validator).
|
26
|
+
extract
|
27
|
+
|
28
|
+
has_nested_params = param_type == 'object' &&
|
29
|
+
param_description.validator.params_ordered.present?
|
30
|
+
|
31
|
+
if has_nested_params
|
32
|
+
schema = Apipie::Generator::Swagger::ParamDescription::Composite.new(
|
33
|
+
param_description.validator.params_ordered,
|
34
|
+
Apipie::Generator::Swagger::Context.new(
|
35
|
+
allow_null: @context.allow_null?,
|
36
|
+
http_method: @context.http_method,
|
37
|
+
controller_method: @context.controller_method
|
38
|
+
)
|
39
|
+
).to_swagger
|
40
|
+
|
41
|
+
return if schema.blank?
|
42
|
+
|
43
|
+
if param_description.additional_properties
|
44
|
+
schema[:additionalProperties] = true
|
45
|
+
end
|
46
|
+
|
47
|
+
if param_description.is_array?
|
48
|
+
schema = for_array(schema)
|
49
|
+
end
|
50
|
+
|
51
|
+
if @context.allow_null?
|
52
|
+
schema = with_null(schema)
|
53
|
+
end
|
54
|
+
|
55
|
+
if schema.present?
|
56
|
+
@schema[:properties][param_description.name.to_sym] = schema
|
57
|
+
end
|
58
|
+
else
|
59
|
+
param_entry = Apipie::Generator::Swagger::ParamDescription::Builder.
|
60
|
+
new(
|
61
|
+
param_description,
|
62
|
+
in_schema: @context.in_schema?,
|
63
|
+
controller_method: @context.controller_method
|
64
|
+
).
|
65
|
+
with_description(language: @context.language).
|
66
|
+
with_type(with_null: @context.allow_null?).
|
67
|
+
with_in(
|
68
|
+
default_in_value: @context.default_in_value,
|
69
|
+
http_method: @context.http_method
|
70
|
+
).
|
71
|
+
to_swagger
|
72
|
+
|
73
|
+
@schema[:properties][param_description.name.to_sym] = param_entry
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if !Apipie.configuration.swagger_allow_additional_properties_in_response
|
78
|
+
@schema[:additionalProperties] = false
|
79
|
+
end
|
80
|
+
|
81
|
+
if @required_params.length > 0
|
82
|
+
@schema[:required] = @required_params
|
83
|
+
end
|
84
|
+
|
85
|
+
@schema
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def for_array(schema)
|
91
|
+
{
|
92
|
+
type: 'array',
|
93
|
+
items: schema
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def with_null(schema)
|
98
|
+
# Ideally we would write schema[:type] = ["object", "null"]
|
99
|
+
# but due to a bug in the json-schema gem, we need to use anyOf
|
100
|
+
# see https://github.com/ruby-json-schema/json-schema/issues/404
|
101
|
+
{
|
102
|
+
anyOf: [ schema, { type: 'null' } ]
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
def validate(param_description)
|
107
|
+
if !param_description.respond_to?(:required)
|
108
|
+
raise "Unexpected param_desc format"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::Description
|
2
|
+
def initialize(param_description, language:)
|
3
|
+
@param_description = param_description
|
4
|
+
@language = language
|
5
|
+
end
|
6
|
+
|
7
|
+
# @return [Hash]
|
8
|
+
def to_hash
|
9
|
+
description = @param_description.options[:desc]
|
10
|
+
|
11
|
+
return {} if description.blank?
|
12
|
+
|
13
|
+
{ description: Apipie.app.translate(description, @language) }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::In
|
2
|
+
IN_KEYWORD_DEFAULT_VALUES = {
|
3
|
+
form_data: 'formData',
|
4
|
+
query: 'query'
|
5
|
+
}
|
6
|
+
|
7
|
+
def initialize(param_description, in_schema:, default_in_value:, http_method:)
|
8
|
+
@param_description = param_description
|
9
|
+
@in_schema = in_schema
|
10
|
+
@default_in_value = default_in_value
|
11
|
+
@http_method = http_method
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Hash]
|
15
|
+
def to_hash
|
16
|
+
# The "name" and "in" keys can only be set on root parameters (non-nested)
|
17
|
+
return {} if @in_schema
|
18
|
+
|
19
|
+
{ in: in_value }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def in_value
|
25
|
+
return @default_in_value if @default_in_value.present?
|
26
|
+
|
27
|
+
if body_allowed_for_current_method?
|
28
|
+
IN_KEYWORD_DEFAULT_VALUES[:form_data]
|
29
|
+
else
|
30
|
+
IN_KEYWORD_DEFAULT_VALUES[:query]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def body_allowed_for_current_method?
|
35
|
+
['get', 'head'].exclude?(@http_method)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::Name
|
2
|
+
def initialize(param_description, prefixed_by: nil)
|
3
|
+
@param_description = param_description
|
4
|
+
@prefixed_by = prefixed_by
|
5
|
+
end
|
6
|
+
|
7
|
+
# @return [Hash]
|
8
|
+
def to_hash
|
9
|
+
name =
|
10
|
+
if @prefixed_by.present?
|
11
|
+
"#{@prefixed_by}[#{@param_description.name}]"
|
12
|
+
else
|
13
|
+
@param_description.name
|
14
|
+
end
|
15
|
+
|
16
|
+
{ name: name }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
class Apipie::Generator::Swagger::ParamDescription::Type
|
2
|
+
def initialize(param_description, with_null:, controller_method:)
|
3
|
+
@param_description = param_description
|
4
|
+
@with_null = with_null
|
5
|
+
@controller_method = controller_method
|
6
|
+
end
|
7
|
+
|
8
|
+
# @return [Hash]
|
9
|
+
def to_hash
|
10
|
+
type_definition = {}
|
11
|
+
|
12
|
+
case type.to_s
|
13
|
+
when 'array'
|
14
|
+
type_definition.merge!(for_array_type)
|
15
|
+
when 'enum'
|
16
|
+
type_definition.merge!(for_enum_type)
|
17
|
+
when 'object'
|
18
|
+
# We only get here if there is no specification
|
19
|
+
# of properties for this object.
|
20
|
+
type_definition.merge!(for_object_type)
|
21
|
+
warn_hash_without_internal_typespec
|
22
|
+
else
|
23
|
+
type_definition.merge!({ type: type.to_s })
|
24
|
+
end
|
25
|
+
|
26
|
+
if @param_description.is_array?
|
27
|
+
type_definition = {
|
28
|
+
items: type_definition,
|
29
|
+
type: 'array'
|
30
|
+
}
|
31
|
+
|
32
|
+
if @with_null
|
33
|
+
type_definition[:type] = [type_definition[:type], 'null']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if @with_null
|
38
|
+
type_definition[:type] = [type_definition[:type], 'null']
|
39
|
+
end
|
40
|
+
|
41
|
+
type_definition
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def params_in_body_use_reference?
|
47
|
+
Apipie.configuration.swagger_json_input_uses_refs
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Apipie::Generator::Swagger::Type, String]
|
51
|
+
def type
|
52
|
+
@_type ||= Apipie::Generator::Swagger::TypeExtractor.
|
53
|
+
new(validator).
|
54
|
+
extract
|
55
|
+
end
|
56
|
+
|
57
|
+
def for_array_type
|
58
|
+
validator_opts = validator.param_description.options
|
59
|
+
items_type = validator_opts[:of].to_s || validator_opts[:array_of].to_s
|
60
|
+
|
61
|
+
if items_type == 'Hash' && params_in_body_use_reference?
|
62
|
+
reference_name = Apipie::Generator::Swagger::OperationId.
|
63
|
+
from(@param_description.method_description, param: @param_description.name).
|
64
|
+
to_s
|
65
|
+
|
66
|
+
items = {
|
67
|
+
'$ref' => reference_name
|
68
|
+
}
|
69
|
+
else
|
70
|
+
items = { type: 'string' }
|
71
|
+
end
|
72
|
+
|
73
|
+
enum = @param_description.options[:in]
|
74
|
+
|
75
|
+
items[:enum] = enum if enum.present?
|
76
|
+
|
77
|
+
{
|
78
|
+
type: 'array',
|
79
|
+
items: items
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def for_enum_type
|
84
|
+
{
|
85
|
+
type: 'string',
|
86
|
+
enum: @param_description.validator.values
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def for_object_type
|
91
|
+
{
|
92
|
+
type: 'object',
|
93
|
+
additionalProperties: true
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def validator
|
98
|
+
@_validator ||= @param_description.validator
|
99
|
+
end
|
100
|
+
|
101
|
+
def warn_hash_without_internal_typespec
|
102
|
+
Apipie::Generator::Swagger::Warning.for_code(
|
103
|
+
Apipie::Generator::Swagger::Warning::HASH_WITHOUT_INTERNAL_TYPESPEC_CODE,
|
104
|
+
@controller_method,
|
105
|
+
{ parameter: @param_description.name }
|
106
|
+
).warn_through_writer
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Apipie::Generator::Swagger::ParamDescription
|
2
|
+
# @param [Apipie::MethodDescription] method_description
|
3
|
+
# @param [String] name
|
4
|
+
#
|
5
|
+
# @return [Apipie::ParamDescription]
|
6
|
+
def self.create_for_missing_param(method_description, name)
|
7
|
+
Apipie::ParamDescription.new(
|
8
|
+
method_description,
|
9
|
+
name,
|
10
|
+
Numeric,
|
11
|
+
{
|
12
|
+
in: "path",
|
13
|
+
required: true,
|
14
|
+
added_from_path: true,
|
15
|
+
}
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
@@ -34,8 +34,6 @@ class Apipie::Generator::Swagger::TypeExtractor
|
|
34
34
|
extract
|
35
35
|
end
|
36
36
|
|
37
|
-
private
|
38
|
-
|
39
37
|
def extract
|
40
38
|
expected_type =
|
41
39
|
if string?
|
@@ -51,6 +49,8 @@ class Apipie::Generator::Swagger::TypeExtractor
|
|
51
49
|
TYPES[expected_type] || @validator.expected_type
|
52
50
|
end
|
53
51
|
|
52
|
+
private
|
53
|
+
|
54
54
|
def string?
|
55
55
|
@validator.blank?
|
56
56
|
end
|
data/lib/apipie/markup.rb
CHANGED
@@ -4,6 +4,11 @@ module Apipie
|
|
4
4
|
|
5
5
|
class RDoc
|
6
6
|
|
7
|
+
def initialize
|
8
|
+
require 'rdoc'
|
9
|
+
require 'rdoc/markup/to_html'
|
10
|
+
end
|
11
|
+
|
7
12
|
def to_html(text)
|
8
13
|
rdoc.convert(text)
|
9
14
|
end
|
@@ -11,14 +16,10 @@ module Apipie
|
|
11
16
|
private
|
12
17
|
|
13
18
|
def rdoc
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
::RDoc::Markup::ToHtml.new()
|
19
|
-
else
|
20
|
-
::RDoc::Markup::ToHtml.new(::RDoc::Options.new)
|
21
|
-
end
|
19
|
+
if Gem::Version.new(::RDoc::VERSION) < Gem::Version.new('4.0.0')
|
20
|
+
::RDoc::Markup::ToHtml.new()
|
21
|
+
else
|
22
|
+
::RDoc::Markup::ToHtml.new(::RDoc::Options.new)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -10,8 +10,7 @@ module Apipie
|
|
10
10
|
@from_concern = dsl_data[:from_concern]
|
11
11
|
@apis = ApisService.new(resource, method, dsl_data).call
|
12
12
|
|
13
|
-
|
14
|
-
@full_description = Apipie.markup_to_html(desc)
|
13
|
+
@full_description = dsl_data[:description] || ''
|
15
14
|
|
16
15
|
@errors = dsl_data[:errors].map do |args|
|
17
16
|
Apipie::ErrorDescription.from_dsl_data(args)
|
@@ -40,7 +39,7 @@ module Apipie
|
|
40
39
|
@params_ordered = ParamDescription.unify(@params_ordered)
|
41
40
|
@headers = dsl_data[:headers]
|
42
41
|
|
43
|
-
@show = if dsl_data.
|
42
|
+
@show = if dsl_data.key? :show
|
44
43
|
dsl_data[:show]
|
45
44
|
else
|
46
45
|
true
|
@@ -166,8 +165,8 @@ module Apipie
|
|
166
165
|
:name => @method,
|
167
166
|
:apis => method_apis_to_json(lang),
|
168
167
|
:formats => formats,
|
169
|
-
:full_description => Apipie.app.translate(@full_description, lang),
|
170
|
-
:errors => errors.map(
|
168
|
+
:full_description => Apipie.markup_to_html(Apipie.app.translate(@full_description, lang)),
|
169
|
+
:errors => errors.map{ |error| error.to_json(lang) }.flatten,
|
171
170
|
:params => params_ordered.map{ |param| param.to_json(lang) }.flatten,
|
172
171
|
:returns => @returns.map{ |return_item| return_item.to_json(lang) }.flatten,
|
173
172
|
:examples => @examples,
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Apipie
|
4
|
+
class ParamDescription
|
5
|
+
# Data transfer object, used when param description is deprecated
|
6
|
+
class Deprecation
|
7
|
+
attr_reader :info, :deprecated_in, :sunset_at
|
8
|
+
|
9
|
+
def initialize(info: nil, deprecated_in: nil, sunset_at: nil)
|
10
|
+
@info = info
|
11
|
+
@deprecated_in = deprecated_in
|
12
|
+
@sunset_at = sunset_at
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json(*_args)
|
16
|
+
{
|
17
|
+
info: @info,
|
18
|
+
deprecated_in: @deprecated_in,
|
19
|
+
sunset_at: @sunset_at
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -12,9 +12,9 @@ module Apipie
|
|
12
12
|
attr_reader :additional_properties, :is_array
|
13
13
|
attr_accessor :parent, :required
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
alias response_only? response_only
|
16
|
+
alias request_only? request_only
|
17
|
+
alias is_array? is_array
|
18
18
|
|
19
19
|
def self.from_dsl_data(method_description, args)
|
20
20
|
param_name, validator, desc_or_options, options, block = args
|
@@ -71,7 +71,7 @@ module Apipie
|
|
71
71
|
@request_only = (@options[:only_in] == :request)
|
72
72
|
raise ArgumentError.new("'#{@options[:only_in]}' is not a valid value for :only_in") if (!@response_only && !@request_only) && @options[:only_in].present?
|
73
73
|
|
74
|
-
@show = if @options.
|
74
|
+
@show = if @options.key? :show
|
75
75
|
@options[:show]
|
76
76
|
else
|
77
77
|
true
|
@@ -97,6 +97,7 @@ module Apipie
|
|
97
97
|
@validations = Array(options[:validations]).map {|v| concern_subst(Apipie.markup_to_html(v)) }
|
98
98
|
|
99
99
|
@additional_properties = @options[:additional_properties]
|
100
|
+
@deprecated = @options[:deprecated] || false
|
100
101
|
end
|
101
102
|
|
102
103
|
def from_concern?
|
@@ -155,17 +156,25 @@ module Apipie
|
|
155
156
|
end
|
156
157
|
|
157
158
|
def to_json(lang = nil)
|
158
|
-
hash = {
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
159
|
+
hash = {
|
160
|
+
name: name.to_s,
|
161
|
+
full_name: full_name,
|
162
|
+
description: preformat_text(Apipie.app.translate(@options[:desc], lang)),
|
163
|
+
required: required,
|
164
|
+
allow_nil: allow_nil,
|
165
|
+
allow_blank: allow_blank,
|
166
|
+
validator: validator.to_s,
|
167
|
+
expected_type: validator.expected_type,
|
168
|
+
metadata: metadata,
|
169
|
+
show: show,
|
170
|
+
validations: validations,
|
171
|
+
deprecated: deprecated?
|
172
|
+
}
|
173
|
+
|
174
|
+
if deprecation.present?
|
175
|
+
hash[:deprecation] = deprecation.to_json
|
176
|
+
end
|
177
|
+
|
169
178
|
if sub_params = validator.params_ordered
|
170
179
|
hash[:params] = sub_params.map { |p| p.to_json(lang)}
|
171
180
|
end
|
@@ -212,7 +221,7 @@ module Apipie
|
|
212
221
|
# action awareness is being inherited from ancestors (in terms of
|
213
222
|
# nested params)
|
214
223
|
def action_aware?
|
215
|
-
if @options.
|
224
|
+
if @options.key?(:action_aware)
|
216
225
|
return @options[:action_aware]
|
217
226
|
elsif @parent
|
218
227
|
@parent.action_aware?
|
@@ -237,7 +246,7 @@ module Apipie
|
|
237
246
|
# crate/update actions.
|
238
247
|
def action_awareness
|
239
248
|
if action_aware?
|
240
|
-
if !@options.
|
249
|
+
if !@options.key?(:allow_nil)
|
241
250
|
if @required
|
242
251
|
@allow_nil = false
|
243
252
|
else
|
@@ -268,7 +277,7 @@ module Apipie
|
|
268
277
|
end
|
269
278
|
|
270
279
|
def is_required?
|
271
|
-
if @options.
|
280
|
+
if @options.key?(:required)
|
272
281
|
if (@options[:required] == true) || (@options[:required] == false)
|
273
282
|
@options[:required]
|
274
283
|
else
|
@@ -279,6 +288,24 @@ module Apipie
|
|
279
288
|
end
|
280
289
|
end
|
281
290
|
|
291
|
+
def deprecated?
|
292
|
+
@deprecated.present?
|
293
|
+
end
|
294
|
+
|
295
|
+
def deprecation
|
296
|
+
return if @deprecated.blank? || @deprecated == true
|
297
|
+
|
298
|
+
case @deprecated
|
299
|
+
when Hash
|
300
|
+
Apipie::ParamDescription::Deprecation.new(
|
301
|
+
info: @deprecated[:info],
|
302
|
+
deprecated_in: @deprecated[:in],
|
303
|
+
sunset_at: @deprecated[:sunset]
|
304
|
+
)
|
305
|
+
when String
|
306
|
+
Apipie::ParamDescription::Deprecation.new(info: @deprecated)
|
307
|
+
end
|
308
|
+
end
|
282
309
|
end
|
283
310
|
|
284
311
|
end
|
@@ -17,7 +17,7 @@ module Apipie
|
|
17
17
|
:_path, :_name, :_params_args, :_returns_args, :_tag_list_arg, :_errors_args,
|
18
18
|
:_formats, :_parent, :_metadata, :_headers, :_deprecated
|
19
19
|
|
20
|
-
def initialize(controller, resource_name, dsl_data = nil, version = nil
|
20
|
+
def initialize(controller, resource_name, dsl_data = nil, version = nil)
|
21
21
|
|
22
22
|
@_methods = ActiveSupport::OrderedHash.new
|
23
23
|
@_params_args = []
|
@@ -35,7 +35,7 @@ module Apipie
|
|
35
35
|
|
36
36
|
def update_from_dsl_data(dsl_data)
|
37
37
|
@_name = dsl_data[:resource_name] if dsl_data[:resource_name]
|
38
|
-
@_full_description =
|
38
|
+
@_full_description = dsl_data[:description]
|
39
39
|
@_short_description = dsl_data[:short_description]
|
40
40
|
@_path = dsl_data[:path] || ""
|
41
41
|
@_formats = dsl_data[:formats]
|
@@ -71,7 +71,7 @@ module Apipie
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def remove_method_description(method_name)
|
74
|
-
if @_methods.
|
74
|
+
if @_methods.key?(method_name)
|
75
75
|
@_methods.delete(method_name)
|
76
76
|
end
|
77
77
|
end
|
@@ -110,7 +110,7 @@ module Apipie
|
|
110
110
|
:api_url => api_url,
|
111
111
|
:name => @_name,
|
112
112
|
:short_description => Apipie.app.translate(@_short_description, lang),
|
113
|
-
:full_description => Apipie.app.translate(@_full_description, lang),
|
113
|
+
:full_description => Apipie.markup_to_html(Apipie.app.translate(@_full_description, lang)),
|
114
114
|
:version => _version,
|
115
115
|
:formats => @_formats,
|
116
116
|
:metadata => @_metadata,
|
@@ -116,12 +116,12 @@ module Apipie
|
|
116
116
|
def additional_properties
|
117
117
|
!!@response_object.additional_properties
|
118
118
|
end
|
119
|
-
alias
|
119
|
+
alias allow_additional_properties additional_properties
|
120
120
|
|
121
121
|
def to_json(lang=nil)
|
122
122
|
{
|
123
123
|
:code => code,
|
124
|
-
:description => description,
|
124
|
+
:description => Apipie.app.translate(description, lang),
|
125
125
|
:is_array => is_array?,
|
126
126
|
:returns_object => params_ordered.map{ |param| param.to_json(lang).tap{|h| h.delete(:validations) }}.flatten,
|
127
127
|
:additional_properties => additional_properties,
|