Skip to content

Commit 653d6d7

Browse files
committed
Support Antora versions for project documentation links
Closes gh-19
1 parent 2a0879f commit 653d6d7

File tree

9 files changed

+66
-13
lines changed

9 files changed

+66
-13
lines changed

src/main/java/io/spring/projectapi/contentful/ProjectDocumentation.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class ProjectDocumentation implements Comparable<ProjectDocumentation> {
3030

3131
private final String version;
3232

33+
private final boolean antora;
34+
3335
private final String api;
3436

3537
private final String ref;
@@ -39,8 +41,10 @@ public class ProjectDocumentation implements Comparable<ProjectDocumentation> {
3941
private final boolean current;
4042

4143
@JsonCreator(mode = Mode.PROPERTIES)
42-
public ProjectDocumentation(String version, String api, String ref, Status status, boolean current) {
44+
public ProjectDocumentation(String version, boolean antora, String api, String ref, Status status,
45+
boolean current) {
4346
this.version = version;
47+
this.antora = antora;
4448
this.api = api;
4549
this.ref = ref;
4650
this.status = status;
@@ -76,6 +80,10 @@ public int compareTo(ProjectDocumentation other) {
7680
return -this.version.compareTo(other.version);
7781
}
7882

83+
public boolean isAntora() {
84+
return this.antora;
85+
}
86+
7987
/**
8088
* Project documentation status.
8189
*/

src/main/java/io/spring/projectapi/web/release/NewRelease.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ public class NewRelease {
3636
@URL
3737
private final String apiDocUrl;
3838

39+
private final boolean isAntora;
40+
3941
@JsonCreator
40-
public NewRelease(String version, String referenceDocUrl, String apiDocUrl) {
42+
public NewRelease(String version, String referenceDocUrl, String apiDocUrl, boolean isAntora) {
4143
this.version = version;
4244
this.referenceDocUrl = referenceDocUrl;
4345
this.apiDocUrl = apiDocUrl;
46+
this.isAntora = isAntora;
4447
}
4548

4649
public String getVersion() {
@@ -55,4 +58,8 @@ public String getApiDocUrl() {
5558
return this.apiDocUrl;
5659
}
5760

61+
public boolean isAntora() {
62+
return this.isAntora;
63+
}
64+
5865
}

src/main/java/io/spring/projectapi/web/release/ReleasesController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public ResponseEntity<String> add(@PathVariable String id, @RequestBody NewRelea
110110
return ResponseEntity.badRequest().body(message);
111111
}
112112
Release.Status status = Release.Status.fromVersion(version);
113-
ProjectDocumentation projectDocumentation = new ProjectDocumentation(release.getVersion(),
113+
ProjectDocumentation projectDocumentation = new ProjectDocumentation(release.getVersion(), release.isAntora(),
114114
release.getApiDocUrl(), release.getReferenceDocUrl(),
115115
ProjectDocumentation.Status.valueOf(status.name()), false);
116116
this.contentfulService.addProjectDocumentation(id, projectDocumentation);

src/test/java/io/spring/projectapi/contentful/ContentfulOperationsTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void addProjectDocumentation() {
8080
assertThat(updatedEntry.size()).isEqualTo(2);
8181
assertThat(updatedEntry).extracting((map) -> map.get("version")).containsExactly("1.0", "2.0");
8282
assertThat(updatedEntry).extracting((map) -> map.get("current")).containsExactly(false, true);
83+
assertThat(updatedEntry).extracting((map) -> map.get("antora")).containsExactly(false, true);
8384
}
8485

8586
@Test
@@ -287,7 +288,7 @@ private Consumer<List<Map<String, Object>>> addRelease() {
287288

288289
private static Map<String, Object> getRelease(boolean current) {
289290
return Map.of("version", "1.0", "api", "http://api.com", "ref", "http://ref.com", "status",
290-
"GENERAL_AVAILABILITY", "repository", "RELEASE", "current", current);
291+
"GENERAL_AVAILABILITY", "repository", "RELEASE", "current", current, "antora", false);
291292
}
292293

293294
@SuppressWarnings("unchecked")
@@ -300,7 +301,7 @@ private void setupNonExistentProject() {
300301
}
301302

302303
private ProjectDocumentation getDocumentation(String version, Status status) {
303-
return new ProjectDocumentation(version, "http://api.com", "http://ref.com", status, false);
304+
return new ProjectDocumentation(version, true, "http://api.com", "http://ref.com", status, false);
304305
}
305306

306307
}

src/test/java/io/spring/projectapi/contentful/ContentfulServiceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class ContentfulServiceTests {
4343

4444
private static final Project PROJECT = new Project("Test Project", "test-project", "github", Status.ACTIVE);
4545

46-
private static final ProjectDocumentation PROJECT_DOCUMENTATION = new ProjectDocumentation("2.0", "http://api.com",
47-
"http://ref.com", ProjectDocumentation.Status.GENERAL_AVAILABILITY, false);
46+
private static final ProjectDocumentation PROJECT_DOCUMENTATION = new ProjectDocumentation("2.0", false,
47+
"http://api.com", "http://ref.com", ProjectDocumentation.Status.GENERAL_AVAILABILITY, false);
4848

4949
private static final ProjectSupport PROJECT_SUPPORT = new ProjectSupport("2.2.x", LocalDate.parse("2020-02-01"),
5050
LocalDate.parse("2020-02-02"), LocalDate.parse("2020-02-03"), LocalDate.parse("2020-02-04"),

src/test/java/io/spring/projectapi/contentful/ProjectDocumentationJsonTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ProjectDocumentationJsonTests {
4848

4949
@Test
5050
void convertValueToMapReturnsMap() {
51-
ProjectDocumentation documentation = new ProjectDocumentation("ver", "api", "ref",
51+
ProjectDocumentation documentation = new ProjectDocumentation("ver", false, "api", "ref",
5252
ProjectDocumentation.Status.PRERELEASE, true);
5353
Map<?, ?> converted = this.objectMapper.convertValue(documentation, Map.class);
5454
Map<String, Object> expected = new HashMap<>();
@@ -57,6 +57,7 @@ void convertValueToMapReturnsMap() {
5757
expected.put("ref", documentation.getRef());
5858
expected.put("status", documentation.getStatus().name());
5959
expected.put("current", documentation.isCurrent());
60+
expected.put("antora", documentation.isAntora());
6061
assertThat(converted).isEqualTo(expected);
6162
}
6263

@@ -69,6 +70,7 @@ void readObjectReadsJson() throws Exception {
6970
.isEqualTo("https://docs.spring.io/spring-boot/docs/{version}/reference/html/");
7071
assertThat(projectDocumentation.getStatus()).isEqualTo(Status.SNAPSHOT);
7172
assertThat(projectDocumentation.isCurrent()).isEqualTo(true);
73+
assertThat(projectDocumentation.isAntora()).isEqualTo(false);
7274
}
7375

7476
}

src/test/java/io/spring/projectapi/web/release/LegacyReleasesControllerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ private List<ProjectDocumentation> getProjectDocumentations() {
7373
List<ProjectDocumentation> result = new ArrayList<>();
7474
String docsRoot;
7575
docsRoot = "https://docs.spring.io/spring-boot/docs/2.3.0/";
76-
result.add(new ProjectDocumentation("2.3.0", docsRoot + "api/", docsRoot + "reference/html/",
76+
result.add(new ProjectDocumentation("2.3.0", false, docsRoot + "api/", docsRoot + "reference/html/",
7777
Status.GENERAL_AVAILABILITY, true));
7878
docsRoot = "https://docs.spring.io/spring-boot/docs/2.3.1-SNAPSHOT/";
79-
result.add(new ProjectDocumentation("2.3.1-SNAPSHOT", docsRoot + "api/", docsRoot + "reference/html/",
79+
result.add(new ProjectDocumentation("2.3.1-SNAPSHOT", false, docsRoot + "api/", docsRoot + "reference/html/",
8080
Status.SNAPSHOT, false));
8181
return result;
8282
}

src/test/java/io/spring/projectapi/web/release/ReleasesControllerTests.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,37 @@ void addAddsRelease() throws Exception {
161161
.contentType(MediaType.APPLICATION_JSON)
162162
.content(from("add.json")))
163163
.andExpect(status().isCreated())
164+
.andExpect(header().string("Location", expectedLocation));
165+
ArgumentCaptor<ProjectDocumentation> captor = ArgumentCaptor.forClass(ProjectDocumentation.class);
166+
verify(this.contentfulService).addProjectDocumentation(eq("spring-boot"), captor.capture());
167+
ProjectDocumentation added = captor.getValue();
168+
assertThat(added.getVersion()).isEqualTo("2.8.0");
169+
assertThat(added.getApi()).isEqualTo("https://docs.spring.io/spring-boot/docs/{version}/api/");
170+
assertThat(added.getRef()).isEqualTo("https://docs.spring.io/spring-boot/docs/{version}/reference/html/");
171+
assertThat(added.getStatus()).isEqualTo(ProjectDocumentation.Status.GENERAL_AVAILABILITY);
172+
assertThat(added.isCurrent()).isFalse();
173+
assertThat(added.isAntora()).isFalse();
174+
}
175+
176+
@Test
177+
@WithMockUser(roles = "ADMIN")
178+
void addWithAntoraVersionAddsRelease() throws Exception {
179+
given(this.contentfulService.getProjectDocumentations("spring-boot")).willReturn(getProjectDocumentations());
180+
String expectedLocation = "https://api.spring.io/projects/spring-boot/releases/2.8.0";
181+
ConstrainedFields fields = ConstrainedFields.constraintsOn(NewRelease.class);
182+
this.mvc
183+
.perform(post("/projects/spring-boot/releases").accept(MediaTypes.HAL_JSON)
184+
.contentType(MediaType.APPLICATION_JSON)
185+
.content(from("add-with-antora.json")))
186+
.andExpect(status().isCreated())
164187
.andExpect(header().string("Location", expectedLocation))
165188
.andDo(document("create-release", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),
166-
requestFields(fields.withPath("version").description("The Release version"),
189+
requestFields(fields.withPath("version").description("The Release version"), fields
190+
.withPath("isAntora")
191+
.type(JsonFieldType.BOOLEAN)
192+
.optional()
193+
.description(
194+
"Indicates if the documentation for this release is on Antora. Defaults to false if not specified."),
167195
fields.withPath("referenceDocUrl")
168196
.description(
169197
"URL of the reference documentation, {version} template variable is supported"),
@@ -178,6 +206,7 @@ void addAddsRelease() throws Exception {
178206
assertThat(added.getRef()).isEqualTo("https://docs.spring.io/spring-boot/docs/{version}/reference/html/");
179207
assertThat(added.getStatus()).isEqualTo(ProjectDocumentation.Status.GENERAL_AVAILABILITY);
180208
assertThat(added.isCurrent()).isFalse();
209+
assertThat(added.isAntora()).isTrue();
181210
}
182211

183212
@Test
@@ -248,10 +277,10 @@ private List<ProjectDocumentation> getProjectDocumentations() {
248277
List<ProjectDocumentation> result = new ArrayList<>();
249278
String docsRoot;
250279
docsRoot = "https://docs.spring.io/spring-boot/docs/2.3.0/";
251-
result.add(new ProjectDocumentation("2.3.0", docsRoot + "api/", docsRoot + "reference/html/",
280+
result.add(new ProjectDocumentation("2.3.0", false, docsRoot + "api/", docsRoot + "reference/html/",
252281
Status.GENERAL_AVAILABILITY, true));
253282
docsRoot = "https://docs.spring.io/spring-boot/docs/2.3.1-SNAPSHOT/";
254-
result.add(new ProjectDocumentation("2.3.1-SNAPSHOT", docsRoot + "api/", docsRoot + "reference/html/",
283+
result.add(new ProjectDocumentation("2.3.1-SNAPSHOT", false, docsRoot + "api/", docsRoot + "reference/html/",
255284
Status.SNAPSHOT, false));
256285
return result;
257286
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": "2.8.0",
3+
"isAntora": true,
4+
"apiDocUrl": "https://docs.spring.io/spring-boot/docs/{version}/api/",
5+
"referenceDocUrl": "https://docs.spring.io/spring-boot/docs/{version}/reference/html/"
6+
}

0 commit comments

Comments
 (0)