Repository navigation
Expand file tree
/
Copy pathVersions.java
More file actions
60 lines (54 loc) · 2.11 KB
/
Copy pathVersions.java
File metadata and controls
60 lines (54 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.a2aproject.docs;
import io.quarkiverse.roq.data.runtime.annotations.DataMapping;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@DataMapping(value = "versions", type = DataMapping.Type.ARRAY_DIR)
public record Versions(List<Version> list) {
public Versions {
if (list == null) {
throw new IllegalArgumentException("Versions list cannot be null");
}
long defaultCount = list.stream().filter(Version::defaultVersion).count();
if (defaultCount != 1) {
throw new IllegalStateException(
"Exactly one version must have defaultVersion: true, found " + defaultCount);
}
Set<Integer> sortOrders = new HashSet<>();
for (Version v : list) {
if (!sortOrders.add(v.sortOrder())) {
throw new IllegalStateException(
"Duplicate sortOrder " + v.sortOrder() + " in version " + v.label());
}
}
}
public record Version(
String label,
String path,
int sortOrder,
boolean defaultVersion,
boolean devVersion,
List<MenuItem> menu) {
public record MenuItem(
String title,
String path,
String icon,
@org.jspecify.annotations.Nullable String target) {
public MenuItem {
if (title == null || title.isBlank()) {
throw new IllegalArgumentException("MenuItem title cannot be null or blank");
}
if (path == null || path.isBlank()) {
throw new IllegalArgumentException("MenuItem path cannot be null or blank");
}
if (!path.startsWith("/")) {
throw new IllegalStateException(
"MenuItem path must start with '/', got: " + path);
}
if (icon == null || icon.isBlank()) {
throw new IllegalArgumentException("MenuItem icon cannot be null or blank");
}
}
}
}
}