From f06169e3a77f05061656280be828078b7580e784 Mon Sep 17 00:00:00 2001 From: Ivan Semenov Date: Tue, 26 Nov 2024 12:29:29 +0100 Subject: [PATCH] [github] add default impl to polymorphic DTOs This ensures forward compatibility GitOrigin-RevId: b1192cd40b7fa86d9f32ff1aade8ec602d70e5ed --- .../jetbrains/plugins/github/api/data/GHActor.kt | 11 ++++++++++- .../github/api/data/GHRepositoryOwnerName.kt | 15 +++++++++------ .../pullrequest/GHPullRequestRequestedReviewer.kt | 12 +++++++++++- .../pullrequest/timeline/GHPRReferencedSubject.kt | 7 +++++-- .../plugins/gitlab/api/dto/GitLabWorkItemDTO.kt | 3 ++- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/data/GHActor.kt b/plugins/github/src/org/jetbrains/plugins/github/api/data/GHActor.kt index 05400867dbf5..bd194443a9ba 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/data/GHActor.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/api/data/GHActor.kt @@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nls @GraphQLFragment("/graphql/fragment/actorInfo.graphql") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "__typename", visible = false, - defaultImpl = GHActor::class) + defaultImpl = GHActor.Unknown::class) @JsonSubTypes( JsonSubTypes.Type(name = "User", value = GHUser::class), JsonSubTypes.Type(name = "Bot", value = GHBot::class), @@ -23,4 +23,13 @@ interface GHActor : CodeReviewUser { override val avatarUrl: String fun getPresentableName(): @Nls String + + class Unknown( + override val id: String, + override val login: String, + override val url: String, + override val avatarUrl: String, + ) : GHActor { + override fun getPresentableName(): @Nls String = login //NON-NLS + } } \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/data/GHRepositoryOwnerName.kt b/plugins/github/src/org/jetbrains/plugins/github/api/data/GHRepositoryOwnerName.kt index 3ac298b29753..50b68b041d42 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/data/GHRepositoryOwnerName.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/api/data/GHRepositoryOwnerName.kt @@ -4,16 +4,19 @@ package org.jetbrains.plugins.github.api.data import com.fasterxml.jackson.annotation.JsonSubTypes import com.fasterxml.jackson.annotation.JsonTypeInfo import com.intellij.collaboration.api.dto.GraphQLFragment +import org.jetbrains.annotations.ApiStatus.NonExtendable @GraphQLFragment("/graphql/fragment/repositoryOwnerName.graphql") -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "__typename", visible = false) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "__typename", visible = false, + defaultImpl = GHRepositoryOwnerName::class) @JsonSubTypes( JsonSubTypes.Type(name = "User", value = GHRepositoryOwnerName.User::class), JsonSubTypes.Type(name = "Organization", value = GHRepositoryOwnerName.Organization::class) ) -interface GHRepositoryOwnerName { - val login: String - - class User(override val login: String) : GHRepositoryOwnerName - class Organization(override val login: String) : GHRepositoryOwnerName +@NonExtendable +open class GHRepositoryOwnerName( + val login: String, +) { + class User(login: String) : GHRepositoryOwnerName(login) + class Organization(login: String) : GHRepositoryOwnerName(login) } \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/GHPullRequestRequestedReviewer.kt b/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/GHPullRequestRequestedReviewer.kt index 644388ea6d19..e38d10a00e18 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/GHPullRequestRequestedReviewer.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/GHPullRequestRequestedReviewer.kt @@ -8,7 +8,8 @@ import com.intellij.openapi.util.NlsSafe import org.jetbrains.plugins.github.api.data.GHUser @GraphQLFragment("/graphql/fragment/pullRequestReviewerInfo.graphql") -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "__typename", visible = false) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "__typename", visible = false, + defaultImpl = GHPullRequestRequestedReviewer.Unknown::class) @JsonSubTypes( JsonSubTypes.Type(name = "User", value = GHUser::class), JsonSubTypes.Type(name = "Team", value = GHTeam::class) @@ -21,4 +22,13 @@ interface GHPullRequestRequestedReviewer { val name: String? fun getPresentableName(): @NlsSafe String = name ?: shortName + + class Unknown( + override val id: String, + override val url: String, + override val avatarUrl: String, + override val name: String?, + ) : GHPullRequestRequestedReviewer { + override val shortName: String = id + } } \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/timeline/GHPRReferencedSubject.kt b/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/timeline/GHPRReferencedSubject.kt index d73cb7ccace9..bd26bb9d828b 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/timeline/GHPRReferencedSubject.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/timeline/GHPRReferencedSubject.kt @@ -3,16 +3,19 @@ package org.jetbrains.plugins.github.api.data.pullrequest.timeline import com.fasterxml.jackson.annotation.JsonSubTypes import com.fasterxml.jackson.annotation.JsonTypeInfo +import org.jetbrains.annotations.ApiStatus.NonExtendable import org.jetbrains.annotations.Nls import org.jetbrains.plugins.github.api.data.GithubIssueState import org.jetbrains.plugins.github.api.data.pullrequest.GHPullRequestState -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "__typename", visible = false) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "__typename", visible = false, + defaultImpl = GHPRReferencedSubject::class) @JsonSubTypes( JsonSubTypes.Type(name = "Issue", value = GHPRReferencedSubject.Issue::class), JsonSubTypes.Type(name = "PullRequest", value = GHPRReferencedSubject.PullRequest::class) ) -sealed class GHPRReferencedSubject(val title: @Nls String, val number: Long, val url: String) { +@NonExtendable +open class GHPRReferencedSubject(val title: @Nls String, val number: Long, val url: String) { class Issue(title: @Nls String, number: Long, url: String, val state: GithubIssueState) : GHPRReferencedSubject(title, number, url) diff --git a/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/api/dto/GitLabWorkItemDTO.kt b/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/api/dto/GitLabWorkItemDTO.kt index 8cf34e16e4ca..e209c6bc1fda 100644 --- a/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/api/dto/GitLabWorkItemDTO.kt +++ b/plugins/gitlab/gitlab-core/src/org/jetbrains/plugins/gitlab/api/dto/GitLabWorkItemDTO.kt @@ -24,7 +24,7 @@ data class GitLabWorkItemDTO( include = JsonTypeInfo.As.PROPERTY, property = "__typename", visible = false, - defaultImpl = GitLabWidgetDTO::class + defaultImpl = Unknown::class ) @JsonSubTypes( JsonSubTypes.Type(name = "WorkItemWidgetAssignees", value = WorkItemWidgetAssignees::class), @@ -54,5 +54,6 @@ data class GitLabWorkItemDTO( class WorkItemWidgetNotes : GitLabWidgetDTO class WorkItemWidgetNotifications : GitLabWidgetDTO class WorkItemWidgetStartAndDueDate : GitLabWidgetDTO + class Unknown : GitLabWidgetDTO } } \ No newline at end of file