Skip to content

Commit

Permalink
Merge pull request #3 from alllex/update-api-model-interface-classes
Browse files Browse the repository at this point in the history
Use sealed interfaces for model types
  • Loading branch information
alllex authored Mar 21, 2024
2 parents 2e45808 + 3d78b68 commit 7cf4e71
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 112 deletions.
30 changes: 9 additions & 21 deletions api/tbot-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,8 @@ public final class me/alllex/tbot/api/model/BotCommand$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class me/alllex/tbot/api/model/BotCommandScope {
public abstract interface class me/alllex/tbot/api/model/BotCommandScope {
public static final field Companion Lme/alllex/tbot/api/model/BotCommandScope$Companion;
public synthetic fun <init> (ILkotlinx/serialization/internal/SerializationConstructorMarker;)V
public static final synthetic fun write$Self (Lme/alllex/tbot/api/model/BotCommandScope;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class me/alllex/tbot/api/model/BotCommandScope$Companion {
Expand Down Expand Up @@ -1188,10 +1186,8 @@ public final class me/alllex/tbot/api/model/ChatLocation$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class me/alllex/tbot/api/model/ChatMember {
public abstract interface class me/alllex/tbot/api/model/ChatMember {
public static final field Companion Lme/alllex/tbot/api/model/ChatMember$Companion;
public synthetic fun <init> (ILkotlinx/serialization/internal/SerializationConstructorMarker;)V
public static final synthetic fun write$Self (Lme/alllex/tbot/api/model/ChatMember;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class me/alllex/tbot/api/model/ChatMember$Companion {
Expand Down Expand Up @@ -3900,10 +3896,8 @@ public final class me/alllex/tbot/api/model/InlineQueryId$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class me/alllex/tbot/api/model/InlineQueryResult {
public abstract interface class me/alllex/tbot/api/model/InlineQueryResult {
public static final field Companion Lme/alllex/tbot/api/model/InlineQueryResult$Companion;
public synthetic fun <init> (ILkotlinx/serialization/internal/SerializationConstructorMarker;)V
public static final synthetic fun write$Self (Lme/alllex/tbot/api/model/InlineQueryResult;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class me/alllex/tbot/api/model/InlineQueryResult$Companion {
Expand Down Expand Up @@ -5052,10 +5046,8 @@ public final class me/alllex/tbot/api/model/InputLocationMessageContent$Companio
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class me/alllex/tbot/api/model/InputMedia {
public abstract interface class me/alllex/tbot/api/model/InputMedia {
public static final field Companion Lme/alllex/tbot/api/model/InputMedia$Companion;
public synthetic fun <init> (ILkotlinx/serialization/internal/SerializationConstructorMarker;)V
public static final synthetic fun write$Self (Lme/alllex/tbot/api/model/InputMedia;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class me/alllex/tbot/api/model/InputMedia$Companion {
Expand Down Expand Up @@ -5268,7 +5260,7 @@ public final class me/alllex/tbot/api/model/InputMediaVideo$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class me/alllex/tbot/api/model/InputMessageContent {
public abstract interface class me/alllex/tbot/api/model/InputMessageContent {
public static final field Companion Lme/alllex/tbot/api/model/InputMessageContent$Companion;
}

Expand Down Expand Up @@ -5729,10 +5721,8 @@ public final class me/alllex/tbot/api/model/MaskPosition$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class me/alllex/tbot/api/model/MenuButton {
public abstract interface class me/alllex/tbot/api/model/MenuButton {
public static final field Companion Lme/alllex/tbot/api/model/MenuButton$Companion;
public synthetic fun <init> (ILkotlinx/serialization/internal/SerializationConstructorMarker;)V
public static final synthetic fun write$Self (Lme/alllex/tbot/api/model/MenuButton;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class me/alllex/tbot/api/model/MenuButton$Companion {
Expand Down Expand Up @@ -6447,10 +6437,8 @@ public final class me/alllex/tbot/api/model/PassportData$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class me/alllex/tbot/api/model/PassportElementError {
public abstract interface class me/alllex/tbot/api/model/PassportElementError {
public static final field Companion Lme/alllex/tbot/api/model/PassportElementError$Companion;
public synthetic fun <init> (ILkotlinx/serialization/internal/SerializationConstructorMarker;)V
public static final synthetic fun write$Self (Lme/alllex/tbot/api/model/PassportElementError;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class me/alllex/tbot/api/model/PassportElementError$Companion {
Expand Down Expand Up @@ -7317,7 +7305,7 @@ public final class me/alllex/tbot/api/model/ReplyKeyboardRemove$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class me/alllex/tbot/api/model/ReplyMarkup {
public abstract interface class me/alllex/tbot/api/model/ReplyMarkup {
public static final field Companion Lme/alllex/tbot/api/model/ReplyMarkup$Companion;
}

Expand Down Expand Up @@ -10246,7 +10234,7 @@ public final class me/alllex/tbot/api/model/UnpinChatMessageRequest$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class me/alllex/tbot/api/model/Update {
public abstract interface class me/alllex/tbot/api/model/Update {
public static final field Companion Lme/alllex/tbot/api/model/Update$Companion;
public abstract fun getUpdateId ()J
public abstract fun getUpdateType ()Lme/alllex/tbot/api/model/UpdateType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,9 @@ class BotApiGenerator {
}
appendLine(" */")
appendLine("@Serializable(with = ${name}Serializer::class)")
appendLine("sealed class $name {")
appendLine(" abstract val updateId: Long")
appendLine(" abstract val updateType: UpdateType")
appendLine("sealed interface $name {")
appendLine(" val updateId: Long")
appendLine(" val updateType: UpdateType")
appendLine("}")
for (updateField in types) {
appendLine()
Expand All @@ -749,7 +749,7 @@ class BotApiGenerator {
appendLine("data class ${updateField.updateTypeName()}(")
appendLine(" override val updateId: Long,")
appendLine(" val ${updateField.name}: ${updateField.type},")
appendLine("): $name() {")
appendLine("): $name {")
appendLine(" override val updateType: UpdateType get() = UpdateType.${updateField.enumValue()}")
appendLine("}")
}
Expand Down Expand Up @@ -798,7 +798,7 @@ class BotApiGenerator {
appendLine("@JsonClassDiscriminator(\"$discriminatorFieldName\")")
}

appendLine("sealed class ${name.value}")
appendLine("sealed interface ${name.value}")

if (discriminatorFieldName == null) {
val avoidFields = setOf("description")
Expand Down Expand Up @@ -872,7 +872,7 @@ class BotApiGenerator {
append("data object ")
append(typeName.value)
if (sealedParentName != null) {
append(" : ${sealedParentName.value}()")
append(" : ${sealedParentName.value}")
}
appendLine()
} else {
Expand All @@ -884,7 +884,7 @@ class BotApiGenerator {

append(")")
if (sealedParentName != null) {
append(" : ${sealedParentName.value}()")
append(" : ${sealedParentName.value}")
}
appendLine(" {")
appendLine(" ${generateDebugToString(typeName.value, trueFields)}")
Expand Down
Loading

0 comments on commit 7cf4e71

Please sign in to comment.