diff --git a/backend/src/main/java/io/papermc/hangar/model/internal/versions/MultipartFileOrUrl.java b/backend/src/main/java/io/papermc/hangar/model/internal/versions/MultipartFileOrUrl.java index 7fdfbce87..ff48490bf 100644 --- a/backend/src/main/java/io/papermc/hangar/model/internal/versions/MultipartFileOrUrl.java +++ b/backend/src/main/java/io/papermc/hangar/model/internal/versions/MultipartFileOrUrl.java @@ -2,23 +2,27 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import io.papermc.hangar.controller.validations.Validate; +import io.papermc.hangar.exceptions.HangarApiException; import io.papermc.hangar.model.common.Platform; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.Size; import java.util.List; import org.jetbrains.annotations.Nullable; // @el(root: String) // can't figure out how to apply this to just the one record component @Schema(description = "List of different jars/external links that are part of the version") public record MultipartFileOrUrl( - @Size(min = 1, max = 3, message = "version.new.error.invalidNumOfPlatforms") - @Schema(description = "List of platforms this jar runs on", example = "[PAPER, WATERFALL, VELOCITY]") - List platforms, + @Schema(description = "List of platforms this jar runs on", example = "[PAPER, WATERFALL, VELOCITY]") List platforms, @Nullable @Validate(SpEL = "@validate.regex(#root, @hangarConfig.urlRegex)", message = "validation.invalidUrl") @Schema(description = "External url to download the jar from if not provided via an attached jar, else null", example = "https://papermc.io/downloads") String externalUrl ) { + public MultipartFileOrUrl { + if (platforms == null || platforms.isEmpty() || platforms.size() > 3) { + throw new HangarApiException("version.new.error.invalidNumOfPlatforms"); + } + } + @JsonIgnore public boolean isUrl() { return this.externalUrl != null && !this.externalUrl.isEmpty(); diff --git a/backend/src/main/java/io/papermc/hangar/model/internal/versions/VersionUpload.java b/backend/src/main/java/io/papermc/hangar/model/internal/versions/VersionUpload.java index 478a7da6d..f47a85e2e 100644 --- a/backend/src/main/java/io/papermc/hangar/model/internal/versions/VersionUpload.java +++ b/backend/src/main/java/io/papermc/hangar/model/internal/versions/VersionUpload.java @@ -28,7 +28,6 @@ public class VersionUpload { // @el(root: String) private final @Validate(SpEL = "@validate.max(#root, @hangarConfig.pages.maxLen)", message = "page.new.error.maxLength") String description; @Size(min = 1, max = 3, message = "version.new.error.invalidNumOfPlatforms") - @NotEmpty(message = "version.new.error.invalidNumOfPlatforms") private final List<@Valid MultipartFileOrUrl> files; // @el(root: String)