telegram-bot-ruby 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +6 -2
- data/README.md +1 -1
- data/Rakefile +0 -45
- data/lib/telegram/bot/api/endpoints.rb +12 -2
- data/lib/telegram/bot/client.rb +1 -1
- data/lib/telegram/bot/exceptions/response_error.rb +1 -1
- data/lib/telegram/bot/types/affiliate_info.rb +15 -0
- data/lib/telegram/bot/types/background_fill.rb +16 -0
- data/lib/telegram/bot/types/background_fill_freeform_gradient.rb +12 -0
- data/lib/telegram/bot/types/background_fill_gradient.rb +14 -0
- data/lib/telegram/bot/types/background_fill_solid.rb +12 -0
- data/lib/telegram/bot/types/background_type.rb +17 -0
- data/lib/telegram/bot/types/background_type_chat_theme.rb +12 -0
- data/lib/telegram/bot/types/background_type_fill.rb +13 -0
- data/lib/telegram/bot/types/background_type_pattern.rb +16 -0
- data/lib/telegram/bot/types/background_type_wallpaper.rb +15 -0
- data/lib/telegram/bot/types/birthdate.rb +13 -0
- data/lib/telegram/bot/types/bot_command.rb +2 -2
- data/lib/telegram/bot/types/bot_command_scope.rb +20 -0
- data/lib/telegram/bot/types/business_connection.rb +16 -0
- data/lib/telegram/bot/types/business_intro.rb +13 -0
- data/lib/telegram/bot/types/business_location.rb +12 -0
- data/lib/telegram/bot/types/business_messages_deleted.rb +13 -0
- data/lib/telegram/bot/types/business_opening_hours.rb +12 -0
- data/lib/telegram/bot/types/business_opening_hours_interval.rb +12 -0
- data/lib/telegram/bot/types/chat.rb +0 -28
- data/lib/telegram/bot/types/chat_administrator_rights.rb +3 -3
- data/lib/telegram/bot/types/chat_background.rb +11 -0
- data/lib/telegram/bot/types/chat_boost_added.rb +11 -0
- data/lib/telegram/bot/types/chat_boost_source.rb +4 -1
- data/lib/telegram/bot/types/chat_boost_source_giveaway.rb +1 -0
- data/lib/telegram/bot/types/chat_full_info.rb +54 -0
- data/lib/telegram/bot/types/chat_invite_link.rb +2 -0
- data/lib/telegram/bot/types/chat_location.rb +1 -1
- data/lib/telegram/bot/types/chat_member.rb +4 -4
- data/lib/telegram/bot/types/chat_member_administrator.rb +3 -3
- data/lib/telegram/bot/types/chat_member_member.rb +1 -0
- data/lib/telegram/bot/types/chat_member_updated.rb +1 -0
- data/lib/telegram/bot/types/chat_shared.rb +3 -0
- data/lib/telegram/bot/types/copy_text_button.rb +11 -0
- data/lib/telegram/bot/types/error.rb +14 -0
- data/lib/telegram/bot/types/external_reply_info.rb +1 -0
- data/lib/telegram/bot/types/force_reply.rb +2 -2
- data/lib/telegram/bot/types/gift.rb +15 -0
- data/lib/telegram/bot/types/gifts.rb +11 -0
- data/lib/telegram/bot/types/giveaway.rb +1 -0
- data/lib/telegram/bot/types/giveaway_completed.rb +1 -0
- data/lib/telegram/bot/types/giveaway_created.rb +1 -0
- data/lib/telegram/bot/types/giveaway_winners.rb +1 -0
- data/lib/telegram/bot/types/inline_keyboard_button.rb +2 -1
- data/lib/telegram/bot/types/inline_query_result.rb +33 -0
- data/lib/telegram/bot/types/inline_query_result_cached_gif.rb +1 -0
- data/lib/telegram/bot/types/inline_query_result_cached_mpeg4_gif.rb +1 -0
- data/lib/telegram/bot/types/inline_query_result_cached_photo.rb +1 -0
- data/lib/telegram/bot/types/inline_query_result_cached_video.rb +1 -0
- data/lib/telegram/bot/types/inline_query_result_gif.rb +2 -1
- data/lib/telegram/bot/types/inline_query_result_mpeg4_gif.rb +2 -1
- data/lib/telegram/bot/types/inline_query_result_photo.rb +1 -0
- data/lib/telegram/bot/types/inline_query_result_video.rb +1 -0
- data/lib/telegram/bot/types/inline_query_results_button.rb +13 -0
- data/lib/telegram/bot/types/input_contact_message_content.rb +1 -1
- data/lib/telegram/bot/types/input_invoice_message_content.rb +5 -5
- data/lib/telegram/bot/types/input_location_message_content.rb +1 -1
- data/lib/telegram/bot/types/input_media.rb +18 -0
- data/lib/telegram/bot/types/input_media_animation.rb +1 -0
- data/lib/telegram/bot/types/input_media_photo.rb +1 -0
- data/lib/telegram/bot/types/input_media_video.rb +1 -0
- data/lib/telegram/bot/types/input_message_content.rb +10 -2
- data/lib/telegram/bot/types/input_paid_media.rb +15 -0
- data/lib/telegram/bot/types/input_paid_media_photo.rb +12 -0
- data/lib/telegram/bot/types/input_paid_media_video.rb +17 -0
- data/lib/telegram/bot/types/input_poll_option.rb +13 -0
- data/lib/telegram/bot/types/input_sticker.rb +15 -0
- data/lib/telegram/bot/types/input_text_message_content.rb +2 -2
- data/lib/telegram/bot/types/input_venue_message_content.rb +1 -1
- data/lib/telegram/bot/types/keyboard_button_request_chat.rb +3 -0
- data/lib/telegram/bot/types/keyboard_button_request_users.rb +3 -0
- data/lib/telegram/bot/types/location.rb +1 -1
- data/lib/telegram/bot/types/maybe_inaccessible_message.rb +4 -1
- data/lib/telegram/bot/types/menu_button.rb +16 -0
- data/lib/telegram/bot/types/message.rb +11 -0
- data/lib/telegram/bot/types/message_origin.rb +4 -1
- data/lib/telegram/bot/types/paid_media.rb +16 -0
- data/lib/telegram/bot/types/paid_media_info.rb +12 -0
- data/lib/telegram/bot/types/paid_media_photo.rb +12 -0
- data/lib/telegram/bot/types/paid_media_preview.rb +14 -0
- data/lib/telegram/bot/types/paid_media_purchased.rb +12 -0
- data/lib/telegram/bot/types/paid_media_video.rb +12 -0
- data/lib/telegram/bot/types/passport_element_error.rb +22 -0
- data/lib/telegram/bot/types/poll.rb +2 -1
- data/lib/telegram/bot/types/poll_option.rb +2 -1
- data/lib/telegram/bot/types/prepared_inline_message.rb +12 -0
- data/lib/telegram/bot/types/reaction_type.rb +6 -2
- data/lib/telegram/bot/types/reaction_type_paid.rb +11 -0
- data/lib/telegram/bot/types/refunded_payment.rb +15 -0
- data/lib/telegram/bot/types/reply_keyboard_markup.rb +2 -2
- data/lib/telegram/bot/types/reply_keyboard_remove.rb +1 -1
- data/lib/telegram/bot/types/response_parameters.rb +12 -0
- data/lib/telegram/bot/types/revenue_withdrawal_state.rb +16 -0
- data/lib/telegram/bot/types/revenue_withdrawal_state_failed.rb +11 -0
- data/lib/telegram/bot/types/revenue_withdrawal_state_pending.rb +11 -0
- data/lib/telegram/bot/types/revenue_withdrawal_state_succeeded.rb +13 -0
- data/lib/telegram/bot/types/shared_user.rb +15 -0
- data/lib/telegram/bot/types/star_transaction.rb +16 -0
- data/lib/telegram/bot/types/star_transactions.rb +11 -0
- data/lib/telegram/bot/types/sticker_set.rb +0 -2
- data/lib/telegram/bot/types/story.rb +4 -1
- data/lib/telegram/bot/types/successful_payment.rb +3 -0
- data/lib/telegram/bot/types/transaction_partner.rb +19 -0
- data/lib/telegram/bot/types/transaction_partner_affiliate_program.rb +13 -0
- data/lib/telegram/bot/types/transaction_partner_fragment.rb +12 -0
- data/lib/telegram/bot/types/transaction_partner_other.rb +11 -0
- data/lib/telegram/bot/types/transaction_partner_telegram_ads.rb +11 -0
- data/lib/telegram/bot/types/transaction_partner_telegram_api.rb +12 -0
- data/lib/telegram/bot/types/transaction_partner_user.rb +18 -0
- data/lib/telegram/bot/types/update.rb +5 -0
- data/lib/telegram/bot/types/user.rb +2 -0
- data/lib/telegram/bot/types/users_shared.rb +1 -1
- data/lib/telegram/bot/version.rb +1 -1
- data/rakelib/parse_schema.rake +73 -0
- data/rakelib/rebuild_types.rake +90 -0
- data/rakelib/templates/empty_type.erb +14 -0
- data/rakelib/templates/type.erb +13 -0
- data/telegram-bot-ruby.gemspec +1 -1
- metadata +66 -3
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
## Just for classes consistency
|
7
|
+
# rubocop:disable Naming/ConstantName
|
8
|
+
PaidMedia = (
|
9
|
+
PaidMediaPreview |
|
10
|
+
PaidMediaPhoto |
|
11
|
+
PaidMediaVideo
|
12
|
+
)
|
13
|
+
# rubocop:enable Naming/ConstantName
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class PaidMediaPhoto < Base
|
7
|
+
attribute :type, Types::String.constrained(eql: 'photo').default('photo')
|
8
|
+
attribute :photo, Types::Array.of(PhotoSize)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class PaidMediaPreview < Base
|
7
|
+
attribute :type, Types::String.constrained(eql: 'preview').default('preview')
|
8
|
+
attribute? :width, Types::Integer
|
9
|
+
attribute? :height, Types::Integer
|
10
|
+
attribute? :duration, Types::Integer
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
## Just for classes consistency
|
7
|
+
# rubocop:disable Naming/ConstantName
|
8
|
+
PassportElementError = (
|
9
|
+
PassportElementErrorDataField |
|
10
|
+
PassportElementErrorFrontSide |
|
11
|
+
PassportElementErrorReverseSide |
|
12
|
+
PassportElementErrorSelfie |
|
13
|
+
PassportElementErrorFile |
|
14
|
+
PassportElementErrorFiles |
|
15
|
+
PassportElementErrorTranslationFile |
|
16
|
+
PassportElementErrorTranslationFiles |
|
17
|
+
PassportElementErrorUnspecified
|
18
|
+
)
|
19
|
+
# rubocop:enable Naming/ConstantName
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -5,7 +5,8 @@ module Telegram
|
|
5
5
|
module Types
|
6
6
|
class Poll < Base
|
7
7
|
attribute :id, Types::String
|
8
|
-
attribute :question, Types::String
|
8
|
+
attribute :question, Types::String.constrained(min_size: 1, max_size: 300)
|
9
|
+
attribute? :question_entities, Types::Array.of(MessageEntity)
|
9
10
|
attribute :options, Types::Array.of(PollOption)
|
10
11
|
attribute :total_voter_count, Types::Integer
|
11
12
|
attribute :is_closed, Types::Bool
|
@@ -4,7 +4,8 @@ module Telegram
|
|
4
4
|
module Bot
|
5
5
|
module Types
|
6
6
|
class PollOption < Base
|
7
|
-
attribute :text, Types::String
|
7
|
+
attribute :text, Types::String.constrained(min_size: 1, max_size: 100)
|
8
|
+
attribute? :text_entities, Types::Array.of(MessageEntity)
|
8
9
|
attribute :voter_count, Types::Integer
|
9
10
|
end
|
10
11
|
end
|
@@ -3,10 +3,14 @@
|
|
3
3
|
module Telegram
|
4
4
|
module Bot
|
5
5
|
module Types
|
6
|
-
|
6
|
+
## Just for classes consistency
|
7
|
+
# rubocop:disable Naming/ConstantName
|
8
|
+
ReactionType = (
|
7
9
|
ReactionTypeEmoji |
|
8
|
-
ReactionTypeCustomEmoji
|
10
|
+
ReactionTypeCustomEmoji |
|
11
|
+
ReactionTypePaid
|
9
12
|
)
|
13
|
+
# rubocop:enable Naming/ConstantName
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class RefundedPayment < Base
|
7
|
+
attribute :currency, Types::String.constrained(eql: 'XTR').default('XTR')
|
8
|
+
attribute :total_amount, Types::Integer
|
9
|
+
attribute :invoice_payload, Types::String
|
10
|
+
attribute :telegram_payment_charge_id, Types::String
|
11
|
+
attribute? :provider_payment_charge_id, Types::String
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -8,8 +8,8 @@ module Telegram
|
|
8
8
|
attribute? :is_persistent, Types::Bool.default(false)
|
9
9
|
attribute? :resize_keyboard, Types::Bool.default(false)
|
10
10
|
attribute? :one_time_keyboard, Types::Bool.default(false)
|
11
|
-
attribute? :input_field_placeholder, Types::String
|
12
|
-
attribute? :selective, Types::Bool
|
11
|
+
attribute? :input_field_placeholder, Types::String.constrained(min_size: 1, max_size: 64)
|
12
|
+
attribute? :selective, Types::Bool
|
13
13
|
|
14
14
|
def to_compact_hash
|
15
15
|
hsh = super
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
## Just for classes consistency
|
7
|
+
# rubocop:disable Naming/ConstantName
|
8
|
+
RevenueWithdrawalState = (
|
9
|
+
RevenueWithdrawalStatePending |
|
10
|
+
RevenueWithdrawalStateSucceeded |
|
11
|
+
RevenueWithdrawalStateFailed
|
12
|
+
)
|
13
|
+
# rubocop:enable Naming/ConstantName
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class RevenueWithdrawalStateSucceeded < Base
|
7
|
+
attribute :type, Types::String.constrained(eql: 'succeeded').default('succeeded')
|
8
|
+
attribute :date, Types::Integer
|
9
|
+
attribute :url, Types::String
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class SharedUser < Base
|
7
|
+
attribute :user_id, Types::Integer
|
8
|
+
attribute? :first_name, Types::String
|
9
|
+
attribute? :last_name, Types::String
|
10
|
+
attribute? :username, Types::String
|
11
|
+
attribute? :photo, Types::Array.of(PhotoSize)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class StarTransaction < Base
|
7
|
+
attribute :id, Types::String
|
8
|
+
attribute :amount, Types::Integer
|
9
|
+
attribute? :nanostar_amount, Types::Integer
|
10
|
+
attribute :date, Types::Integer
|
11
|
+
attribute? :source, TransactionPartner
|
12
|
+
attribute? :receiver, TransactionPartner
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -7,8 +7,6 @@ module Telegram
|
|
7
7
|
attribute :name, Types::String
|
8
8
|
attribute :title, Types::String
|
9
9
|
attribute :sticker_type, Types::String
|
10
|
-
attribute :is_animated, Types::Bool
|
11
|
-
attribute :is_video, Types::Bool
|
12
10
|
attribute :stickers, Types::Array.of(Sticker)
|
13
11
|
attribute? :thumbnail, PhotoSize
|
14
12
|
end
|
@@ -7,6 +7,9 @@ module Telegram
|
|
7
7
|
attribute :currency, Types::String
|
8
8
|
attribute :total_amount, Types::Integer
|
9
9
|
attribute :invoice_payload, Types::String
|
10
|
+
attribute? :subscription_expiration_date, Types::Integer
|
11
|
+
attribute? :is_recurring, Types::True
|
12
|
+
attribute? :is_first_recurring, Types::True
|
10
13
|
attribute? :shipping_option_id, Types::String
|
11
14
|
attribute? :order_info, OrderInfo
|
12
15
|
attribute :telegram_payment_charge_id, Types::String
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
## Just for classes consistency
|
7
|
+
# rubocop:disable Naming/ConstantName
|
8
|
+
TransactionPartner = (
|
9
|
+
TransactionPartnerUser |
|
10
|
+
TransactionPartnerAffiliateProgram |
|
11
|
+
TransactionPartnerFragment |
|
12
|
+
TransactionPartnerTelegramAds |
|
13
|
+
TransactionPartnerTelegramApi |
|
14
|
+
TransactionPartnerOther
|
15
|
+
)
|
16
|
+
# rubocop:enable Naming/ConstantName
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class TransactionPartnerAffiliateProgram < Base
|
7
|
+
attribute :type, Types::String.constrained(eql: 'affiliate_program').default('affiliate_program')
|
8
|
+
attribute? :sponsor_user, User
|
9
|
+
attribute :commission_per_mille, Types::Integer
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class TransactionPartnerFragment < Base
|
7
|
+
attribute :type, Types::String.constrained(eql: 'fragment').default('fragment')
|
8
|
+
attribute? :withdrawal_state, RevenueWithdrawalState
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class TransactionPartnerTelegramApi < Base
|
7
|
+
attribute :type, Types::String.constrained(eql: 'telegram_api').default('telegram_api')
|
8
|
+
attribute :request_count, Types::Integer
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Bot
|
5
|
+
module Types
|
6
|
+
class TransactionPartnerUser < Base
|
7
|
+
attribute :type, Types::String.constrained(eql: 'user').default('user')
|
8
|
+
attribute :user, User
|
9
|
+
attribute? :affiliate, AffiliateInfo
|
10
|
+
attribute? :invoice_payload, Types::String
|
11
|
+
attribute? :subscription_period, Types::Integer
|
12
|
+
attribute? :paid_media, Types::Array.of(PaidMedia)
|
13
|
+
attribute? :paid_media_payload, Types::String
|
14
|
+
attribute? :gift, Gift
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -9,6 +9,10 @@ module Telegram
|
|
9
9
|
attribute? :edited_message, Message
|
10
10
|
attribute? :channel_post, Message
|
11
11
|
attribute? :edited_channel_post, Message
|
12
|
+
attribute? :business_connection, BusinessConnection
|
13
|
+
attribute? :business_message, Message
|
14
|
+
attribute? :edited_business_message, Message
|
15
|
+
attribute? :deleted_business_messages, BusinessMessagesDeleted
|
12
16
|
attribute? :message_reaction, MessageReactionUpdated
|
13
17
|
attribute? :message_reaction_count, MessageReactionCountUpdated
|
14
18
|
attribute? :inline_query, InlineQuery
|
@@ -16,6 +20,7 @@ module Telegram
|
|
16
20
|
attribute? :callback_query, CallbackQuery
|
17
21
|
attribute? :shipping_query, ShippingQuery
|
18
22
|
attribute? :pre_checkout_query, PreCheckoutQuery
|
23
|
+
attribute? :purchased_paid_media, PaidMediaPurchased
|
19
24
|
attribute? :poll, Poll
|
20
25
|
attribute? :poll_answer, PollAnswer
|
21
26
|
attribute? :my_chat_member, ChatMemberUpdated
|
@@ -15,6 +15,8 @@ module Telegram
|
|
15
15
|
attribute? :can_join_groups, Types::Bool
|
16
16
|
attribute? :can_read_all_group_messages, Types::Bool
|
17
17
|
attribute? :supports_inline_queries, Types::Bool
|
18
|
+
attribute? :can_connect_to_business, Types::Bool
|
19
|
+
attribute? :has_main_web_app, Types::Bool
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
data/lib/telegram/bot/version.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openapi3_parser'
|
4
|
+
|
5
|
+
desc 'Parse types from public json, should be up to date https://github.com/ark0f/tg-bot-api'
|
6
|
+
task :parse_schema do
|
7
|
+
document = Openapi3Parser.load_url('https://ark0f.github.io/tg-bot-api/openapi.json')
|
8
|
+
|
9
|
+
result = document.components.schemas.to_h do |type_name, schema|
|
10
|
+
type_schema = schema.properties.to_h do |property_name, property_schema|
|
11
|
+
attribute = { type: parse_initial_type(property_schema, property_name) }
|
12
|
+
|
13
|
+
unless property_schema.any_of.nil?
|
14
|
+
attribute[:type] = property_schema.any_of.map { |item| property_schema.name || item.name || item.type }.uniq
|
15
|
+
end
|
16
|
+
|
17
|
+
# Input File is literally just a string for our purpose
|
18
|
+
attribute[:type]&.delete('InputFile')
|
19
|
+
attribute[:type] = attribute[:type].join if attribute[:type]&.length == 1
|
20
|
+
|
21
|
+
attribute[:required] = true if required_keys(schema).include?(property_name)
|
22
|
+
|
23
|
+
# getting required values from the description, no values in json 😔
|
24
|
+
required_value = property_schema.description&.match(/always “(.+)”|must be \*(.+)\*/)
|
25
|
+
attribute[:required_value] = (required_value[1] || required_value[2]).delete('\\') if required_value
|
26
|
+
|
27
|
+
# for some reason every property's minLength is 0 by default, probably parser bug, had to ignore that
|
28
|
+
attribute[:min_size] = property_schema[:minLength] if property_schema[:minLength] != 0
|
29
|
+
attribute[:max_size] = property_schema[:maxLength] if property_schema[:maxLength]
|
30
|
+
|
31
|
+
attribute[:items] = property_schema.items.type if property_schema&.items
|
32
|
+
if property_schema&.type == 'array' && property_schema&.items&.type.nil?
|
33
|
+
attribute[:items] = property_schema&.items&.name
|
34
|
+
end
|
35
|
+
|
36
|
+
attribute[:items] = property_schema.items.name if property_schema&.items&.type == 'object'
|
37
|
+
|
38
|
+
# array of arrays
|
39
|
+
if property_schema&.items&.type == 'array'
|
40
|
+
attribute[:items] = { type: 'array', items: property_schema.items.items.name }
|
41
|
+
end
|
42
|
+
|
43
|
+
attribute = apply_default_schema(attribute, property_schema)
|
44
|
+
[property_name, attribute]
|
45
|
+
end
|
46
|
+
|
47
|
+
# find empty classes
|
48
|
+
type_schema[:type] = schema.any_of.map(&:name) if schema.properties.empty? && schema.any_of
|
49
|
+
[type_name, type_schema]
|
50
|
+
end
|
51
|
+
|
52
|
+
# Input File is literally just a string for our purpose
|
53
|
+
File.write "#{__dir__}/../data/type_attributes.json", JSON.pretty_generate(result.except('InputFile'))
|
54
|
+
end
|
55
|
+
|
56
|
+
def required_keys(schema)
|
57
|
+
schema.required.to_a || []
|
58
|
+
end
|
59
|
+
|
60
|
+
def apply_default_schema(attribute, property_schema)
|
61
|
+
attribute[:default] = property_schema.default unless property_schema.default.nil?
|
62
|
+
# previous line would have been enough, but had to check the description due to issue: https://github.com/kevindew/openapi3_parser/issues/28
|
63
|
+
attribute[:default] = false if property_schema.description&.include?('Defaults to *false*')
|
64
|
+
attribute
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_initial_type(property_schema, property_name)
|
68
|
+
case property_schema.type
|
69
|
+
when nil then property_name.capitalize.gsub(/_(\w)/) { Regexp.last_match(1).upcase }
|
70
|
+
when 'object' then property_schema.name
|
71
|
+
else property_schema.type
|
72
|
+
end
|
73
|
+
end
|