Skip to content

Commit 50743f2

Browse files
committed
update restdocs, move to spring-5
1 parent e709a1a commit 50743f2

13 files changed

Lines changed: 134 additions & 709 deletions

File tree

‎pom.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@
201201
<module>spring-protobuf</module>
202202
<module>spring-quartz</module>
203203
<module>spring-rest-angular</module>
204-
<module>spring-rest-docs</module>
205204
<module>spring-rest-full</module>
206205
<module>spring-rest-query-language</module>
207206
<module>spring-rest</module>

‎spring-5/pom.xml‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
<groupId>org.springframework.boot</groupId>
4040
<artifactId>spring-boot-starter-webflux</artifactId>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-hateoas</artifactId>
45+
</dependency>
4246
<dependency>
4347
<groupId>org.projectreactor</groupId>
4448
<artifactId>reactor-spring</artifactId>
@@ -135,6 +139,22 @@
135139
<version>${junit.platform.version}</version>
136140
<scope>test</scope>
137141
</dependency>
142+
<dependency>
143+
<groupId>org.springframework.restdocs</groupId>
144+
<artifactId>spring-restdocs-mockmvc</artifactId>
145+
<scope>test</scope>
146+
</dependency>
147+
<dependency>
148+
<groupId>org.springframework.restdocs</groupId>
149+
<artifactId>spring-restdocs-webtestclient</artifactId>
150+
<scope>test</scope>
151+
</dependency>
152+
<dependency>
153+
<groupId>org.springframework.restdocs</groupId>
154+
<artifactId>spring-restdocs-restassured</artifactId>
155+
<scope>test</scope>
156+
</dependency>
157+
138158

139159
</dependencies>
140160

@@ -163,6 +183,29 @@
163183
</excludes>
164184
</configuration>
165185
</plugin>
186+
<plugin>
187+
<groupId>org.asciidoctor</groupId>
188+
<artifactId>asciidoctor-maven-plugin</artifactId>
189+
<version>${asciidoctor-plugin.version}</version>
190+
<executions>
191+
<execution>
192+
<id>generate-docs</id>
193+
<phase>package</phase>
194+
<goals>
195+
<goal>process-asciidoc</goal>
196+
</goals>
197+
<configuration>
198+
<backend>html</backend>
199+
<doctype>book</doctype>
200+
<attributes>
201+
<snippets>${snippetsDirectory}</snippets>
202+
</attributes>
203+
<sourceDirectory>src/docs/asciidocs</sourceDirectory>
204+
<outputDirectory>target/generated-docs</outputDirectory>
205+
</configuration>
206+
</execution>
207+
</executions>
208+
</plugin>
166209
</plugins>
167210
</build>
168211

@@ -199,6 +242,8 @@
199242
<johnzon.version>1.1.3</johnzon.version>
200243
<jsonb-api.version>1.0</jsonb-api.version>
201244
<geronimo-json_1.1_spec.version>1.0</geronimo-json_1.1_spec.version>
245+
<asciidoctor-plugin.version>1.5.6</asciidoctor-plugin.version>
246+
<snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
202247
</properties>
203248

204249
</project>

spring-rest-docs/src/main/java/com/example/CRUDController.java renamed to spring-5/src/main/java/com/baeldung/restdocs/CRUDController.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example;
1+
package com.baeldung.restdocs;
22

33
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
44

@@ -7,49 +7,53 @@
77

88
import org.springframework.http.HttpHeaders;
99
import org.springframework.http.HttpStatus;
10+
import org.springframework.web.bind.annotation.DeleteMapping;
11+
import org.springframework.web.bind.annotation.GetMapping;
12+
import org.springframework.web.bind.annotation.PatchMapping;
1013
import org.springframework.web.bind.annotation.PathVariable;
14+
import org.springframework.web.bind.annotation.PostMapping;
15+
import org.springframework.web.bind.annotation.PutMapping;
1116
import org.springframework.web.bind.annotation.RequestBody;
1217
import org.springframework.web.bind.annotation.RequestMapping;
13-
import org.springframework.web.bind.annotation.RequestMethod;
1418
import org.springframework.web.bind.annotation.ResponseStatus;
1519
import org.springframework.web.bind.annotation.RestController;
1620

1721
@RestController
1822
@RequestMapping("/crud")
1923
public class CRUDController {
2024

21-
@RequestMapping(method = RequestMethod.GET)
22-
@ResponseStatus(HttpStatus.OK)
25+
@GetMapping
2326
public List<CrudInput> read(@RequestBody CrudInput crudInput) {
2427
List<CrudInput> returnList = new ArrayList<CrudInput>();
2528
returnList.add(crudInput);
2629
return returnList;
2730
}
2831

2932
@ResponseStatus(HttpStatus.CREATED)
30-
@RequestMapping(method = RequestMethod.POST)
33+
@PostMapping
3134
public HttpHeaders save(@RequestBody CrudInput crudInput) {
3235
HttpHeaders httpHeaders = new HttpHeaders();
33-
httpHeaders.setLocation(linkTo(CRUDController.class).slash(crudInput.getTitle()).toUri());
36+
httpHeaders.setLocation(linkTo(CRUDController.class).slash(crudInput.getId()).toUri());
3437
return httpHeaders;
3538
}
3639

37-
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
40+
@DeleteMapping(value = "/{id}")
3841
@ResponseStatus(HttpStatus.OK)
39-
HttpHeaders delete(@RequestBody CrudInput crudInput) {
40-
HttpHeaders httpHeaders = new HttpHeaders();
41-
return httpHeaders;
42+
HttpHeaders delete(@PathVariable("id") long id) {
43+
return new HttpHeaders();
4244
}
4345

44-
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
46+
@PutMapping(value = "/{id}")
4547
@ResponseStatus(HttpStatus.ACCEPTED)
4648
void put(@PathVariable("id") long id, @RequestBody CrudInput crudInput) {
4749

4850
}
4951

50-
@RequestMapping(value = "/{id}", method = RequestMethod.PATCH)
51-
@ResponseStatus(HttpStatus.NO_CONTENT)
52-
void patch(@PathVariable("id") long id, @RequestBody CrudInput crudInput) {
53-
52+
@PatchMapping(value = "/{id}")
53+
public List<CrudInput> patch(@PathVariable("id") long id, @RequestBody CrudInput crudInput) {
54+
List<CrudInput> returnList = new ArrayList<CrudInput>();
55+
crudInput.setId(id);
56+
returnList.add(crudInput);
57+
return returnList;
5458
}
5559
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.baeldung.restdocs;
2+
3+
import java.net.URI;
4+
import java.util.Collections;
5+
import java.util.List;
6+
7+
import javax.validation.constraints.NotBlank;
8+
import javax.validation.constraints.NotNull;
9+
10+
import com.fasterxml.jackson.annotation.JsonCreator;
11+
import com.fasterxml.jackson.annotation.JsonProperty;
12+
13+
public class CrudInput {
14+
15+
@NotNull
16+
private long id;
17+
18+
@NotBlank
19+
private String title;
20+
21+
private String body;
22+
23+
private List<URI> tagUris;
24+
25+
@JsonCreator
26+
public CrudInput(@JsonProperty("id") long id, @JsonProperty("title") String title, @JsonProperty("body") String body, @JsonProperty("tags") List<URI> tagUris) {
27+
this.id=id;
28+
this.title = title;
29+
this.body = body;
30+
this.tagUris = tagUris == null ? Collections.<URI> emptyList() : tagUris;
31+
}
32+
33+
public String getTitle() {
34+
return title;
35+
}
36+
37+
public String getBody() {
38+
return body;
39+
}
40+
41+
public long getId() {
42+
return id;
43+
}
44+
45+
public void setId(long id) {
46+
this.id = id;
47+
}
48+
49+
public void setTitle(String title) {
50+
this.title = title;
51+
}
52+
53+
public void setBody(String body) {
54+
this.body = body;
55+
}
56+
57+
public void setTagUris(List<URI> tagUris) {
58+
this.tagUris = tagUris;
59+
}
60+
61+
@JsonProperty("tags")
62+
public List<URI> getTagUris() {
63+
return this.tagUris;
64+
}
65+
66+
}

spring-rest-docs/src/main/java/com/example/IndexController.java renamed to spring-5/src/main/java/com/baeldung/restdocs/IndexController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
package com.example;
1+
package com.baeldung.restdocs;
22

33
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
44

55
import org.springframework.hateoas.ResourceSupport;
6+
import org.springframework.web.bind.annotation.GetMapping;
67
import org.springframework.web.bind.annotation.RequestMapping;
7-
import org.springframework.web.bind.annotation.RequestMethod;
88
import org.springframework.web.bind.annotation.RestController;
99

1010
@RestController
1111
@RequestMapping("/")
1212
public class IndexController {
1313

14-
@RequestMapping(method = RequestMethod.GET)
14+
@GetMapping
1515
public ResourceSupport index() {
1616
ResourceSupport index = new ResourceSupport();
1717
index.add(linkTo(CRUDController.class).withRel("crud"));

spring-rest-docs/src/main/java/com/example/SpringRestDocsApplication.java renamed to spring-5/src/main/java/com/baeldung/restdocs/SpringRestDocsApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example;
1+
package com.baeldung.restdocs;
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;

‎spring-rest-docs/README.MD‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎spring-rest-docs/pom.xml‎

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)