Skip to content

Commit 8cdc027

Browse files
authored
Mark as optional parameter for RBS in Model#initialize (#529)
This resolves current inconsistency between implementation and RBS in Model#initialize like below ``` lib/line/bot/v2/messaging_api/model/reply_message_request.rb:32:12: [error] The method parameter has different kind from the declaration `(reply_token: ::String, messages: ::Array[::Line::Bot::V2::MessagingApi::Message], notification_disabled: (bool | nil)) -> void` │ Diagnostic ID: Ruby::DifferentMethodParameterKind │ └ notification_disabled: false, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lib/line/bot/v2/messaging_api/model/reply_message_request.rb:33:12: [error] The method parameter has different kind from the declaration `(reply_token: ::String, messages: ::Array[::Line::Bot::V2::MessagingApi::Message], notification_disabled: (bool | nil)) -> void` │ Diagnostic ID: Ruby::DifferentMethodParameterKind │ └ **dynamic_attributes ~~~~~~~~~~~~~~~~~~~~ ``` (one of tasks for #526)
1 parent 8cd3451 commit 8cdc027

File tree

294 files changed

+949
-1761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

294 files changed

+949
-1761
lines changed

generator/src/main/resources/line-bot-sdk-ruby-generator/model.pebble

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Line
2121
# @see {{ model.model.externalDocumentation.url }}
2222
{% endif -%}
2323
class {{ model.model.classname }}{% if model.model.parent != null %} < {{ model.model.parent }}{% endif %}
24+
{%- if not model.model.isEnum -%}
2425
{%- for variable in model.model.vars %}
2526
# @!attribute [{% if model.model.vendorExtensions.get("x-selector").propertyName != variable.name %}rw{% else %}r{% endif %}] {{ variable.name }}
2627
{% if variable.openApiType == 'array' -%}
@@ -135,7 +136,10 @@ module Line
135136
{{ child.typeName }}: Line::Bot::V2::{{ packageName | camelize }}::{{ child.className }},
136137
{%- endfor %}
137138
}[type.to_sym]
138-
end{% endif %}
139+
end
140+
{%- endif %}
141+
{%- else %}{# if not model.model.isEnum #}
142+
{% endif -%}{# if not model.model.isEnum #}
139143
end
140144
end
141145
end

generator/src/main/resources/line-bot-sdk-ruby-rbs-generator/model.pebble

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,28 @@ module Line
3939
def initialize: (
4040
{% for variable in model.model.vars -%}
4141
{% if model.model.vendorExtensions.get("x-selector").propertyName != variable.name -%}
42-
{% if variable.openApiType == 'array' -%}
42+
{{ (not variable.required or variable.defaultValue != null) ? '?' : '' }} {#- optioanl parameter => Add '?' #}
43+
{%- if variable.openApiType == 'array' -%}
4344
{% if variable.items.isModel -%}
4445
{{ variable.name }}: {{ "Array[#{variable.items.openApiType}]" }}{% if not variable.required %}?{% endif -%}
4546
{% elseif variable.items.allowableValues != null -%}
4647
{{ variable.name }}: Array[{% for value in variable.items.allowableValues.values %}'{{ value }}'{{ loop.last ? '' : '|' }}{% endfor -%}]{% if not variable.required %}?{% endif -%}
4748
{% else -%}
4849
{{ variable.name }}: {{ variable.items.openApiType ? "Array[#{typeMapping[variable.items.openApiType]}]" : 'Array[untyped]' }}{% if not variable.required %}?{% endif -%}
4950
{% endif -%}
50-
{% elseif variable.isModel -%}
51+
{%- elseif variable.isModel -%}
5152
{{ variable.name }}: {{ variable.openApiType }}{% if not variable.required %}?{% endif -%}
52-
{% else -%}
53+
{%- else -%}
5354
{% if variable.allowableValues != null -%}
5455
{{ variable.name }}: {% for value in variable.allowableValues.values %}'{{ value }}'{{ loop.last ? '' : '|' }}{% endfor %}{% if not variable.required %}?{% endif -%}
5556
{% else -%}
5657
{{ variable.name }}: {{ typeMapping[variable.openApiType] ? typeMapping[variable.openApiType] : 'untyped' }}{% if not variable.required %}?{% endif -%}
5758
{% endif -%}
58-
{% endif %}{{ loop.last ? '' : ",
59-
" }}{% endif %}{% endfor %}
59+
{% endif -%}
60+
,
61+
{% endif -%}
62+
{%- endfor -%}
63+
**Hash[Symbol, untyped] dynamic_attributes
6064
) -> void
6165

6266
def self.create: (args: Hash[Symbol, untyped]) -> {{ model.model.classname }}

lib/line/bot/v2/liff/model/liff_bot_prompt.rb

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,7 @@ module V2
1313
module Liff
1414
# Specify the setting for bot link feature with one of the following values: `normal`: Display the option to add the LINE Official Account as a friend in the channel consent screen. `aggressive`: Display a screen with the option to add the LINE Official Account as a friend after the channel consent screen. `none`: Don't display the option to add the LINE Official Account as a friend. The default value is none.
1515
class LiffBotPrompt
16-
17-
def initialize(
18-
**dynamic_attributes
19-
)
20-
21-
22-
dynamic_attributes.each do |key, value|
23-
self.class.attr_accessor key
24-
25-
if value.is_a?(Hash)
26-
struct_klass = Struct.new(*value.keys.map(&:to_sym))
27-
struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
28-
instance_variable_set("@#{key}", struct_klass.new(*struct_values))
29-
else
30-
instance_variable_set("@#{key}", value)
31-
end
32-
end
33-
end
34-
35-
def self.create(args) # steep:ignore
36-
return new(**args) # steep:ignore
37-
end
38-
39-
# @param other [Object] Object to compare
40-
# @return [Boolean] true if the objects are equal, false otherwise
41-
def ==(other)
42-
return false unless self.class == other.class
43-
44-
instance_variables.all? do |var|
45-
instance_variable_get(var) == other.instance_variable_get(var)
46-
end
47-
end
48-
49-
# @return [Integer] Hash code of the object
50-
def hash
51-
[self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
52-
end
16+
5317
end
5418
end
5519
end

lib/line/bot/v2/liff/model/liff_scope.rb

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,7 @@ module V2
1313
module Liff
1414
# Array of scopes required for some LIFF SDK methods to function. The default value is `[\"profile\", \"chat_message.write\"]`.
1515
class LiffScope
16-
17-
def initialize(
18-
**dynamic_attributes
19-
)
20-
21-
22-
dynamic_attributes.each do |key, value|
23-
self.class.attr_accessor key
24-
25-
if value.is_a?(Hash)
26-
struct_klass = Struct.new(*value.keys.map(&:to_sym))
27-
struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
28-
instance_variable_set("@#{key}", struct_klass.new(*struct_values))
29-
else
30-
instance_variable_set("@#{key}", value)
31-
end
32-
end
33-
end
34-
35-
def self.create(args) # steep:ignore
36-
return new(**args) # steep:ignore
37-
end
38-
39-
# @param other [Object] Object to compare
40-
# @return [Boolean] true if the objects are equal, false otherwise
41-
def ==(other)
42-
return false unless self.class == other.class
43-
44-
instance_variables.all? do |var|
45-
instance_variable_get(var) == other.instance_variable_get(var)
46-
end
47-
end
48-
49-
# @return [Integer] Hash code of the object
50-
def hash
51-
[self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
52-
end
16+
5317
end
5418
end
5519
end

lib/line/bot/v2/manage_audience/model/audience_group_create_route.rb

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,7 @@ module V2
1313
module ManageAudience
1414
# How the audience was created. One of: - `OA_MANAGER`: Audience created with [LINE Official Account Manager](https://manager.line.biz/). - `MESSAGING_API`: Audience created with Messaging API. - `POINT_AD`: Audience created with [LINE Points Ads](https://www.linebiz.com/jp/service/line-point-ad/) (Japanese only). - `AD_MANAGER`: Audience created with [LINE Ads](https://admanager.line.biz/).
1515
class AudienceGroupCreateRoute
16-
17-
def initialize(
18-
**dynamic_attributes
19-
)
20-
21-
22-
dynamic_attributes.each do |key, value|
23-
self.class.attr_accessor key
24-
25-
if value.is_a?(Hash)
26-
struct_klass = Struct.new(*value.keys.map(&:to_sym))
27-
struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
28-
instance_variable_set("@#{key}", struct_klass.new(*struct_values))
29-
else
30-
instance_variable_set("@#{key}", value)
31-
end
32-
end
33-
end
34-
35-
def self.create(args) # steep:ignore
36-
return new(**args) # steep:ignore
37-
end
38-
39-
# @param other [Object] Object to compare
40-
# @return [Boolean] true if the objects are equal, false otherwise
41-
def ==(other)
42-
return false unless self.class == other.class
43-
44-
instance_variables.all? do |var|
45-
instance_variable_get(var) == other.instance_variable_get(var)
46-
end
47-
end
48-
49-
# @return [Integer] Hash code of the object
50-
def hash
51-
[self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
52-
end
16+
5317
end
5418
end
5519
end

lib/line/bot/v2/manage_audience/model/audience_group_failed_type.rb

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,7 @@ module V2
1313
module ManageAudience
1414
# Failed type
1515
class AudienceGroupFailedType
16-
17-
def initialize(
18-
**dynamic_attributes
19-
)
20-
21-
22-
dynamic_attributes.each do |key, value|
23-
self.class.attr_accessor key
24-
25-
if value.is_a?(Hash)
26-
struct_klass = Struct.new(*value.keys.map(&:to_sym))
27-
struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
28-
instance_variable_set("@#{key}", struct_klass.new(*struct_values))
29-
else
30-
instance_variable_set("@#{key}", value)
31-
end
32-
end
33-
end
34-
35-
def self.create(args) # steep:ignore
36-
return new(**args) # steep:ignore
37-
end
38-
39-
# @param other [Object] Object to compare
40-
# @return [Boolean] true if the objects are equal, false otherwise
41-
def ==(other)
42-
return false unless self.class == other.class
43-
44-
instance_variables.all? do |var|
45-
instance_variable_get(var) == other.instance_variable_get(var)
46-
end
47-
end
48-
49-
# @return [Integer] Hash code of the object
50-
def hash
51-
[self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
52-
end
16+
5317
end
5418
end
5519
end

lib/line/bot/v2/manage_audience/model/audience_group_job_failed_type.rb

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,7 @@ module V2
1313
module ManageAudience
1414
# Failed type
1515
class AudienceGroupJobFailedType
16-
17-
def initialize(
18-
**dynamic_attributes
19-
)
20-
21-
22-
dynamic_attributes.each do |key, value|
23-
self.class.attr_accessor key
24-
25-
if value.is_a?(Hash)
26-
struct_klass = Struct.new(*value.keys.map(&:to_sym))
27-
struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
28-
instance_variable_set("@#{key}", struct_klass.new(*struct_values))
29-
else
30-
instance_variable_set("@#{key}", value)
31-
end
32-
end
33-
end
34-
35-
def self.create(args) # steep:ignore
36-
return new(**args) # steep:ignore
37-
end
38-
39-
# @param other [Object] Object to compare
40-
# @return [Boolean] true if the objects are equal, false otherwise
41-
def ==(other)
42-
return false unless self.class == other.class
43-
44-
instance_variables.all? do |var|
45-
instance_variable_get(var) == other.instance_variable_get(var)
46-
end
47-
end
48-
49-
# @return [Integer] Hash code of the object
50-
def hash
51-
[self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
52-
end
16+
5317
end
5418
end
5519
end

lib/line/bot/v2/manage_audience/model/audience_group_job_status.rb

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,7 @@ module V2
1313
module ManageAudience
1414
# Job status
1515
class AudienceGroupJobStatus
16-
17-
def initialize(
18-
**dynamic_attributes
19-
)
20-
21-
22-
dynamic_attributes.each do |key, value|
23-
self.class.attr_accessor key
24-
25-
if value.is_a?(Hash)
26-
struct_klass = Struct.new(*value.keys.map(&:to_sym))
27-
struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
28-
instance_variable_set("@#{key}", struct_klass.new(*struct_values))
29-
else
30-
instance_variable_set("@#{key}", value)
31-
end
32-
end
33-
end
34-
35-
def self.create(args) # steep:ignore
36-
return new(**args) # steep:ignore
37-
end
38-
39-
# @param other [Object] Object to compare
40-
# @return [Boolean] true if the objects are equal, false otherwise
41-
def ==(other)
42-
return false unless self.class == other.class
43-
44-
instance_variables.all? do |var|
45-
instance_variable_get(var) == other.instance_variable_get(var)
46-
end
47-
end
48-
49-
# @return [Integer] Hash code of the object
50-
def hash
51-
[self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
52-
end
16+
5317
end
5418
end
5519
end

lib/line/bot/v2/manage_audience/model/audience_group_job_type.rb

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,7 @@ module V2
1313
module ManageAudience
1414
# Job Type
1515
class AudienceGroupJobType
16-
17-
def initialize(
18-
**dynamic_attributes
19-
)
20-
21-
22-
dynamic_attributes.each do |key, value|
23-
self.class.attr_accessor key
24-
25-
if value.is_a?(Hash)
26-
struct_klass = Struct.new(*value.keys.map(&:to_sym))
27-
struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
28-
instance_variable_set("@#{key}", struct_klass.new(*struct_values))
29-
else
30-
instance_variable_set("@#{key}", value)
31-
end
32-
end
33-
end
34-
35-
def self.create(args) # steep:ignore
36-
return new(**args) # steep:ignore
37-
end
38-
39-
# @param other [Object] Object to compare
40-
# @return [Boolean] true if the objects are equal, false otherwise
41-
def ==(other)
42-
return false unless self.class == other.class
43-
44-
instance_variables.all? do |var|
45-
instance_variable_get(var) == other.instance_variable_get(var)
46-
end
47-
end
48-
49-
# @return [Integer] Hash code of the object
50-
def hash
51-
[self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
52-
end
16+
5317
end
5418
end
5519
end

0 commit comments

Comments
 (0)