Skip to content

Commit

Permalink
Work around Swagger validation issue
Browse files Browse the repository at this point in the history
Closes #1269
  • Loading branch information
kennytv committed Sep 6, 2023
1 parent 99b7b9c commit 5bc5249
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Platform> platforms,
@Schema(description = "List of platforms this jar runs on", example = "[PAPER, WATERFALL, VELOCITY]") List<Platform> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5bc5249

Please sign in to comment.