Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 14554fd

Browse files
authored
RestdocsNotExpanded in a separate module (#303)
Closes #282
1 parent bee7125 commit 14554fd

File tree

10 files changed

+68
-25
lines changed

10 files changed

+68
-25
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
<modules>
188188
<module>spring-auto-restdocs-json-doclet</module>
189189
<module>spring-auto-restdocs-dokka-json</module>
190+
<module>spring-auto-restdocs-annotations</module>
190191
<module>spring-auto-restdocs-core</module>
191192
<module>spring-auto-restdocs-docs</module>
192193
</modules>
@@ -204,6 +205,7 @@
204205
</properties>
205206
<modules>
206207
<module>spring-auto-restdocs-json-doclet-jdk9</module>
208+
<module>spring-auto-restdocs-annotations</module>
207209
<module>spring-auto-restdocs-core</module>
208210
<module>spring-auto-restdocs-docs</module>
209211
</modules>

samples/java-webmvc/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<groupId>capital.scalable</groupId>
8686
<artifactId>spring-auto-restdocs-core</artifactId>
8787
<version>${spring-auto-restdocs.version}</version>
88+
<scope>test</scope>
8889
</dependency>
8990
<dependency>
9091
<groupId>org.springframework.data</groupId>

samples/java-webmvc/src/main/java/capital/scalable/restdocs/example/items/ItemResource.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,7 +37,6 @@
3737
import capital.scalable.restdocs.example.constraints.English;
3838
import capital.scalable.restdocs.example.constraints.German;
3939
import capital.scalable.restdocs.example.constraints.Id;
40-
import org.apache.commons.lang3.BooleanUtils;
4140
import org.springframework.data.domain.Page;
4241
import org.springframework.data.domain.PageImpl;
4342
import org.springframework.data.domain.Pageable;
@@ -280,7 +279,7 @@ public HypermediaItemResponse getHypermediaItem(@PathVariable("id") @Id String i
280279
response.add(linkTo(methodOn(ItemResource.class).getHypermediaItem(id, embedded)).withSelfRel());
281280
response.add(linkTo(methodOn(ItemResource.class).getItem(id)).withRel("classicItem"));
282281
response.add(linkTo(methodOn(ItemResource.class).processSingleItem(id, null)).withRel("process"));
283-
if (BooleanUtils.isTrue(embedded)) {
282+
if (embedded != null && embedded) {
284283
response.embed("children", new Object[]{CHILD});
285284
response.embed("attributes", ATTRIBUTES);
286285
response.embed("meta", META);

samples/shared/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
<groupId>javax.validation</groupId>
4747
<artifactId>validation-api</artifactId>
4848
</dependency>
49+
<dependency>
50+
<groupId>capital.scalable</groupId>
51+
<artifactId>spring-auto-restdocs-annotations</artifactId>
52+
<version>${spring-auto-restdocs.version}</version>
53+
</dependency>
4954
</dependencies>
5055

5156
<profiles>

samples/shared/src/main/java/capital/scalable/restdocs/example/items/Metadata2.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@
2020

2121
package capital.scalable.restdocs.example.items;
2222

23+
import capital.scalable.restdocs.jackson.RestdocsNotExpanded;
24+
2325
public class Metadata2 extends Metadata {
2426
/**
2527
* Order attribute. Available only if metadata type=2
2628
*/
2729
private Integer order;
2830

31+
/**
32+
* Sub metadata (recursive). Not expanded as client should not see it.
33+
*/
34+
@RestdocsNotExpanded
35+
private Metadata2 sub;
36+
2937
Metadata2() {
3038
}
3139

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>capital.scalable</groupId>
9+
<artifactId>spring-auto-restdocs-parent</artifactId>
10+
<version>2.0.5-SNAPSHOT</version>
11+
<relativePath>..</relativePath>
12+
</parent>
13+
14+
<artifactId>spring-auto-restdocs-annotations</artifactId>
15+
<packaging>jar</packaging>
16+
17+
<name>Spring Auto REST Docs Annotations</name>
18+
<description>Spring Auto REST Docs supporting annotations</description>
19+
20+
</project>

spring-auto-restdocs-core/src/main/java/capital/scalable/restdocs/jackson/RestdocsNotExpanded.java renamed to spring-auto-restdocs-annotations/src/main/java/capital/scalable/restdocs/jackson/RestdocsNotExpanded.java

File renamed without changes.

spring-auto-restdocs-core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
</properties>
2323

2424
<dependencies>
25+
<dependency>
26+
<groupId>capital.scalable</groupId>
27+
<artifactId>spring-auto-restdocs-annotations</artifactId>
28+
<version>${project.version}</version>
29+
</dependency>
2530
<dependency>
2631
<groupId>org.springframework.restdocs</groupId>
2732
<artifactId>spring-restdocs-core</artifactId>

spring-auto-restdocs-docs/getting-started.adoc

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ For Java 9 support, use `spring-auto-restdocs-json-doclet-jdk9` as doclet depend
2929
<groupId>capital.scalable</groupId>
3030
<artifactId>spring-auto-restdocs-core</artifactId>
3131
<version>${latestRelease}</version>
32-
<scope>test</scope> <1>
32+
<scope>test</scope>
3333
</dependency>
3434
3535
<build>
@@ -42,10 +42,10 @@ For Java 9 support, use `spring-auto-restdocs-json-doclet-jdk9` as doclet depend
4242
</includes>
4343
<systemPropertyVariables>
4444
<org.springframework.restdocs.outputDir>
45-
\${project.build.directory}/generated-snippets <2>
45+
\${project.build.directory}/generated-snippets <1>
4646
</org.springframework.restdocs.outputDir>
4747
<org.springframework.restdocs.javadocJsonDir>
48-
\${project.build.directory}/generated-javadoc-json <3>
48+
\${project.build.directory}/generated-javadoc-json <2>
4949
</org.springframework.restdocs.javadocJsonDir>
5050
</systemPropertyVariables>
5151
</configuration>
@@ -64,11 +64,11 @@ For Java 9 support, use `spring-auto-restdocs-json-doclet-jdk9` as doclet depend
6464
<doclet>capital.scalable.restdocs.jsondoclet.ExtractDocumentationAsJsonDoclet</doclet>
6565
<docletArtifact>
6666
<groupId>capital.scalable</groupId>
67-
<artifactId>spring-auto-restdocs-json-doclet</artifactId> <4>
67+
<artifactId>spring-auto-restdocs-json-doclet</artifactId> <3>
6868
<version>${latestRelease}</version>
6969
</docletArtifact>
70-
<destDir>generated-javadoc-json</destDir> <3>
71-
<reportOutputDirectory>\${project.build.directory}</reportOutputDirectory> <3>
70+
<destDir>generated-javadoc-json</destDir> <2>
71+
<reportOutputDirectory>\${project.build.directory}</reportOutputDirectory> <2>
7272
<useStandardDocletOptions>false</useStandardDocletOptions>
7373
<show>package</show>
7474
</configuration>
@@ -79,12 +79,11 @@ For Java 9 support, use `spring-auto-restdocs-json-doclet-jdk9` as doclet depend
7979
</plugins>
8080
</build>
8181
----
82-
<1> Has to be removed if `@RestdocsNotExpanded` is used.
83-
<2> (Optional) Determines directory where snippets are saved. Defaults to `generated-snippets` in build directory.
84-
<3> (Optional) Determines where JSON files are saved. Defaults to `generated-javadoc-json` in build directory.
82+
<1> (Optional) Determines directory where snippets are saved. Defaults to `generated-snippets` in build directory.
83+
<2> (Optional) Determines where JSON files are saved. Defaults to `generated-javadoc-json` in build directory.
8584
Multiple directories can be listed by separating them with `,`.
8685
The directories are processed in order and only the first found JSON file is used.
87-
<4> For Java 9 support, use `spring-auto-restdocs-json-doclet-jdk9` as doclet dependency.
86+
<3> For Java 9 support, use `spring-auto-restdocs-json-doclet-jdk9` as doclet dependency.
8887

8988
+
9089
[source,javascript]
@@ -95,26 +94,26 @@ configurations {
9594
}
9695
9796
ext {
98-
javadocJsonDir = file("$buildDir/generated-javadoc-json") <3>
97+
javadocJsonDir = file("$buildDir/generated-javadoc-json") <2>
9998
}
10099
101100
dependencies {
102-
testCompile group: 'capital.scalable', name: 'spring-auto-restdocs-core', version: '${latestRelease}' <1>
103-
jsondoclet group: 'capital.scalable', name: 'spring-auto-restdocs-json-doclet', version: '${latestRelease}' <4>
101+
testCompile group: 'capital.scalable', name: 'spring-auto-restdocs-core', version: '${latestRelease}'
102+
jsondoclet group: 'capital.scalable', name: 'spring-auto-restdocs-json-doclet', version: '${latestRelease}' <3>
104103
}
105104
106105
task jsonDoclet(type: Javadoc, dependsOn: compileJava) {
107106
source = sourceSets.main.allJava
108107
classpath = sourceSets.main.compileClasspath
109-
destinationDir = javadocJsonDir <3>
108+
destinationDir = javadocJsonDir <2>
110109
options.docletpath = configurations.jsondoclet.files.asType(List)
111110
options.doclet = 'capital.scalable.restdocs.jsondoclet.ExtractDocumentationAsJsonDoclet'
112111
options.memberLevel = JavadocMemberLevel.PACKAGE
113112
}
114113
115114
test {
116-
systemProperty 'org.springframework.restdocs.outputDir', snippetsDir <2>
117-
systemProperty 'org.springframework.restdocs.javadocJsonDir', javadocJsonDir <3>
115+
systemProperty 'org.springframework.restdocs.outputDir', snippetsDir <1>
116+
systemProperty 'org.springframework.restdocs.javadocJsonDir', javadocJsonDir <2>
118117
119118
dependsOn jsonDoclet
120119
}
@@ -123,13 +122,12 @@ jar {
123122
dependsOn asciidoctor
124123
}
125124
----
126-
<1> Has to be `compile` instead of `testCompile` if `@RestdocsNotExpanded` is used.
127-
<2> (Optional) Determines directory where snippets are saved. Defaults to `generated-snippets` in build directory.
128-
<3> (Optional) Determines where JSON files are saved.
125+
<1> (Optional) Determines directory where snippets are saved. Defaults to `generated-snippets` in build directory.
126+
<2> (Optional) Determines where JSON files are saved.
129127
Defaults to `generated-javadoc-json` in build directory.
130128
Multiple directories can be listed by separating them with `,`.
131129
The directories are processed in order and only the first found JSON file is used.
132-
<4> For Java 9 support, use `spring-auto-restdocs-json-doclet-jdk9` as doclet dependency.
130+
<3> For Java 9 support, use `spring-auto-restdocs-json-doclet-jdk9` as doclet dependency.
133131

134132
. Configure MockMvc or WebTestClient
135133
+

spring-auto-restdocs-docs/other.adoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ See how it looks in the link:{html-preview}{example-dir}/generated-docs/index.ht
5151
For custom translations of section titles, table headers and other messages:
5252

5353
1. Create a file `SnippetMessages.properties` in `capital.scalable.restdocs.i18n` package.
54-
2. Add translations to the file using keys from link:{master-dir}/spring-auto-restdocs-core/src/test/resources/capital/scalable/restdocs/i18n/DefaultSnippetMessages.properties[DefaultSnippetMessages].
54+
2. Add translations to the file using keys from link:{master-dir}/spring-auto-restdocs-core/src/test/resources/capital/scalable/restdocs/i18n/DefaultSnippetMessages.properties[DefaultSnippetMessages].[[localization]]
55+
56+
=== Recursive structures support
57+
58+
To prevent infinite loop in recursive structures, annotate the recursive field with the `@RestdocsNotExpanded` annotation
59+
from the `spring-auto-restdocs-annotations` maven module.

0 commit comments

Comments
 (0)