Skip to content

Commit f615adf

Browse files
committed
feat(spec): Add Parameter, RequestBody, MediaType, Response, Server, Info records
1 parent 55794da commit f615adf

7 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.retailsvc.http.spec;
2+
3+
public record Info(String title, String version) {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.retailsvc.http.spec;
2+
3+
import com.retailsvc.http.spec.schema.Schema;
4+
5+
public record MediaType(Schema schema) {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.retailsvc.http.spec;
2+
3+
import com.retailsvc.http.spec.schema.Schema;
4+
5+
public record Parameter(String name, Location in, boolean required, Schema schema) {
6+
public enum Location {
7+
PATH,
8+
QUERY,
9+
HEADER,
10+
COOKIE
11+
}
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.retailsvc.http.spec;
2+
3+
import java.util.Map;
4+
5+
public record RequestBody(boolean required, Map<String, MediaType> content) {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.retailsvc.http.spec;
2+
3+
import java.util.Map;
4+
5+
public record Response(Map<String, MediaType> content) {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.retailsvc.http.spec;
2+
3+
import java.net.URI;
4+
5+
public record Server(String url) {
6+
public String basePath() {
7+
return URI.create(url).getPath();
8+
}
9+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.retailsvc.http.spec;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import com.retailsvc.http.spec.schema.BooleanSchema;
6+
import com.retailsvc.http.spec.schema.Schema;
7+
import com.retailsvc.http.spec.schema.TypeName;
8+
import java.util.Map;
9+
import java.util.Set;
10+
import org.junit.jupiter.api.Test;
11+
12+
class SpecRecordsTest {
13+
private final Schema s = new BooleanSchema(Set.of(TypeName.BOOLEAN));
14+
15+
@Test
16+
void parameterLocationEnum() {
17+
Parameter p = new Parameter("x", Parameter.Location.QUERY, true, s);
18+
assertThat(p.in()).isEqualTo(Parameter.Location.QUERY);
19+
assertThat(p.required()).isTrue();
20+
}
21+
22+
@Test
23+
void requestBodyStoresContent() {
24+
RequestBody body = new RequestBody(true, Map.of("application/json", new MediaType(s)));
25+
assertThat(body.content()).containsKey("application/json");
26+
assertThat(body.required()).isTrue();
27+
}
28+
29+
@Test
30+
void serverHasUrl() {
31+
assertThat(new Server("http://localhost/api").url()).isEqualTo("http://localhost/api");
32+
}
33+
34+
@Test
35+
void infoHasTitleAndVersion() {
36+
Info i = new Info("test", "1.0.0");
37+
assertThat(i.title()).isEqualTo("test");
38+
assertThat(i.version()).isEqualTo("1.0.0");
39+
}
40+
}

0 commit comments

Comments
 (0)