Documentify allows easy and convenient creation of OpenAPI specification documents through Kotlin DSL, making users from the complexity of traditional RestDocs. It combines the advantages of both Swagger and RestDocs for efficient and intuitive document management.
Add the following dependency to your build.gradle.kts
file:
dependencies {
implementation("io.github.bgmsound:documentify-core:${version}")
}
Latest version : 0.0.2
First, make your test class extends Documentify
. and set up the test environment like this:
@BeforeEach
fun setUp(provider: RestDocumentationContextProvider) {
testService = mockk()
standalone(provider) {
controllers(TestController(testService))
}
}
You can also set up the test environment with a web application context or an auto-configured MockMvc.
webApplicationContext(provider, context)
mockMvc(provider, context)
And add the following code to your test class:
@BeforeEach
fun setUp(provider: RestDocumentationContextProvider) {
standalone(provider) {
controllers(TestController())
}
}
@Test
fun documentationGetApi() {
every { testService.test() } returns SampleResponse("path", "test")
documentation("test-get-api") {
information {
summary("test get api")
description("this is test get api")
tag("test")
}
requestLine(Method.GET, "/api/test/{path}") {
pathVariable("path", "path", "path")
}
responseBody {
field("testField1", "path", "path")
field("testField2", "message", "test")
}
}
}