Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST Docs + Epages 조합 API Document Generate #2

Closed
meloning opened this issue Jul 30, 2023 · 2 comments · Fixed by #23
Closed

REST Docs + Epages 조합 API Document Generate #2

meloning opened this issue Jul 30, 2023 · 2 comments · Fixed by #23
Labels
documentation Improvements or additions to documentation feature New feature or request
Milestone

Comments

@meloning
Copy link
Owner

meloning commented Jul 30, 2023

프로젝트 root 내 build.gradle.kts

plugins {
    id("org.springframework.boot") apply false
    id("io.spring.dependency-management") apply false

    id("org.jmailen.kotlinter")

    id("com.epages.restdocs-api-spec") apply false  // epages 플러그인 추가 version은 settings.gradle에서 적용할 것.

    kotlin("jvm")
    kotlin("kapt")
    kotlin("plugin.spring") apply false
    kotlin("plugin.jpa") apply false
}

...

val restDocsProject = listOf(
    project(":mega-coffee-api"), // Admin API가 추가될 수 있으니 list로 미리 선언
)
configure(restDocsProject) {
    apply(plugin = "com.epages.restdocs-api-spec")

    extensions.extraProperties["snippetsDir"] = file("build/generated-snippets")

    val epagesVersion: String by project

    dependencies {
        testImplementation("org.springframework.restdocs:spring-restdocs-mockmvc")

        testImplementation("com.epages:restdocs-api-spec:$epagesVersion")
        testImplementation("com.epages:restdocs-api-spec-mockmvc:$epagesVersion")
    }

    /**
     * @see <a href="https://github.com/ePages-de/restdocs-api-spec">Spring REST Docs API specification Integration</a>
     */
    configure<OpenApi3Extension> {
        setServer("http://localhost:9000")
        title = "MGC Employee Manage OpenApi Specification"
        version = "1.0.0"
        format = "yaml"
    }

    tasks.named("bootJar") {
        doLast {
            val sourceDir = project.file("swagger-ui")
            val yamlFile = project.file("${project.buildDir}/api-spec/openapi3.yaml")
            val targetDir = project.file("build/classes/kotlin/main/BOOT-INF/classes/static/swagger-ui")

            copy {
                from(sourceDir) {
                    into(targetDir)
                }
                from(yamlFile) {
                    into(targetDir)
                }
            }
        }
    }
}

이렇게 구성한 후 Redoc으로 열어서 API 문서들을 확인하면 될것 같다.

alt text

@meloning meloning added this to the v1.0.0 milestone Jul 30, 2023
@meloning meloning added documentation Improvements or additions to documentation feature New feature or request labels Jul 30, 2023
@meloning meloning linked a pull request Aug 26, 2023 that will close this issue
@meloning
Copy link
Owner Author

[Result]

Screenshot from 2023-08-27 02-58-23

Screenshot from 2023-08-27 02-59-18

원하는 문서 Output이 나오게 된거 같아 기쁘다.

이제 Github Action을 통해 변경된 문서를 반영할 수 있도록 Pipeline을 구축하면 될 것 같다.

@meloning
Copy link
Owner Author

[API Document URL]
https://meloning.github.io/redoc-meloning-api/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature New feature or request
Projects
None yet
1 participant