Skip to content

Commit bea6c17

Browse files
authored
Clarify response type (line#546)
This change clarifies the return type of the function in both YARD and RBS. Due to issues with steep (soutaro/steep#1603), this change disables a useful rule that should normally be enabled. I verified using RBS runtime tests in advance and chose to ignore steep errors. As a result, there are currently no additional errors to fix. There might be unknown patterns that could slip through, but eliminating this risk would require submitting a patch to steep, which I have decided against...
1 parent 11d37b0 commit bea6c17

File tree

22 files changed

+2581
-1771
lines changed

22 files changed

+2581
-1771
lines changed

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module Line
5656

5757
# {{ op.notes }}
5858
# This requests to <code>{{ op.httpMethod }} {{ endpoint(operations.classname) }}{{ op.path }}</code>
59+
# This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
5960
#
6061
{% for param in op.allParams -%}
6162
# @param {{param.paramName}} [{{ param.dataType }}{{ param.required ? '' : ', nil' }}] {{param.description}}
@@ -69,17 +70,19 @@ module Line
6970
{% if op.externalDocs.url != null -%}
7071
# @see {{op.externalDocs.url}}
7172
{%- endif %}
72-
# @return [response body, response status code, and response headers]
7373
{%- for response in op.responses %}
7474
{%- if response.content['application/json'].schema.complexType != null %}
7575
# @return [Array(Line::Bot::V2::{{ packageName | camelize }}::{{ response.content['application/json'].schema.complexType }}, Integer, Hash{String => String})] when HTTP status code is {{ response.code }}
7676
{%- else %}
7777
# @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is {{ response.code }}
7878
{%- endif %}
7979
{%- endfor %}
80-
def {{op.nickname}}_with_http_info({% for param in op.allParams %}
80+
# @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
81+
{#- Remove this steep:ignore after https://github.com/soutaro/steep/issues/1603 is resolved #}
82+
def {{op.nickname}}_with_http_info( # steep:ignore MethodBodyTypeMismatch
83+
{%- for param in op.allParams %}
8184
{{param.paramName}}:{{ param.required ? '' : ' nil' }}{{ loop.last ? '' : ',' -}}
82-
{% endfor %}
85+
{%- endfor %}
8386
)
8487
path = "{{ op.path }}"{% for param in op.pathParams %}
8588
.gsub(/{{ "{" + param.baseName + "}" }}/, {{ param.paramName }}.to_s)
@@ -106,23 +109,23 @@ module Line
106109
headers: header_params{% endif %}
107110
)
108111

109-
response_body = case response.code.to_i
110-
{%- for response in op.responses %}
111-
when {{ response.code }}
112-
{%- if response.content['application/json'].schema.complexType != null %}
113-
json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
114-
json.transform_keys! do |key|
115-
Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
116-
end
117-
Line::Bot::V2::{{ packageName | camelize }}::{{ response.content['application/json'].schema.complexType }}.create(json) # steep:ignore InsufficientKeywordArguments
118-
{%- else %}
119-
response.body
120-
{%- endif %}{% endfor %}
121-
else
122-
response.body
123-
end
124-
125-
[response_body, response.code.to_i, response.each_header.to_h]
112+
case response.code.to_i
113+
{%- for response in op.responses %}
114+
when {{ response.code }}
115+
{%- if response.content['application/json'].schema.complexType != null %}
116+
json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
117+
json.transform_keys! do |key|
118+
Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
119+
end
120+
response_body = Line::Bot::V2::{{ packageName | camelize }}::{{ response.content['application/json'].schema.complexType }}.create(json) # steep:ignore InsufficientKeywordArguments
121+
[response_body, {{ response.code }}, response.each_header.to_h]
122+
{%- else %}
123+
[response.body, {{ response.code }}, response.each_header.to_h]
124+
{%- endif %}
125+
{%- endfor %}
126+
else
127+
[response.body, response.code.to_i, response.each_header.to_h]
128+
end
126129
end
127130

128131
# {{ op.notes }}
@@ -148,6 +151,7 @@ module Line
148151
# @return [String, nil] when HTTP status code is {{ response.code }}
149152
{%- endif %}
150153
{%- endfor %}
154+
# @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
151155
def {{op.nickname}}({% for param in op.allParams %}
152156
{{param.paramName}}:{{ param.required ? '' : ' nil' }}{{ loop.last ? '' : ',' -}}
153157
{% endfor %}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ module Line
4040
{%- for param in op.allParams %}
4141
{{ param.required ? '' : '?' }}{{param.paramName}}: {{ param.dataType }}{{ param.required ? '' : '?' }}{{ loop.last ? '' : ', ' -}}
4242
{% endfor %}
43-
) -> [({% for response in op.responses %}{{ response.baseType == 'object' or response.baseType == null or response.isFile ? 'String?' : response.dataType }}{{ loop.last ? '' : '|' }}{% endfor %}), Integer, Hash[String, String]]
43+
) -> (
44+
{%- for response in op.responses %}
45+
{{ loop.first ? '' : '| ' }}[{{ response.baseType == 'object' or response.baseType == null or response.isFile ? 'String?' : response.dataType }}, {{ response.code }}, Hash[untyped, untyped]] # when HTTP status code is {{ response.code }}
46+
{%- endfor %}
47+
| [String?, Integer, Hash[untyped, untyped]] # otherwise
48+
)
4449

4550
# {{ op.notes }}
4651
#
@@ -60,7 +65,13 @@ module Line
6065
{%- for param in op.allParams %}
6166
{{ param.required ? '' : '?' }}{{param.paramName}}: {{ param.dataType }}{{ param.required ? '' : '?' }}{{ loop.last ? '' : ', ' -}}
6267
{% endfor %}
63-
) -> ({% for response in op.responses %}{{ response.baseType == 'object' or response.baseType == null or response.isFile ? 'String?' : response.dataType }}{{ loop.last ? '' : '|' }}{% endfor %}){% endfor %}
68+
) -> (
69+
{%- for response in op.responses %}
70+
{{ loop.first ? '' : '| ' }}{{ response.baseType == 'object' or response.baseType == null or response.isFile ? 'String?' : response.dataType }} # when HTTP status code is {{ response.code }}
71+
{%- endfor %}
72+
| String? # otherwise
73+
)
74+
{%- endfor %}
6475
end
6576
end
6677
end

0 commit comments

Comments
 (0)