From 4426b6caafbc04a2526dcd83009ffba54c7302c9 Mon Sep 17 00:00:00 2001 From: goyounha11 Date: Tue, 23 Jul 2024 11:12:01 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=91=EC=97=85=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 6 +++--- publish.gradle | 2 +- .../com/goyounha11/core/reponse/ApiResult.kt | 5 +++++ src/main/kotlin/com/goyounha11/docs/DocsUtil.kt | 15 ++++++++++++++- src/test/kotlin/com/goyounha11/api/UserApiTest.kt | 4 +++- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index bdbca7a..43cf582 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,8 +2,8 @@ import org.hidetake.gradle.swagger.generator.GenerateSwaggerUI import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - id("org.springframework.boot") version "3.1.5" - id("io.spring.dependency-management") version "1.1.3" + id("org.springframework.boot") version "3.3.1" + id("io.spring.dependency-management") version "1.1.5" id("com.epages.restdocs-api-spec") version "0.18.2" id("org.hidetake.swagger.generator") version "2.19.2" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" @@ -12,7 +12,7 @@ plugins { } group = "io.github.goyounha11" -version = "0.0.5" +version = "0.0.6" apply(from = "${rootDir}/scripts/publish-maven.gradle") apply(from = "publish.gradle") diff --git a/publish.gradle b/publish.gradle index f0bbe53..e294155 100644 --- a/publish.gradle +++ b/publish.gradle @@ -1,6 +1,6 @@ ext { PUBLISH_GROUP_ID = 'io.github.goyounha11' - PUBLISH_VERSION = '0.0.5' + PUBLISH_VERSION = '0.0.6' PUBLISH_ARTIFACT_ID = 'automatedAPIDocsUtil' PUBLISH_DESCRIPTION = 'restdocs simple create util' PUBLISH_URL = 'https://github.com/goyounha11/automatedAPIDocsUtil' diff --git a/src/main/kotlin/com/goyounha11/core/reponse/ApiResult.kt b/src/main/kotlin/com/goyounha11/core/reponse/ApiResult.kt index 6b42e8c..bba48f5 100644 --- a/src/main/kotlin/com/goyounha11/core/reponse/ApiResult.kt +++ b/src/main/kotlin/com/goyounha11/core/reponse/ApiResult.kt @@ -1,11 +1,16 @@ package com.goyounha11.core.reponse +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull import java.time.LocalDateTime data class ApiResult( + @field:NotBlank val code: String, + @field:NotBlank val message: String, + @field:NotNull val responseAt: LocalDateTime = LocalDateTime.now(), val data: T? = null ) { diff --git a/src/main/kotlin/com/goyounha11/docs/DocsUtil.kt b/src/main/kotlin/com/goyounha11/docs/DocsUtil.kt index dd8f414..9d32917 100644 --- a/src/main/kotlin/com/goyounha11/docs/DocsUtil.kt +++ b/src/main/kotlin/com/goyounha11/docs/DocsUtil.kt @@ -5,6 +5,7 @@ import com.epages.restdocs.apispec.ParameterDescriptorWithType import com.epages.restdocs.apispec.ResourceDocumentation.parameterWithName import com.epages.restdocs.apispec.ResourceDocumentation.resource import com.epages.restdocs.apispec.ResourceSnippetParametersBuilder +import com.epages.restdocs.apispec.Schema import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper @@ -40,7 +41,9 @@ object DocsUtil { description: String, resultActions: ResultActions, requestClazz: Class<*>? = null, - responseClazz: Class<*>? = null + responseClazz: Class<*>? = null, + requestSchema: String? = null, + responseSchema: String? = null ): RestDocumentationResultHandler { val resourceSnippetParametersBuilder = ResourceSnippetParametersBuilder().tags(tag).description(description) @@ -66,6 +69,16 @@ object DocsUtil { resourceSnippetParametersBuilder.pathParameters(requestPathParameter) resourceSnippetParametersBuilder.responseFields(responseFieldDescriptors) + resourceSnippetParametersBuilder.apply { + requestSchema?.let { schema -> + requestSchema(Schema(schema)) + } + + responseSchema?.let { schema -> + responseSchema(Schema(schema)) + } + } + return document( identifier, Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), diff --git a/src/test/kotlin/com/goyounha11/api/UserApiTest.kt b/src/test/kotlin/com/goyounha11/api/UserApiTest.kt index 2c59f0f..26b3436 100644 --- a/src/test/kotlin/com/goyounha11/api/UserApiTest.kt +++ b/src/test/kotlin/com/goyounha11/api/UserApiTest.kt @@ -71,7 +71,9 @@ internal class UserApiTest { "유저 회원가입 API", resultAction, UserCreateRequest::class.java, - UserCreateData::class.java + UserCreateData::class.java, + "UserCreateRequest", + "UserCreateData" ) ) }