From 24eb4b4a3687b7e8e8d0addaaef71a168cd1495f Mon Sep 17 00:00:00 2001 From: Ruslan Ibragimov Date: Sat, 19 Aug 2023 10:54:04 +0300 Subject: [PATCH] Generate reply_markup child --- core-gen/src/main/kotlin/Generate.kt | 15 ++++++++++++--- .../io/heapy/kotbot/bot/model/ForceReply.kt | 2 +- .../heapy/kotbot/bot/model/ReplyKeyboardMarkup.kt | 2 +- .../heapy/kotbot/bot/model/ReplyKeyboardRemove.kt | 2 +- .../io/heapy/kotbot/bot/model/ReplyMarkup.kt} | 3 --- 5 files changed, 15 insertions(+), 9 deletions(-) rename core/src/{generated/kotlin/io/heapy/kotbot/bot/model/_todo_.kt => main/kotlin/io/heapy/kotbot/bot/model/ReplyMarkup.kt} (75%) diff --git a/core-gen/src/main/kotlin/Generate.kt b/core-gen/src/main/kotlin/Generate.kt index e80b607..885c16e 100644 --- a/core-gen/src/main/kotlin/Generate.kt +++ b/core-gen/src/main/kotlin/Generate.kt @@ -27,16 +27,25 @@ fun main() { } fun TelegramApi.generate() { - val supertypeMapping = objects + val objectSupertypeMapping = objects .filterIsInstance() .flatMap { anyOf -> anyOf.any_of.map { (it as ReferenceApiType).reference to anyOf.name } } .toMap() - val methodFiles = methods.map(Method::toFileSpec) + val methodSupertypeMapping = methods.flatMap { it.arguments ?: emptyList() } + .filterIsInstance() + .flatMap { anyOf -> + anyOf.any_of + .filterIsInstance() + .map { it.reference to anyOf.name.snakeToTitle() } + } + .toMap() + + val methodFiles = methods.map { it.toFileSpec() } - val objectsFiles = objects.map { it.toFileSpec(supertypeMapping) } + val objectsFiles = objects.map { it.toFileSpec(objectSupertypeMapping + methodSupertypeMapping) } val anyOfArgumentsFiles = objects.filterIsInstance() .flatMap(PropertiesObject::toAnyOfArguments) diff --git a/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ForceReply.kt b/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ForceReply.kt index a943fc5..9ab8ac5 100644 --- a/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ForceReply.kt +++ b/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ForceReply.kt @@ -21,4 +21,4 @@ public data class ForceReply( * *Optional*. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the *text* of the [Message](https://core.telegram.org/bots/api/#message) object; 2) if the bot's message is a reply (has *reply_to_message_id*), sender of the original message. */ public val selective: Boolean? = null, -) +) : ReplyMarkup diff --git a/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ReplyKeyboardMarkup.kt b/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ReplyKeyboardMarkup.kt index 5ba7b1e..66015e0 100644 --- a/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ReplyKeyboardMarkup.kt +++ b/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ReplyKeyboardMarkup.kt @@ -36,4 +36,4 @@ public data class ReplyKeyboardMarkup( * *Example:* A user requests to change the bot's language, bot replies to the request with a keyboard to select the new language. Other users in the group don't see the keyboard. */ public val selective: Boolean? = null, -) +) : ReplyMarkup diff --git a/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ReplyKeyboardRemove.kt b/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ReplyKeyboardRemove.kt index fd0399b..f2474a0 100644 --- a/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ReplyKeyboardRemove.kt +++ b/core/src/generated/kotlin/io/heapy/kotbot/bot/model/ReplyKeyboardRemove.kt @@ -18,4 +18,4 @@ public data class ReplyKeyboardRemove( * *Example:* A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. */ public val selective: Boolean? = null, -) +) : ReplyMarkup diff --git a/core/src/generated/kotlin/io/heapy/kotbot/bot/model/_todo_.kt b/core/src/main/kotlin/io/heapy/kotbot/bot/model/ReplyMarkup.kt similarity index 75% rename from core/src/generated/kotlin/io/heapy/kotbot/bot/model/_todo_.kt rename to core/src/main/kotlin/io/heapy/kotbot/bot/model/ReplyMarkup.kt index 068d2ca..bb3adf0 100644 --- a/core/src/generated/kotlin/io/heapy/kotbot/bot/model/_todo_.kt +++ b/core/src/main/kotlin/io/heapy/kotbot/bot/model/ReplyMarkup.kt @@ -2,8 +2,5 @@ package io.heapy.kotbot.bot.model import kotlinx.serialization.Serializable -/** - * TODO: Generate sealead classes - */ @Serializable public sealed interface ReplyMarkup