Skip to content

Commit 2d5bb22

Browse files
authored
Support Spring REST Docs 3.0.0 (#211) (#225)
* Support Spring REST Docs 3.0.0 (#211) According to spring-rest-docs 'requestParameters' are replaced by 'queryParameters' and 'formParameters'. If 'requestParameters' are used to document the API, this must be replaced by one of the new functions Upgrades (needed to use spring-rest-docs 3.0.0): * gradle 7.6 * kotlin 1.7.10 * spring-boot 3.0.2 * java 17 * Use java-17 in travis ci * use kotlin 1.7.22 as there are runtime dependencies to this version * Update generators and gradle plugin for rest-docs v3
1 parent 9f7318f commit 2d5bb22

30 files changed

Lines changed: 341 additions & 162 deletions

File tree

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dist: focal
22
before_install:
3-
- sudo apt-get install -y openjdk-8-jdk
3+
- sudo apt-get install -y openjdk-17-jdk
44
before_cache:
55
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
66
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
@@ -25,7 +25,7 @@ env:
2525
global:
2626
- CI_NAME=travis-ci
2727
- SIGNING_KEYRING_FILE="${TRAVIS_BUILD_DIR}/secret-keys.gpg"
28-
- JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
28+
- JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
2929
# coveralls
3030
- secure: "nOkY2AcR5Z7hKKzi+zCzmzPk+xiRRrJjGliDJnHnEO7g+iJ8SmT+thHuMFcXqvjxJ006LbR3GPB8M8qgFXFDPEUDRPppShi3waOm1ddlM2iXh9kbCoROoioyRO+F07deH6ExibkLbu/xq3WwAAw7lx/ZP+buc2R2VCbV0nLKP9iE4nHQX8msLgmU1LjWf0Au1Pgl2eWXV0J4/ZJOvcVu9hvBf1Ow4C7BNb0KZmMjeT9uMK0hiGpb9VVbwedOWfsbaFmqmKYqVKS8UtNmG+HBjvZfajrIARKRPc9w9uEvfl4E1H/J7PJLy2kOrCOauj8LMu6DduSrWcg08T5VnH51cavSAsWWG1ImTgEsUBNpllc9r1XLhQCLQ1TWCgGmleqYjZ2ySvg0MQpFjTgXMZC+aDkjZjcEeq3BgrncAR/bcG4ByrZBWyoEXDxBwoMZnkryTxK07UUgXRXdjJUldJ5CQW9oSfd+oEXKJyqQGNt0ob3S0sRS5uhrKniK+6Mwzxf6vXeYvn2fVP5j3hocUz4XzDJQoDDmJi6D4BpwksqJ81CNOHpyeDIOhdXxvA/J8DMCK0Q7tTSbnSOxItaht56CSxqqLSGax3/4Nr+5QX9jpmdJ03HdpP+MOuIl6dZCmE4/w1IFaFEfhpETPlnWZHl1BsOt7omDeW7yCttDq3Y1mXU="
3131
# gradle plugin portal

build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
id("pl.allegro.tech.build.axion-release") version "1.9.2"
1313
jacoco
1414
java
15-
kotlin("jvm") version "1.4.20" apply false
15+
kotlin("jvm") version "1.7.22" apply false
1616
`maven-publish`
1717
}
1818

@@ -58,12 +58,12 @@ allprojects {
5858
subprojects {
5959

6060
val jacksonVersion by extra { "2.12.2" }
61-
val springBootVersion by extra { "2.1.9.RELEASE" }
62-
val springRestDocsVersion by extra { "2.0.4.RELEASE" }
61+
val springBootVersion by extra { "3.0.2" }
62+
val springRestDocsVersion by extra { "3.0.0" }
6363
val junitVersion by extra { "5.4.2" }
6464

6565
tasks.withType<KotlinCompile> {
66-
kotlinOptions.jvmTarget = "1.8"
66+
kotlinOptions.jvmTarget = "17"
6767
}
6868

6969
tasks.withType<Test> {

gradle/wrapper/gradle-wrapper.jar

1.71 KB
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
4+
networkTimeout=10000
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

gradlew

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

restdocs-api-spec-gradle-plugin/src/test/kotlin/com/epages/restdocs/apispec/gradle/ApiSpecTaskTest.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ abstract class ApiSpecTaskTest {
102102
"contentType" : null,
103103
"headers" : [ ],
104104
"pathParameters" : [ ],
105-
"requestParameters" : [ ],
105+
"queryParameters" : [ ],
106+
"formParameters" : [ ],
106107
"requestFields" : [ ],
107108
"example" : null,
108109
"securityRequirements" : {
@@ -146,7 +147,8 @@ abstract class ApiSpecTaskTest {
146147
"default" : "a default value"
147148
} ],
148149
"pathParameters" : [ ],
149-
"requestParameters" : [ ],
150+
"queryParameters" : [ ],
151+
"formParameters" : [ ],
150152
"requestFields" : [ ],
151153
"example" : null,
152154
"securityRequirements" : {
@@ -182,7 +184,8 @@ abstract class ApiSpecTaskTest {
182184
"contentType" : null,
183185
"headers" : [ ],
184186
"pathParameters" : [ ],
185-
"requestParameters" : [ ],
187+
"queryParameters" : [ ],
188+
"formParameters" : [ ],
186189
"requestFields" : [ ],
187190
"example" : null,
188191
"securityRequirements" : null

restdocs-api-spec-mockmvc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
testImplementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion") {
2121
exclude("junit")
2222
}
23+
testImplementation("org.springframework.boot:spring-boot-starter-validation:$springBootVersion")
2324
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
2425
testImplementation("org.junit-pioneer:junit-pioneer:0.3.0")
2526
testImplementation("org.springframework.boot:spring-boot-starter-hateoas:$springBootVersion")

restdocs-api-spec-mockmvc/src/test/kotlin/com/epages/restdocs/apispec/ResourceSnippetIntegrationTest.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ package com.epages.restdocs.apispec
22

33
import com.epages.restdocs.apispec.ResourceDocumentation.parameterWithName
44
import com.epages.restdocs.apispec.ResourceDocumentation.resource
5+
import jakarta.validation.constraints.NotEmpty
56
import org.hibernate.validator.constraints.Length
67
import org.junit.jupiter.api.extension.ExtendWith
78
import org.springframework.boot.SpringApplication
89
import org.springframework.boot.autoconfigure.SpringBootApplication
910
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
1011
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
1112
import org.springframework.context.ConfigurableApplicationContext
13+
import org.springframework.hateoas.EntityModel
14+
import org.springframework.hateoas.IanaLinkRelations
1215
import org.springframework.hateoas.Link
13-
import org.springframework.hateoas.Resource
14-
import org.springframework.hateoas.mvc.BasicLinkBuilder
16+
import org.springframework.hateoas.server.mvc.BasicLinkBuilder.linkToCurrentMapping
1517
import org.springframework.http.HttpHeaders.ACCEPT
1618
import org.springframework.http.HttpHeaders.CONTENT_TYPE
1719
import org.springframework.http.ResponseEntity
@@ -26,7 +28,6 @@ import org.springframework.web.bind.annotation.RequestBody
2628
import org.springframework.web.bind.annotation.RequestHeader
2729
import org.springframework.web.bind.annotation.RestController
2830
import java.util.UUID
29-
import javax.validation.constraints.NotEmpty
3031

3132
@ExtendWith(SpringExtension::class)
3233
@WebMvcTest
@@ -53,17 +54,17 @@ open class ResourceSnippetIntegrationTest {
5354
@PathVariable otherId: Int?,
5455
@RequestHeader("X-Custom-Header") customHeader: String,
5556
@RequestBody testDataHolder: TestDataHolder
56-
): ResponseEntity<Resource<TestDataHolder>> {
57-
val resource = Resource(testDataHolder.copy(id = UUID.randomUUID().toString()))
58-
val link = BasicLinkBuilder.linkToCurrentMapping().slash("some").slash(someId).slash("other").slash(otherId).toUri().toString()
59-
resource.add(Link(link, Link.REL_SELF))
60-
resource.add(Link(link, "multiple"))
61-
resource.add(Link(link, "multiple"))
57+
): ResponseEntity<EntityModel<TestDataHolder>> {
58+
val resource = EntityModel.of(testDataHolder.copy(id = UUID.randomUUID().toString()))
59+
val link = linkToCurrentMapping().slash("some").slash(someId).slash("other").slash(otherId).toUri().toString()
60+
resource.add(Link.of(link, IanaLinkRelations.SELF))
61+
resource.add(Link.of(link, "multiple"))
62+
resource.add(Link.of(link, "multiple"))
6263

6364
return ResponseEntity
6465
.ok()
6566
.header("X-Custom-Header", customHeader)
66-
.body<Resource<TestDataHolder>>(resource)
67+
.body<EntityModel<TestDataHolder>>(resource)
6768
}
6869
}
6970
}

restdocs-api-spec-model/src/main/kotlin/com/epages/restdocs/apispec/model/ResourceModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ data class RequestModel(
3737
val securityRequirements: SecurityRequirements?,
3838
val headers: List<HeaderDescriptor>,
3939
val pathParameters: List<ParameterDescriptor>,
40-
val requestParameters: List<ParameterDescriptor>,
40+
val queryParameters: List<ParameterDescriptor>,
41+
val formParameters: List<ParameterDescriptor>,
4142
val requestFields: List<FieldDescriptor>,
4243
val example: String? = null,
4344
val schema: Schema? = null

0 commit comments

Comments
 (0)