Spring Rest Docs

장점 단점
- 테스트가 성공해야 문서 생성 되기 때문에 API 명세 최신화가 강제된다

공식 문서

https://docs.spring.io/spring-restdocs/docs/current/reference/htmlsingle/#introduction

최소 요구사항

build.gradle

plugins {
    id "org.asciidoctor.jvm.convert" version "3.3.2"  // ①
}

configurations {
    asciidoctorExt // ②
}

dependencies {
    //..
    
    //③
    asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'
    testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
}

ext { // ④
    snippetsDir = file("${layout.buildDirectory.asFile.get()}/generated-snippets")
}

test {
    outputs.dir snippetsDir  // ⑤
    useJUnitPlatform()
}

asciidoctor.doFirst { // ⑥
    delete file("src/main/resources/static/docs")
}

asciidoctor { // ⑦
    configurations 'asciidoctorExt'
    baseDirFollowsSourceDir()
    inputs.dir snippetsDir
    dependsOn test
}

task createDocument(type: Copy) { // ⑧
    dependsOn asciidoctor
    from file("${layout.buildDirectory.asFile.get()}/docs/asciidoc")
    into file("src/main/resources/static/docs")
}

bootJar {
    dependsOn createDocument
    from("${asciidoctor.outputDir}") {
        into 'static/docs'
    }
}

// test > asciidoctor > createDocument > build
build {
    dependsOn createDocument
}

① asciidoc 문서를 html, pdf 등 다양한 형식으로 변환하는데 사용되는 gradle 플러그인

② configuration

③ 의존성 추가