Skip to content

Commit 415f402

Browse files
committed
Support Spring REST Docs 3.0.0 (ePages-de#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
1 parent 9b84729 commit 415f402

File tree

22 files changed

+268
-110
lines changed

22 files changed

+268
-110
lines changed

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.10" 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-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-openapi-generator/src/main/kotlin/com/epages/restdocs/apispec/openapi2/OpenApi20Generator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ object OpenApi20Generator {
327327
SecurityType.OAUTH2 -> addSecurity(OAUTH2_SECURITY_NAME, securityRequirements2ScopesList(securityRequirements))
328328
SecurityType.BASIC -> addSecurity(BASIC_SECURITY_NAME, null)
329329
SecurityType.API_KEY -> addSecurity(API_KEY_SECURITY_NAME, null)
330+
SecurityType.JWT_BEARER -> { /* not specified for OpenApi 2.0 */ }
330331
}
331332
}
332333
}

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

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

restdocs-api-spec-restassured/src/main/kotlin/com/epages/restdocs/apispec/RestAssuredRestDocumentationWrapper.kt

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

33
import org.springframework.restdocs.operation.preprocess.OperationRequestPreprocessor
44
import org.springframework.restdocs.operation.preprocess.OperationResponsePreprocessor
5-
import org.springframework.restdocs.restassured3.RestAssuredRestDocumentation
6-
import org.springframework.restdocs.restassured3.RestDocumentationFilter
5+
import org.springframework.restdocs.restassured.RestAssuredRestDocumentation
6+
import org.springframework.restdocs.restassured.RestDocumentationFilter
77
import org.springframework.restdocs.snippet.Snippet
88
import java.util.function.Function
99

0 commit comments

Comments
 (0)