Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit f938390

Browse files
author
Corneil du Plessis
authored
Fix rest documentation for changes to spring-rest-docs in skipper (#6024)
Added query-parameters and path-parameters where applicable. Added snippet template to query-parameters and updated template for path-parameters to improve readability. Fixes #6008
1 parent 935ce3f commit f938390

File tree

16 files changed

+176
-31
lines changed

16 files changed

+176
-31
lines changed

spring-cloud-skipper/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<spring-cloud-deployer.version>3.0.0-SNAPSHOT</spring-cloud-deployer.version>
2929

3030
<zeroturnaround.version>1.17</zeroturnaround.version>
31-
<spring-restdocs.version>3.0.1</spring-restdocs.version>
3231
<java-semver.version>0.10.2</java-semver.version>
3332

3433
<equalverifier.version>3.15.8</equalverifier.version>
@@ -181,16 +180,6 @@
181180
<artifactId>java-semver</artifactId>
182181
<version>${java-semver.version}</version>
183182
</dependency>
184-
<dependency>
185-
<groupId>org.springframework.restdocs</groupId>
186-
<artifactId>spring-restdocs-mockmvc</artifactId>
187-
<version>${spring-restdocs.version}</version>
188-
</dependency>
189-
<dependency>
190-
<groupId>org.springframework.restdocs</groupId>
191-
<artifactId>spring-restdocs-core</artifactId>
192-
<version>${spring-restdocs.version}</version>
193-
</dependency>
194183
<dependency>
195184
<groupId>nl.jqno.equalsverifier</groupId>
196185
<artifactId>equalsverifier</artifactId>

spring-cloud-skipper/spring-cloud-skipper-docs/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
<artifactId>spring-boot-starter-test</artifactId>
4646
<scope>test</scope>
4747
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.restdocs</groupId>
50+
<artifactId>spring-restdocs-mockmvc</artifactId>
51+
<scope>test</scope>
52+
</dependency>
4853
<dependency>
4954
<groupId>org.springframework.restdocs</groupId>
5055
<artifactId>spring-restdocs-core</artifactId>

spring-cloud-skipper/spring-cloud-skipper-docs/src/main/asciidoc/api-guide.adoc

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ A `GET` request returns a paginated list for all the Spring Cloud Skipper platfo
158158

159159
include::{snippets}/deployers-documentation/get-all-deployers/http-request.adoc[]
160160

161+
===== Request parameters
162+
163+
include::{snippets}/deployers-documentation/get-all-deployers/query-parameters.adoc[]
164+
161165
===== Example request
162166

163167
include::{snippets}/deployers-documentation/get-all-deployers/curl-request.adoc[]
@@ -184,6 +188,10 @@ A `GET` request will return a paginated list for all Spring Cloud Skipper packag
184188

185189
include::{snippets}/package-metadata-documentation/get-all-package-metadata/http-request.adoc[]
186190

191+
===== Path parameters
192+
193+
include::{snippets}/package-metadata-documentation/get-all-package-metadata/query-parameters.adoc[]
194+
187195
===== Example request
188196

189197
include::{snippets}/package-metadata-documentation/get-all-package-metadata/curl-request.adoc[]
@@ -227,6 +235,11 @@ A `GET` request returns the details of a package using the `id` of the package.
227235

228236
include::{snippets}/package-metadata-documentation/get-package-metadata-details/http-request.adoc[]
229237

238+
===== Path parameters
239+
240+
include::{snippets}/package-metadata-documentation/get-package-metadata-details/path-parameters.adoc[]
241+
242+
230243
===== Example request
231244

232245
include::{snippets}/package-metadata-documentation/get-package-metadata-details/curl-request.adoc[]
@@ -248,6 +261,10 @@ A `GET` request returns a list of all the Spring Cloud Skipper package metadata
248261
getPackageMetadataSearchFindByName
249262
include::{snippets}/package-metadata-documentation/get-package-metadata-search-find-by-name/http-request.adoc[]
250263

264+
===== Request parameters
265+
266+
include::{snippets}/package-metadata-documentation/get-package-metadata-search-find-by-name/query-parameters.adoc[]
267+
251268
===== Example request
252269

253270
include::{snippets}/package-metadata-documentation/get-package-metadata-search-find-by-name/curl-request.adoc[]
@@ -267,7 +284,11 @@ A `GET` request returns a list for all Spring Cloud Skipper package metadata by
267284

268285
===== Request structure
269286

270-
include::{snippets}/package-metadata-documentation/get-package-metadata-search-find-by-name-containing-ignore-case//http-request.adoc[]
287+
include::{snippets}/package-metadata-documentation/get-package-metadata-search-find-by-name-containing-ignore-case/http-request.adoc[]
288+
289+
===== Request parameters
290+
291+
include::{snippets}/package-metadata-documentation/get-package-metadata-search-find-by-name-containing-ignore-case/query-parameters.adoc[]
271292

272293
===== Example request
273294

@@ -338,6 +359,10 @@ The `install` link can install a package identified by its ID into the target pl
338359

339360
include::{snippets}/install-documentation/install-package-with-id/http-request.adoc[]
340361

362+
===== Path parameters
363+
364+
include::{snippets}/install-documentation/install-package-with-id/path-parameters.adoc[]
365+
341366
===== Example request
342367

343368
include::{snippets}/install-documentation/install-package-with-id/curl-request.adoc[]
@@ -458,6 +483,10 @@ given release name.
458483

459484
include::{snippets}/list-documentation/list-releases-by-release-name/http-request.adoc[]
460485

486+
====== Path parameters
487+
488+
include::{snippets}/list-documentation/list-releases-by-release-name/path-parameters.adoc[]
489+
461490
====== Example request
462491

463492
include::{snippets}/list-documentation/list-releases-by-release-name/curl-request.adoc[]
@@ -481,6 +510,10 @@ The `status` REST endpoint provides the status for the last known release versio
481510

482511
include::{snippets}/status-documentation/get-status-of-release/http-request.adoc[]
483512

513+
====== Path parameters
514+
515+
include::{snippets}/status-documentation/get-status-of-release/path-parameters.adoc[]
516+
484517
====== Example request
485518

486519
include::{snippets}/status-documentation/get-status-of-release/curl-request.adoc[]
@@ -501,6 +534,10 @@ The `status` REST endpoint can provide the status for a specific release version
501534

502535
include::{snippets}/status-documentation/get-status-of-release-for-version/http-request.adoc[]
503536

537+
====== Path parameters
538+
539+
include::{snippets}/status-documentation/get-status-of-release-for-version/path-parameters.adoc[]
540+
504541
====== Example request
505542

506543
include::{snippets}/status-documentation/get-status-of-release-for-version/curl-request.adoc[]
@@ -554,6 +591,10 @@ This part of the api is deprecated, please use
554591

555592
include::{snippets}/rollback-documentation/rollback-release/http-request.adoc[]
556593

594+
====== Path parameters
595+
596+
include::{snippets}/rollback-documentation/rollback-release/path-parameters.adoc[]
597+
557598
====== Example request
558599

559600
include::{snippets}/rollback-documentation/rollback-release/curl-request.adoc[]
@@ -598,6 +639,10 @@ The `manifest` REST endpoint returns the manifest for the last known release ver
598639

599640
include::{snippets}/manifest-documentation/get-manifest-of-release/http-request.adoc[]
600641

642+
====== Path parameters
643+
644+
include::{snippets}/manifest-documentation/get-manifest-of-release/path-parameters.adoc[]
645+
601646
====== Example request
602647

603648
include::{snippets}/manifest-documentation/get-manifest-of-release/curl-request.adoc[]
@@ -614,6 +659,10 @@ The `manifest` REST endpoint can return the manifest for a specific release vers
614659

615660
include::{snippets}/manifest-documentation/get-manifest-of-release-for-version/http-request.adoc[]
616661

662+
====== Path parameters
663+
664+
include::{snippets}/manifest-documentation/get-manifest-of-release-for-version/path-parameters.adoc[]
665+
617666
====== Example request
618667

619668
include::{snippets}/manifest-documentation/get-manifest-of-release-for-version/curl-request.adoc[]
@@ -635,6 +684,10 @@ The delete operation does not uninstall the uploaded packages corresponding to t
635684

636685
include::{snippets}/delete-documentation/delete-release-default/http-request.adoc[]
637686

687+
====== Path Parameters
688+
689+
include::{snippets}/delete-documentation/delete-release-default/path-parameters.adoc[]
690+
638691
====== Example request
639692

640693
include::{snippets}/delete-documentation/delete-release-default/curl-request.adoc[]
@@ -655,6 +708,10 @@ You can use a DELETE request to delete an existing release and uninstall the pac
655708

656709
include::{snippets}/delete-documentation/delete-release/http-request.adoc[]
657710

711+
====== Path Parameters
712+
713+
include::{snippets}/delete-documentation/delete-release-default/path-parameters.adoc[]
714+
658715
====== Example request
659716

660717
include::{snippets}/delete-documentation/delete-release/curl-request.adoc[]

spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/docs/BaseDocumentation.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.HashMap;
2222
import java.util.List;
2323
import java.util.Map;
24+
import java.util.concurrent.Callable;
2425

2526
import com.fasterxml.jackson.annotation.JsonInclude;
2627
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -66,6 +67,8 @@
6667
import org.springframework.restdocs.request.QueryParametersSnippet;
6768
import org.springframework.test.context.ActiveProfiles;
6869
import org.springframework.test.web.servlet.MockMvc;
70+
import org.springframework.test.web.servlet.MvcResult;
71+
import org.springframework.test.web.servlet.ResultHandler;
6972
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
7073
import org.springframework.web.context.WebApplicationContext;
7174
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -110,6 +113,7 @@ public abstract class BaseDocumentation {
110113
@Autowired
111114
public WebApplicationContext context;
112115

116+
protected RestDocs documentation;
113117

114118
@Autowired
115119
protected RepositoryRepository repositoryRepository;
@@ -186,13 +190,13 @@ private void prepareDocumentationTests(WebApplicationContext context) {
186190
this.documentationHandler = document("{class-name}/{method-name}",
187191
preprocessRequest(prettyPrint()),
188192
preprocessResponse(prettyPrint()));
189-
193+
this.documentation = new ToggleableResultHandler(documentationHandler);
190194
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
191195
.apply(this.restDocumentationConfigurer.uris()
192196
.withScheme("http")
193197
.withHost("localhost")
194198
.withPort(7577))
195-
.alwaysDo(this.documentationHandler)
199+
.alwaysDo((ToggleableResultHandler) this.documentation)
196200
.build();
197201
}
198202

@@ -269,5 +273,38 @@ protected static String convertObjectToJson(Object object) throws IOException {
269273
String json = mapper.writeValueAsString(object);
270274
return json;
271275
}
276+
@FunctionalInterface
277+
public interface RestDocs {
278+
void dontDocument(Callable action) throws Exception;
279+
}
280+
private static class ToggleableResultHandler implements ResultHandler, RestDocs {
281+
private final ResultHandler delegate;
282+
283+
private boolean off = false;
284+
285+
private ToggleableResultHandler(ResultHandler delegate) {
286+
this.delegate = delegate;
287+
}
288+
289+
@Override
290+
public void handle(MvcResult result) throws Exception {
291+
if (!off) {
292+
delegate.handle(result);
293+
}
294+
}
295+
296+
/**
297+
* Perform the given action while turning off the delegate handler.
298+
*/
299+
@Override
300+
public void dontDocument(Callable action) throws Exception {
301+
off = true;
302+
try {
303+
action.call();
304+
} finally {
305+
off = false;
306+
}
307+
}
308+
}
272309

273310
}

spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/docs/DeleteDocumentation.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
3333
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
3434
import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath;
35+
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
36+
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
3537
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
36-
3738
/**
3839
* @author Gunnar Hillert
3940
* @author Ilayaperumal Gopinathan
@@ -44,12 +45,16 @@ class DeleteDocumentation extends BaseDocumentation {
4445
@Test
4546
void deleteRelease() throws Exception {
4647
Release release = createTestRelease("test", StatusCode.DELETED);
48+
4749
when(this.skipperStateMachineService.deleteRelease(any(String.class), any(DeleteProperties.class))).thenReturn(release);
4850
this.mockMvc.perform(
4951
delete("/api/release/{releaseName}/package", release.getName())
5052
.accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON))
5153
.andExpect(status().isOk())
5254
.andDo(this.documentationHandler.document(
55+
pathParameters(
56+
parameterWithName("releaseName").description("The name of the release to be deleted")
57+
),
5358
responseFields(
5459
subsectionWithPath("links").ignored(),
5560
fieldWithPath("name").description("Name of the release"),
@@ -117,6 +122,7 @@ void deleteReleaseDefault() throws Exception {
117122
.accept(MediaType.APPLICATION_JSON).contentType(contentType))
118123
.andExpect(status().isOk())
119124
.andDo(this.documentationHandler.document(
125+
pathParameters(parameterWithName("releaseName").description("Name of the release to be deleted")),
120126
responseFields(
121127
subsectionWithPath("links").ignored(),
122128
fieldWithPath("name").description("Name of the release"),

spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/docs/HistoryDocumentation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
2727
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
2828
import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath;
29+
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
30+
import static org.springframework.restdocs.request.RequestDocumentation.queryParameters;
2931
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
30-
3132
/**
3233
* @author Gunnar Hillert
3334
* @author Ilayaperumal Gopinathan
@@ -43,6 +44,7 @@ void showVersionHistoryForRelease() throws Exception {
4344
this.mockMvc.perform(
4445
get("/api/releases/search/findByNameIgnoreCaseContainingOrderByNameAscVersionDesc?name={name}", "test")).andExpect(status().isOk())
4546
.andDo(this.documentationHandler.document(
47+
queryParameters(parameterWithName("name").description("Name of release")),
4648
responseFields(
4749
subsectionWithPath("_links").ignored(),
4850
subsectionWithPath("_embedded.releases[]._links").ignored(),

spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/docs/InstallDocumentation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
3434
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
3535
import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath;
36+
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
37+
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
3638
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
37-
3839
/**
3940
* @author Gunnar Hillert
4041
* @author Ilayaperumal Gopinathan
@@ -143,6 +144,7 @@ void installPackageWithId() throws Exception {
143144
.contentType(contentType)
144145
.content(convertObjectToJson(installProperties2))).andExpect(status().isCreated())
145146
.andDo(this.documentationHandler.document(
147+
pathParameters(parameterWithName("packageMetaDataId").description("Id of package to install")),
146148
responseFields(
147149
subsectionWithPath("links").ignored(),
148150
fieldWithPath("name").description("Name of the release"),

spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/docs/ListDocumentation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
3131
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
3232
import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath;
33+
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
34+
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
3335
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
34-
3536
/**
3637
* @author Gunnar Hillert
3738
* @author Ilayaperumal Gopinathan
@@ -115,6 +116,7 @@ void listReleasesByReleaseName() throws Exception {
115116
this.mockMvc.perform(
116117
get("/api/release/list/{releaseName}", release.getName())).andExpect(status().isOk())
117118
.andDo(this.documentationHandler.document(
119+
pathParameters(parameterWithName("releaseName").description("Name of the releases to list")),
118120
responseFields(
119121
subsectionWithPath("_embedded.releases[]._links").ignored(),
120122
fieldWithPath("_embedded.releases[].name").description("Name of the release"),

spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/docs/LogsDocumentation.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
import static org.mockito.Mockito.when;
2929
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
3030
import static org.springframework.restdocs.payload.PayloadDocumentation.responseBody;
31+
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
32+
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
3133
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
32-
3334
/**
3435
* @author Ilayaperumal Gopinathan
3536
* @author Corneil du Plessis
@@ -48,6 +49,7 @@ void getLogsofRelease() throws Exception {
4849
.contentType(contentType))
4950
.andExpect(status().isOk())
5051
.andDo(this.documentationHandler.document(
52+
pathParameters(parameterWithName("releaseName").description("The name of the release to show logs")),
5153
responseBody()));
5254
}
5355

@@ -61,6 +63,10 @@ void getLogsofReleaseByAppName() throws Exception {
6163
release.getName(), "myapp"))
6264
.andExpect(status().isOk())
6365
.andDo(this.documentationHandler.document(
66+
pathParameters(
67+
parameterWithName("releaseName").description("The name of the release to show logs"),
68+
parameterWithName("appName").description("The name of the app to show logs")
69+
),
6470
responseBody()));
6571
}
6672
}

0 commit comments

Comments
 (0)