Skip to content

Commit

Permalink
Fix type value line#351
Browse files Browse the repository at this point in the history
  • Loading branch information
mokuzon committed Jan 20, 2025
1 parent 875e3b8 commit 6a07795
Show file tree
Hide file tree
Showing 384 changed files with 647 additions and 553 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ post '/callback' do
request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
reply_token: event.reply_token,
messages: [
Line::Bot::V2::MessagingApi::TextMessage.new(type: 'text', text: "[ECHO] #{event.message.text}")
Line::Bot::V2::MessagingApi::TextMessage.new(text: "[ECHO] #{event.message.text}")
]
)
client.reply_message(reply_message_request: request)
Expand Down Expand Up @@ -148,7 +148,6 @@ end

def main
dummy_message = Line::Bot::V2::MessagingApi::TextMessage.new(
type: "text",
text: "Hello, world!",
)

Expand Down
2 changes: 1 addition & 1 deletion examples/v2/echobot/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def parser
request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
reply_token: event.reply_token,
messages: [
Line::Bot::V2::MessagingApi::TextMessage.new(type: 'text', text: message)
Line::Bot::V2::MessagingApi::TextMessage.new(text: message)
]
)
client.reply_message(reply_message_request: request)
Expand Down
89 changes: 6 additions & 83 deletions examples/v2/kitchensink/app.rb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/v2/rich_menu/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def rich_menu_request_a
areas: [
Line::Bot::V2::MessagingApi::RichMenuArea.new(
bounds: Line::Bot::V2::MessagingApi::RichMenuBounds.new(x: 0, y: 0, width: 1250, height: 1686),
action: Line::Bot::V2::MessagingApi::URIAction.new(type: 'uri', uri: 'https://www.line-community.me/')
action: Line::Bot::V2::MessagingApi::URIAction.new(uri: 'https://www.line-community.me/')
),
Line::Bot::V2::MessagingApi::RichMenuArea.new(
bounds: Line::Bot::V2::MessagingApi::RichMenuBounds.new(x: 1251, y: 0, width: 1250, height: 1686),
action: Line::Bot::V2::MessagingApi::RichMenuSwitchAction.new(type: 'richmenuswitch', rich_menu_alias_id: 'richmenu-alias-b', data: 'richmenu-changed-to-b')
action: Line::Bot::V2::MessagingApi::RichMenuSwitchAction.new(rich_menu_alias_id: 'richmenu-alias-b', data: 'richmenu-changed-to-b')
)
]
)
Expand All @@ -65,11 +65,11 @@ def rich_menu_request_b
areas: [
Line::Bot::V2::MessagingApi::RichMenuArea.new(
bounds: Line::Bot::V2::MessagingApi::RichMenuBounds.new(x: 0, y: 0, width: 1250, height: 1686),
action: Line::Bot::V2::MessagingApi::RichMenuSwitchAction.new(type: 'richmenuswitch', rich_menu_alias_id: 'richmenu-alias-a', data: 'richmenu-changed-to-a')
action: Line::Bot::V2::MessagingApi::RichMenuSwitchAction.new(rich_menu_alias_id: 'richmenu-alias-a', data: 'richmenu-changed-to-a')
),
Line::Bot::V2::MessagingApi::RichMenuArea.new(
bounds: Line::Bot::V2::MessagingApi::RichMenuBounds.new(x: 1251, y: 0, width: 1250, height: 1686),
action: Line::Bot::V2::MessagingApi::URIAction.new(type: 'uri', uri: 'https://www.line-community.me/')
action: Line::Bot::V2::MessagingApi::URIAction.new(uri: 'https://www.line-community.me/')
)
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package line.bot.generator;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.openapitools.codegen.CodegenDiscriminator;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.languages.AbstractRubyCodegen;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.utils.StringUtils;

// https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java
Expand Down Expand Up @@ -64,4 +71,29 @@ public void processOpts() {
additionalProperties.put("typeMapping", typeMapping);
supportingFiles.add(new SupportingFile("line-bot-sdk-ruby-generator/core.pebble", apiPackage().replace('.', File.separatorChar), "core.rb"));
}

@Override
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
final Map<String, ModelsMap> result = super.postProcessAllModels(objs);

for (ModelsMap entry : result.values()) {
for (ModelMap mo : entry.getModels()) {
CodegenModel cm = mo.getModel();

if (cm.getParentModel() != null) {
final CodegenDiscriminator discriminator = cm.getParentModel().getDiscriminator();
final Optional<String> mappingNameOptional = discriminator.getMappedModels().stream().filter(
it -> it.getModelName().equals(cm.name)
).map(CodegenDiscriminator.MappedModel::getMappingName).findFirst();
mappingNameOptional.ifPresent(mappingName -> {
final Map<String, Object> selector = new HashMap<>();
selector.put("propertyName", discriminator.getPropertyName());
selector.put("mappingName", mappingName);
cm.getVendorExtensions().put("x-selector", selector);
});
}
}
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package line.bot.generator;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.openapitools.codegen.CodegenDiscriminator;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.languages.AbstractRubyCodegen;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.utils.StringUtils;

// https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java
Expand Down Expand Up @@ -65,4 +72,29 @@ public void processOpts() {
super.processOpts();
additionalProperties.put("typeMapping", this.typeMapping);
}

@Override
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
final Map<String, ModelsMap> result = super.postProcessAllModels(objs);

for (ModelsMap entry : result.values()) {
for (ModelMap mo : entry.getModels()) {
CodegenModel cm = mo.getModel();

if (cm.getParentModel() != null) {
final CodegenDiscriminator discriminator = cm.getParentModel().getDiscriminator();
final Optional<String> mappingNameOptional = discriminator.getMappedModels().stream().filter(
it -> it.getModelName().equals(cm.name)
).map(CodegenDiscriminator.MappedModel::getMappingName).findFirst();
mappingNameOptional.ifPresent(mappingName -> {
final Map<String, Object> selector = new HashMap<>();
selector.put("propertyName", discriminator.getPropertyName());
selector.put("mappingName", mappingName);
cm.getVendorExtensions().put("x-selector", selector);
});
}
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ module Line
module {{ packageName | camelize }}
class {{ model.model.classname }}{% if model.model.parent != null %} < {{ model.model.parent }}{% endif %}
{%- for property in model.model.vars %}
attr_accessor :{{ property.name }}{% if property.description != null %} # {{ property.description }}{% endif %}
{% if model.model.vendorExtensions.get("x-selector") == null or model.model.vendorExtensions.get("x-selector").propertyName != property.name %}attr_accessor{% else %}attr_reader{% endif %} :{{ property.name }}{% if property.description != null %} # {{ property.description }}{% endif %}
{%- endfor %}

def initialize(
{%- for property in model.model.vars %}
{{ property.name }}:{% if property.defaultValue == null %}{{ property.required ? '' : ' nil' }}{% else %}{{ ' ' + property.defaultValue }}{% endif %}{{ loop.last ? '' : ',' -}}
{% endfor %}
def initialize({% for property in model.model.vars %}{% if model.model.vendorExtensions.get("x-selector") == null or model.model.vendorExtensions.get("x-selector").propertyName != property.name %}
{{ property.name }}:{% if property.defaultValue == null %}{{ property.required ? '' : ' nil' }}{% else %}{{ ' ' + property.defaultValue }}{% endif %}{{ loop.last ? '' : ',' -}}{% endif %}{% endfor %}
)
{% if model.model.vendorExtensions.get("x-selector") != null %}@{{model.model.vendorExtensions.get("x-selector").propertyName}} = "{{model.model.vendorExtensions.get("x-selector").mappingName}}"{% endif -%}
{%- for property in model.model.vars %}
@{{ property.name }} = {{ property.name -}}
{% if model.model.vendorExtensions.get("x-selector") == null or model.model.vendorExtensions.get("x-selector").propertyName != property.name %}@{{ property.name }} = {{ property.name }}{% endif -%}
{% endfor %}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,25 @@ module Line
{% for variable in model.model.vars -%}
{% if variable.openApiType == 'array' -%}
{% if variable.items.isModel -%}
attr_accessor {{ variable.name }}: {{ "Array[#{variable.items.openApiType}]" }}{% if not variable.required %}?{% endif %}
{% if model.model.vendorExtensions.get("x-selector").propertyName != variable.name %}attr_accessor{% else %}attr_reader{% endif %} {{ variable.name }}: {{ "Array[#{variable.items.openApiType}]" }}{% if not variable.required %}?{% endif %}
{% elseif variable.items.allowableValues != null -%}
attr_accessor {{ variable.name }}: Array[{% for value in variable.items.allowableValues.values %}'{{ value }}'{{ loop.last ? '' : '|' }}{% endfor -%}]{% if not variable.required %}?{% endif %}
{% if model.model.vendorExtensions.get("x-selector").propertyName != variable.name %}attr_accessor{% else %}attr_reader{% endif %} {{ variable.name }}: Array[{% for value in variable.items.allowableValues.values %}'{{ value }}'{{ loop.last ? '' : '|' }}{% endfor -%}]{% if not variable.required %}?{% endif %}
{% else -%}
attr_accessor {{ variable.name }}: {{ variable.items.openApiType ? "Array[#{typeMapping[variable.items.openApiType]}]" : 'Array[untyped]' }}{% if not variable.required %}?{% endif %}
{% if model.model.vendorExtensions.get("x-selector").propertyName != variable.name %}attr_accessor{% else %}attr_reader{% endif %} {{ variable.name }}: {{ variable.items.openApiType ? "Array[#{typeMapping[variable.items.openApiType]}]" : 'Array[untyped]' }}{% if not variable.required %}?{% endif %}
{% endif -%}
{% elseif variable.isModel -%}
attr_accessor {{ variable.name }}: {{ variable.openApiType }}{% if not variable.required %}?{% endif %}
{% if model.model.vendorExtensions.get("x-selector").propertyName != variable.name %}attr_accessor{% else %}attr_reader{% endif %} {{ variable.name }}: {{ variable.openApiType }}{% if not variable.required %}?{% endif %}
{% else -%}
{% if variable.allowableValues != null -%}
attr_accessor {{ variable.name }}: {% for value in variable.allowableValues.values %}'{{ value }}'{{ loop.last ? '' : '|' }}{% endfor %}{% if not variable.required %}?{% endif %}
{% if model.model.vendorExtensions.get("x-selector").propertyName != variable.name %}attr_accessor{% else %}attr_reader{% endif %} {{ variable.name }}: {% for value in variable.allowableValues.values %}'{{ value }}'{{ loop.last ? '' : '|' }}{% endfor %}{% if not variable.required %}?{% endif %}
{% else -%}
attr_accessor {{ variable.name }}: {{ typeMapping[variable.openApiType] ? typeMapping[variable.openApiType] : 'untyped' }}{% if not variable.required %}?{% endif %}
{% if model.model.vendorExtensions.get("x-selector").propertyName != variable.name %}attr_accessor{% else %}attr_reader{% endif %} {{ variable.name }}: {{ typeMapping[variable.openApiType] ? typeMapping[variable.openApiType] : 'untyped' }}{% if not variable.required %}?{% endif %}
{% endif -%}
{% endif -%}
{% endfor %}
def initialize: (
{% for variable in model.model.vars -%}
{% if model.model.vendorExtensions.get("x-selector") == null or model.model.vendorExtensions.get("x-selector").propertyName != variable.name -%}
{% if variable.openApiType == 'array' -%}
{% if variable.items.isModel -%}
{{ variable.name }}: {{ "Array[#{variable.items.openApiType}]" }}{% if not variable.required %}?{% endif -%}
Expand All @@ -55,7 +56,7 @@ module Line
{{ variable.name }}: {{ typeMapping[variable.openApiType] ? typeMapping[variable.openApiType] : 'untyped' }}{% if not variable.required %}?{% endif -%}
{% endif -%}
{% endif %}{{ loop.last ? '' : ",
" }}{% endfor %}
" }}{% endif %}{% endfor %}
) -> void
{%- endif %}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ChannelAccessTokenKeyIdsResponse
def initialize(
kids:
)

@kids = kids
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def initialize(
error: nil,
error_description: nil
)

@error = error
@error_description = error_description
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(
token_type: 'Bearer',
key_id:
)

@access_token = access_token
@expires_in = expires_in
@token_type = token_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(
expires_in:,
token_type: 'Bearer'
)

@access_token = access_token
@expires_in = expires_in
@token_type = token_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(
expires_in:,
token_type: 'Bearer'
)

@access_token = access_token
@expires_in = expires_in
@token_type = token_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def initialize(
expires_in:,
scope: nil
)

@client_id = client_id
@expires_in = expires_in
@scope = scope
Expand Down
1 change: 1 addition & 0 deletions lib/line/bot/v2/insight/model/age_tile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize(
age: nil,
percentage: nil
)

@age = age
@percentage = percentage
end
Expand Down
1 change: 1 addition & 0 deletions lib/line/bot/v2/insight/model/app_type_tile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize(
app_type: nil,
percentage: nil
)

@app_type = app_type
@percentage = percentage
end
Expand Down
1 change: 1 addition & 0 deletions lib/line/bot/v2/insight/model/area_tile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize(
area: nil,
percentage: nil
)

@area = area
@percentage = percentage
end
Expand Down
1 change: 1 addition & 0 deletions lib/line/bot/v2/insight/model/error_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize(
message: nil,
property: nil
)

@message = message
@property = property
end
Expand Down
1 change: 1 addition & 0 deletions lib/line/bot/v2/insight/model/error_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def initialize(
message:,
details: nil
)

@message = message
@details = details
end
Expand Down
1 change: 1 addition & 0 deletions lib/line/bot/v2/insight/model/gender_tile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def initialize(
gender: nil,
percentage: nil
)

@gender = gender
@percentage = percentage
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def initialize(
app_types: nil,
subscription_periods: nil
)

@available = available
@genders = genders
@ages = ages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(
messages: nil,
clicks: nil
)

@overview = overview
@messages = messages
@clicks = clicks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(
unique_click: nil,
unique_click_of_request: nil
)

@seq = seq
@url = url
@click = click
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def initialize(
unique_media_played75_percent: nil,
unique_media_played100_percent: nil
)

@seq = seq
@impression = impression
@media_played = media_played
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def initialize(
unique_media_played: nil,
unique_media_played100_percent: nil
)

@request_id = request_id
@timestamp = timestamp
@delivered = delivered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(
targeted_reaches: nil,
blocks: nil
)

@status = status
@followers = followers
@targeted_reaches = targeted_reaches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def initialize(
api_narrowcast: nil,
api_reply: nil
)

@status = status
@broadcast = broadcast
@targeting = targeting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(
messages:,
clicks:
)

@overview = overview
@messages = messages
@clicks = clicks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def initialize(
unique_click: nil,
unique_click_of_request: nil
)

@seq = seq
@url = url
@click = click
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def initialize(
unique_media_played75_percent: nil,
unique_media_played100_percent: nil
)

@seq = seq
@impression = impression
@media_played = media_played
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(
unique_media_played: nil,
unique_media_played100_percent: nil
)

@unique_impression = unique_impression
@unique_click = unique_click
@unique_media_played = unique_media_played
Expand Down
Loading

0 comments on commit 6a07795

Please sign in to comment.