Skip to content

Commit 917594f

Browse files
committed
feat(schema): Scaffold combinator records (oneOf/anyOf/allOf/not/const/enum)
1 parent 2f0bdea commit 917594f

8 files changed

Lines changed: 118 additions & 1 deletion

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.retailsvc.http.spec.schema;
2+
3+
import java.util.List;
4+
import java.util.Set;
5+
6+
public record AllOfSchema(List<Schema> parts) implements Schema {
7+
@Override
8+
public Set<TypeName> types() {
9+
return Set.of();
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.retailsvc.http.spec.schema;
2+
3+
import java.util.List;
4+
import java.util.Set;
5+
6+
public record AnyOfSchema(List<Schema> options) implements Schema {
7+
@Override
8+
public Set<TypeName> types() {
9+
return Set.of();
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.retailsvc.http.spec.schema;
2+
3+
import java.util.Set;
4+
5+
public record ConstSchema(Object value) implements Schema {
6+
@Override
7+
public Set<TypeName> types() {
8+
return Set.of();
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.retailsvc.http.spec.schema;
2+
3+
import java.util.List;
4+
import java.util.Set;
5+
6+
public record EnumSchema(List<Object> values) implements Schema {
7+
@Override
8+
public Set<TypeName> types() {
9+
return Set.of();
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.retailsvc.http.spec.schema;
2+
3+
import java.util.Set;
4+
5+
public record NotSchema(Schema schema) implements Schema {
6+
@Override
7+
public Set<TypeName> types() {
8+
return Set.of();
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.retailsvc.http.spec.schema;
2+
3+
import java.util.List;
4+
import java.util.Set;
5+
6+
public record OneOfSchema(List<Schema> options) implements Schema {
7+
@Override
8+
public Set<TypeName> types() {
9+
return Set.of();
10+
}
11+
}

src/main/java/com/retailsvc/http/spec/schema/Schema.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public sealed interface Schema
1010
ObjectSchema,
1111
ArraySchema,
1212
NullSchema,
13-
RefSchema {
13+
RefSchema,
14+
OneOfSchema,
15+
AnyOfSchema,
16+
AllOfSchema,
17+
NotSchema,
18+
ConstSchema,
19+
EnumSchema {
1420
Set<TypeName> types();
1521
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.retailsvc.http.spec.schema;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.List;
6+
import java.util.Set;
7+
import org.junit.jupiter.api.Test;
8+
9+
class CombinatorScaffoldTest {
10+
private final Schema s = new BooleanSchema(Set.of(TypeName.BOOLEAN));
11+
12+
@Test
13+
void oneOfHoldsOptions() {
14+
assertThat(new OneOfSchema(List.of(s)).options()).hasSize(1);
15+
}
16+
17+
@Test
18+
void anyOfHoldsOptions() {
19+
assertThat(new AnyOfSchema(List.of(s)).options()).hasSize(1);
20+
}
21+
22+
@Test
23+
void allOfHoldsParts() {
24+
assertThat(new AllOfSchema(List.of(s)).parts()).hasSize(1);
25+
}
26+
27+
@Test
28+
void notHoldsSchema() {
29+
assertThat(new NotSchema(s).schema()).isSameAs(s);
30+
}
31+
32+
@Test
33+
void constHoldsValue() {
34+
assertThat(new ConstSchema("x").value()).isEqualTo("x");
35+
}
36+
37+
@Test
38+
void enumHoldsValues() {
39+
assertThat(new EnumSchema(List.of(1, 2)).values()).hasSize(2);
40+
}
41+
42+
@Test
43+
void allCombinatorsTypesEmpty() {
44+
assertThat(new OneOfSchema(List.of(s)).types()).isEmpty();
45+
assertThat(new ConstSchema("x").types()).isEmpty();
46+
}
47+
}

0 commit comments

Comments
 (0)