From ef6f9ae6ab52edf04ce26fc60a3b0835449882f9 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 18 Aug 2023 15:25:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Controller=E3=81=AE=E8=87=AA=E5=8B=95?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 43 +++++++++++++++++++++++++---- src/main/resources/openapi/api.yaml | 15 ++++++---- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8b799706..1f52b4a9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.openapitools.generator.gradle.plugin.tasks.GenerateTask val ktor_version: String by project val kotlin_version: String by project @@ -16,6 +17,7 @@ plugins { id("com.google.devtools.ksp") version "1.8.21-1.0.11" id("org.springframework.boot") version "3.1.2" kotlin("plugin.spring") version "1.8.21" + id("org.openapi.generator") version "6.6.0" // id("org.jetbrains.kotlin.plugin.serialization") version "1.8.10" } @@ -59,6 +61,35 @@ tasks.clean { delete += listOf("$rootDir/src/main/resources/static") } +tasks.create("openApiGenerateServer", GenerateTask::class) { + generatorName.set("kotlin-spring") + inputSpec.set("$rootDir/src/main/resources/openapi/api.yaml") + outputDir.set("$buildDir/generated/sources/openapi") + apiPackage.set("dev.usbharu.hideout.controller") + modelPackage.set("dev.usbharu.hideout.domain.model.generated") + configOptions.put("interfaceOnly", "true") + configOptions.put("useSpringBoot3", "true") + additionalProperties.put("useTags", "true") + schemaMappings.putAll( + mapOf( + "ReactionResponse" to "dev.usbharu.hideout.domain.model.hideout.dto.ReactionResponse", + "Account" to "dev.usbharu.hideout.domain.model.hideout.dto.Account", + "JwtToken" to "dev.usbharu.hideout.domain.model.hideout.dto.JwtToken", + "PostRequest" to "dev.usbharu.hideout.domain.model.hideout.form.Post", + "PostResponse" to "dev.usbharu.hideout.domain.model.hideout.dto.PostResponse", + "Reaction" to "dev.usbharu.hideout.domain.model.hideout.form.Reaction", + "RefreshToken" to "dev.usbharu.hideout.domain.model.hideout.form.RefreshToken", + "UserLogin" to "dev.usbharu.hideout.domain.model.hideout.form.UserLogin", + "UserResponse" to "dev.usbharu.hideout.domain.model.hideout.dto.UserResponse", + "UserCreate" to "dev.usbharu.hideout.domain.model.hideout.form.UserCreate", + "Visibility" to "dev.usbharu.hideout.domain.model.hideout.entity.Visibility", + ) + ) + +// importMappings.putAll(mapOf("ReactionResponse" to "ReactionResponse")) +// typeMappings.putAll(mapOf("ReactionResponse" to "ReactionResponse")) +} + repositories { mavenCentral() } @@ -72,7 +103,7 @@ kotlin { } sourceSets.main { - kotlin.srcDirs("$buildDir/generated/ksp/main") + kotlin.srcDirs("$buildDir/generated/ksp/main", "$buildDir/generated/sources/openapi/src/main/kotlin") } dependencies { @@ -104,8 +135,10 @@ dependencies { ksp("io.insert-koin:koin-ksp-compiler:1.2.0") implementation("org.springframework.boot:spring-boot-starter-web") - - + implementation("jakarta.validation:jakarta.validation-api") + implementation("jakarta.annotation:jakarta.annotation-api:2.1.0") + compileOnly("io.swagger.core.v3:swagger-annotations:2.2.6") + implementation("io.swagger.core.v3:swagger-models:2.2.6") implementation("io.ktor:ktor-client-logging-jvm:$ktor_version") implementation("io.ktor:ktor-server-host-common-jvm:$ktor_version") @@ -113,7 +146,7 @@ dependencies { testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version") testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") - testImplementation ("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4") + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4") implementation("io.ktor:ktor-client-core:$ktor_version") implementation("io.ktor:ktor-client-cio:$ktor_version") @@ -153,7 +186,7 @@ graalvmNative { named("main") { fallback.set(false) verbose.set(true) - agent{ + agent { enabled.set(false) } diff --git a/src/main/resources/openapi/api.yaml b/src/main/resources/openapi/api.yaml index 840daedd..8cbfd648 100644 --- a/src/main/resources/openapi/api.yaml +++ b/src/main/resources/openapi/api.yaml @@ -214,12 +214,7 @@ paths: content: application/json: schema: - type: object - properties: - username: - type: string - password: - type: string + $ref: "#/components/schemas/UserCreate" responses: 201: description: ユーザーが作成された @@ -509,6 +504,14 @@ components: url: type: string + UserCreate: + type: object + properties: + username: + type: string + password: + type: string + securitySchemes: BearerAuth: type: http