From 23507f1812111875506ecf7607c0dff233b8e3c5 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 3 Jun 2024 00:44:43 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20core=E3=81=8B=E3=82=89mastodon?= =?UTF-8?q?=E3=81=AB=E3=83=86=E3=83=B3=E3=83=97=E3=83=AC=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=82=92=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 43 +++++++++- hideout-core/build.gradle.kts | 22 ------ .../RegisterLocalActorApplicationService.kt | 2 +- .../hideout/core/config/ApplicationConfig.kt | 26 +++++++ .../actor/RemoteActorCheckDomainService.kt | 2 +- .../factory/ActorFactoryImpl.kt | 2 +- .../infrastructure/factory/PostFactoryImpl.kt | 2 +- .../hideout/generate/JsonOrFormBind.kt | 22 ++++++ .../JsonOrFormModelMethodProcessor.kt | 78 +++++++++++++++++++ .../dev/usbharu/hideout/util/RsaUtil.kt | 8 -- hideout-mastodon/build.gradle.kts | 53 ++++++++++++- hideout-mastodon/settings.gradle.kts | 13 ++++ .../src/main/resources/openapi/mastodon.yaml | 0 .../templates/api.mustache | 0 .../templates/apiController.mustache | 0 .../templates/apiDelegate.mustache | 0 .../templates/apiInterface.mustache | 0 .../templates/apiUtil.mustache | 0 .../templates/api_test.mustache | 0 .../templates/beanValidation.mustache | 0 .../templates/beanValidationModel.mustache | 0 .../templates/beanValidationPath.mustache | 0 .../beanValidationPathParams.mustache | 0 .../beanValidationQueryParams.mustache | 0 .../templates/bodyParams.mustache | 0 .../templates/dataClass.mustache | 0 .../templates/dataClassOptVar.mustache | 0 .../templates/dataClassReqVar.mustache | 0 .../templates/enumClass.mustache | 0 .../templates/exceptions.mustache | 0 .../templates/formParams.mustache | 0 .../templates/generatedAnnotation.mustache | 0 .../templates/headerParams.mustache | 0 .../templates/homeController.mustache | 0 .../templates/interfaceOptVar.mustache | 0 .../templates/interfaceReqVar.mustache | 0 .../libraries/spring-boot/README.mustache | 0 .../spring-boot/application.mustache | 0 .../spring-boot/buildGradle-sb3-Kts.mustache | 0 .../spring-boot/buildGradleKts.mustache | 0 .../spring-boot/defaultBasePath.mustache | 0 .../libraries/spring-boot/pom-sb3.mustache | 0 .../libraries/spring-boot/pom.mustache | 0 .../spring-boot/settingsGradle.mustache | 0 .../springBootApplication.mustache | 0 .../libraries/spring-boot/swagger-ui.mustache | 0 .../libraries/spring-cloud/README.mustache | 0 .../libraries/spring-cloud/apiClient.mustache | 0 .../apiKeyRequestInterceptor.mustache | 0 .../spring-cloud/buildGradle-sb3-Kts.mustache | 0 .../spring-cloud/buildGradleKts.mustache | 0 .../spring-cloud/clientConfiguration.mustache | 0 .../libraries/spring-cloud/pom-sb3.mustache | 0 .../libraries/spring-cloud/pom.mustache | 0 .../spring-cloud/settingsGradle.mustache | 0 .../templates/methodBody.mustache | 0 .../templates/model.mustache | 0 .../templates/modelMutable.mustache | 0 .../templates/openapi.mustache | 0 .../templates/optionalDataType.mustache | 0 .../templates/pathParams.mustache | 0 .../templates/queryParams.mustache | 0 .../templates/returnTypes.mustache | 0 .../templates/returnValue.mustache | 0 .../templates/service.mustache | 0 .../templates/serviceImpl.mustache | 0 .../springdocDocumentationConfig.mustache | 0 .../springfoxDocumentationConfig.mustache | 0 .../templates/typeInfoAnnotation.mustache | 0 settings.gradle.kts | 1 + 70 files changed, 236 insertions(+), 38 deletions(-) create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/ApplicationConfig.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormBind.kt create mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt rename {hideout-core => hideout-mastodon}/src/main/resources/openapi/mastodon.yaml (100%) rename {hideout-core => hideout-mastodon}/templates/api.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/apiController.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/apiDelegate.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/apiInterface.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/apiUtil.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/api_test.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/beanValidation.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/beanValidationModel.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/beanValidationPath.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/beanValidationPathParams.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/beanValidationQueryParams.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/bodyParams.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/dataClass.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/dataClassOptVar.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/dataClassReqVar.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/enumClass.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/exceptions.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/formParams.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/generatedAnnotation.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/headerParams.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/homeController.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/interfaceOptVar.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/interfaceReqVar.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/README.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/application.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/buildGradle-sb3-Kts.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/buildGradleKts.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/defaultBasePath.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/pom-sb3.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/pom.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/settingsGradle.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/springBootApplication.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-boot/swagger-ui.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-cloud/README.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-cloud/apiClient.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-cloud/apiKeyRequestInterceptor.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-cloud/buildGradle-sb3-Kts.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-cloud/buildGradleKts.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-cloud/clientConfiguration.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-cloud/pom-sb3.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-cloud/pom.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/libraries/spring-cloud/settingsGradle.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/methodBody.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/model.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/modelMutable.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/openapi.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/optionalDataType.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/pathParams.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/queryParams.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/returnTypes.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/returnValue.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/service.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/serviceImpl.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/springdocDocumentationConfig.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/springfoxDocumentationConfig.mustache (100%) rename {hideout-core => hideout-mastodon}/templates/typeInfoAnnotation.mustache (100%) diff --git a/build.gradle.kts b/build.gradle.kts index c0e7f565..3ad2888b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,13 +16,54 @@ plugins { alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.spring.boot) + alias(libs.plugins.kotlin.spring) +} + +apply { + plugin("io.spring.dependency-management") +} + +repositories { + mavenCentral() + maven { + url = uri("https://git.usbharu.dev/api/packages/usbharu/maven") + } + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/usbharu/http-signature") + credentials { + + username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") + password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") + } + } + maven { + name = "GitHubPackages2" + url = uri("https://maven.pkg.github.com/multim-dev/emoji-kt") + credentials { + + username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME") + password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN") + } + } +} +configurations { + all { + exclude("org.springframework.boot", "spring-boot-starter-logging") + exclude("ch.qos.logback", "logback-classic") + } } dependencies { implementation("dev.usbharu:hideout-core:0.0.1") - implementation("dev.usbharu:hideout-worker:0.0.1") + implementation("dev.usbharu:hideout-mastodon:1.0-SNAPSHOT") } tasks.register("run") { dependsOn(gradle.includedBuild("hideout-core").task(":run")) +} + +springBoot { + mainClass = "dev.usbharu.hideout.SpringApplicationKt" } \ No newline at end of file diff --git a/hideout-core/build.gradle.kts b/hideout-core/build.gradle.kts index 52db4593..5920eb91 100644 --- a/hideout-core/build.gradle.kts +++ b/hideout-core/build.gradle.kts @@ -4,14 +4,12 @@ import com.github.jk1.license.importer.DependencyDataImporter import com.github.jk1.license.importer.XmlReportImporter import com.github.jk1.license.render.* import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import org.openapitools.generator.gradle.plugin.tasks.GenerateTask plugins { alias(libs.plugins.kotlin.jvm) alias(libs.plugins.detekt) alias(libs.plugins.spring.boot) alias(libs.plugins.kotlin.spring) - alias(libs.plugins.openapi.generator) alias(libs.plugins.kover) alias(libs.plugins.license.report) @@ -102,26 +100,6 @@ tasks.clean { delete += listOf("$rootDir/src/main/resources/static") } -tasks.create("openApiGenerateMastodonCompatibleApi", GenerateTask::class) { - generatorName.set("kotlin-spring") - inputSpec.set("$rootDir/src/main/resources/openapi/mastodon.yaml") - outputDir.set("$buildDir/generated/sources/mastodon") - apiPackage.set("dev.usbharu.hideout.controller.mastodon.generated") - modelPackage.set("dev.usbharu.hideout.domain.mastodon.model.generated") - configOptions.put("interfaceOnly", "true") - configOptions.put("useSpringBoot3", "true") - configOptions.put("reactive", "true") - additionalProperties.put("useTags", "true") - - importMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile") - typeMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile") - schemaMappings.put( - "StatusesRequest", - "dev.usbharu.hideout.mastodon.interfaces.api.status.StatusesRequest" - ) - templateDir.set("$rootDir/templates") -} - repositories { mavenCentral() maven { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActorApplicationService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActorApplicationService.kt index e52af918..6608a0e2 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActorApplicationService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/application/actor/RegisterLocalActorApplicationService.kt @@ -16,8 +16,8 @@ package dev.usbharu.hideout.core.application.actor -import dev.usbharu.hideout.application.config.ApplicationConfig import dev.usbharu.hideout.core.application.shared.Transaction +import dev.usbharu.hideout.core.config.ApplicationConfig import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.instance.InstanceRepository import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/ApplicationConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/ApplicationConfig.kt new file mode 100644 index 00000000..b4b0e391 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/ApplicationConfig.kt @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.core.config + +import org.springframework.boot.context.properties.ConfigurationProperties +import java.net.URL + +@ConfigurationProperties("hideout") +data class ApplicationConfig( + val url: URL, + val private: Boolean = true, +) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt index d7bf7ba8..a2f9b6fd 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/service/actor/RemoteActorCheckDomainService.kt @@ -16,7 +16,7 @@ package dev.usbharu.hideout.core.domain.service.actor -import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.core.config.ApplicationConfig import dev.usbharu.hideout.core.domain.model.actor.Actor import org.springframework.stereotype.Service diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt index 3e610e53..d9e56e09 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/ActorFactoryImpl.kt @@ -16,7 +16,7 @@ package dev.usbharu.hideout.core.infrastructure.factory -import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.core.config.ApplicationConfig import dev.usbharu.hideout.core.domain.model.actor.* import dev.usbharu.hideout.core.domain.model.instance.InstanceId import dev.usbharu.hideout.core.domain.model.shared.Domain diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt index 822035d9..ab31daf1 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt @@ -16,7 +16,7 @@ package dev.usbharu.hideout.core.infrastructure.factory -import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.core.config.ApplicationConfig import dev.usbharu.hideout.core.domain.model.actor.ActorId import dev.usbharu.hideout.core.domain.model.actor.ActorName import dev.usbharu.hideout.core.domain.model.media.MediaId diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormBind.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormBind.kt new file mode 100644 index 00000000..4a74319e --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormBind.kt @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.generate + +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.VALUE_PARAMETER) +annotation class JsonOrFormBind diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt new file mode 100644 index 00000000..d7a97736 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/generate/JsonOrFormModelMethodProcessor.kt @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2024 usbharu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.usbharu.hideout.generate + +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.core.MethodParameter +import org.springframework.validation.BindException +import org.springframework.web.bind.support.WebDataBinderFactory +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.web.method.annotation.ModelAttributeMethodProcessor +import org.springframework.web.method.support.HandlerMethodArgumentResolver +import org.springframework.web.method.support.ModelAndViewContainer +import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor + +@Suppress("TooGenericExceptionCaught") +class JsonOrFormModelMethodProcessor( + private val modelAttributeMethodProcessor: ModelAttributeMethodProcessor, + private val requestResponseBodyMethodProcessor: RequestResponseBodyMethodProcessor, +) : HandlerMethodArgumentResolver { + private val isJsonRegex = Regex("application/((\\w*)\\+)?json") + + override fun supportsParameter(parameter: MethodParameter): Boolean = + parameter.hasParameterAnnotation(JsonOrFormBind::class.java) + + override fun resolveArgument( + parameter: MethodParameter, + mavContainer: ModelAndViewContainer?, + webRequest: NativeWebRequest, + binderFactory: WebDataBinderFactory?, + ): Any? { + val contentType = webRequest.getHeader("Content-Type").orEmpty() + logger.trace("ContentType is {}", contentType) + if (contentType.contains(isJsonRegex)) { + logger.trace("Determine content type as json.") + return requestResponseBodyMethodProcessor.resolveArgument( + parameter, + mavContainer, + webRequest, + binderFactory + ) + } + + return try { + modelAttributeMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory) + } catch (e: BindException) { + throw e + } catch (exception: Exception) { + try { + requestResponseBodyMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory) + } catch (e: BindException) { + throw e + } catch (e: Exception) { + logger.warn("Failed to bind request (1)", exception) + logger.warn("Failed to bind request (2)", e) + throw IllegalArgumentException("Failed to bind request.") + } + } + } + + companion object { + val logger: Logger = LoggerFactory.getLogger(JsonOrFormModelMethodProcessor::class.java) + } +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt index 56b20ac3..3460a515 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt @@ -17,9 +17,7 @@ package dev.usbharu.hideout.util import java.security.KeyFactory -import java.security.interfaces.RSAPrivateKey import java.security.interfaces.RSAPublicKey -import java.security.spec.PKCS8EncodedKeySpec import java.security.spec.X509EncodedKeySpec object RsaUtil { @@ -38,10 +36,4 @@ object RsaUtil { return decodeRsaPublicKey(replace) } - fun decodeRsaPrivateKey(byteArray: ByteArray): RSAPrivateKey { - val pkcS8EncodedKeySpec = PKCS8EncodedKeySpec(byteArray) - return KeyFactory.getInstance("RSA").generatePrivate(pkcS8EncodedKeySpec) as RSAPrivateKey - } - - fun decodeRsaPrivateKey(encoded: String): RSAPrivateKey = decodeRsaPrivateKey(Base64Util.decode(encoded)) } diff --git a/hideout-mastodon/build.gradle.kts b/hideout-mastodon/build.gradle.kts index 45be2756..2907614d 100644 --- a/hideout-mastodon/build.gradle.kts +++ b/hideout-mastodon/build.gradle.kts @@ -1,5 +1,15 @@ +import org.openapitools.generator.gradle.plugin.tasks.GenerateTask + plugins { - kotlin("jvm") version "1.9.23" + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.openapi.generator) + alias(libs.plugins.spring.boot) + alias(libs.plugins.kotlin.spring) +} + + +apply { + plugin("io.spring.dependency-management") } group = "dev.usbharu" @@ -10,7 +20,19 @@ repositories { } dependencies { - testImplementation(kotlin("test")) + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-security") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + + implementation("dev.usbharu:hideout-core:0.0.1") + + implementation(libs.jackson.databind) + implementation(libs.jackson.module.kotlin) + implementation(libs.jakarta.annotation) + implementation(libs.jakarta.validation) + + implementation(libs.bundles.openapi) + implementation(libs.bundles.coroutines) } tasks.test { @@ -18,4 +40,29 @@ tasks.test { } kotlin { jvmToolchain(21) -} \ No newline at end of file +} + +tasks.create("openApiGenerateMastodonCompatibleApi", GenerateTask::class) { + generatorName.set("kotlin-spring") + inputSpec.set("$rootDir/src/main/resources/openapi/mastodon.yaml") + outputDir.set("$buildDir/generated/sources/mastodon") + apiPackage.set("dev.usbharu.hideout.mastodon.interfaces.api.generated") + modelPackage.set("dev.usbharu.hideout.mastodon.interfaces.api.generated.model") + configOptions.put("interfaceOnly", "true") + configOptions.put("useSpringBoot3", "true") + configOptions.put("reactive", "true") + configOptions.put("gradleBuildFile", "false") + configOptions.put("useSwaggerUI", "false") + configOptions.put("enumPropertyNaming", "UPPERCASE") + additionalProperties.put("useTags", "true") + + importMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile") + typeMappings.put("org.springframework.core.io.Resource", "org.springframework.web.multipart.MultipartFile") + templateDir.set("$rootDir/templates") +} + +sourceSets.main { + kotlin.srcDirs( + "$buildDir/generated/sources/mastodon/src/main/kotlin" + ) +} diff --git a/hideout-mastodon/settings.gradle.kts b/hideout-mastodon/settings.gradle.kts index c023f31a..9334d94c 100644 --- a/hideout-mastodon/settings.gradle.kts +++ b/hideout-mastodon/settings.gradle.kts @@ -3,3 +3,16 @@ plugins { } rootProject.name = "hideout-mastodon" +includeBuild("../hideout-core") + +dependencyResolutionManagement { + repositories { + mavenCentral() + } + + versionCatalogs { + create("libs") { + from(files("../libs.versions.toml")) + } + } +} \ No newline at end of file diff --git a/hideout-core/src/main/resources/openapi/mastodon.yaml b/hideout-mastodon/src/main/resources/openapi/mastodon.yaml similarity index 100% rename from hideout-core/src/main/resources/openapi/mastodon.yaml rename to hideout-mastodon/src/main/resources/openapi/mastodon.yaml diff --git a/hideout-core/templates/api.mustache b/hideout-mastodon/templates/api.mustache similarity index 100% rename from hideout-core/templates/api.mustache rename to hideout-mastodon/templates/api.mustache diff --git a/hideout-core/templates/apiController.mustache b/hideout-mastodon/templates/apiController.mustache similarity index 100% rename from hideout-core/templates/apiController.mustache rename to hideout-mastodon/templates/apiController.mustache diff --git a/hideout-core/templates/apiDelegate.mustache b/hideout-mastodon/templates/apiDelegate.mustache similarity index 100% rename from hideout-core/templates/apiDelegate.mustache rename to hideout-mastodon/templates/apiDelegate.mustache diff --git a/hideout-core/templates/apiInterface.mustache b/hideout-mastodon/templates/apiInterface.mustache similarity index 100% rename from hideout-core/templates/apiInterface.mustache rename to hideout-mastodon/templates/apiInterface.mustache diff --git a/hideout-core/templates/apiUtil.mustache b/hideout-mastodon/templates/apiUtil.mustache similarity index 100% rename from hideout-core/templates/apiUtil.mustache rename to hideout-mastodon/templates/apiUtil.mustache diff --git a/hideout-core/templates/api_test.mustache b/hideout-mastodon/templates/api_test.mustache similarity index 100% rename from hideout-core/templates/api_test.mustache rename to hideout-mastodon/templates/api_test.mustache diff --git a/hideout-core/templates/beanValidation.mustache b/hideout-mastodon/templates/beanValidation.mustache similarity index 100% rename from hideout-core/templates/beanValidation.mustache rename to hideout-mastodon/templates/beanValidation.mustache diff --git a/hideout-core/templates/beanValidationModel.mustache b/hideout-mastodon/templates/beanValidationModel.mustache similarity index 100% rename from hideout-core/templates/beanValidationModel.mustache rename to hideout-mastodon/templates/beanValidationModel.mustache diff --git a/hideout-core/templates/beanValidationPath.mustache b/hideout-mastodon/templates/beanValidationPath.mustache similarity index 100% rename from hideout-core/templates/beanValidationPath.mustache rename to hideout-mastodon/templates/beanValidationPath.mustache diff --git a/hideout-core/templates/beanValidationPathParams.mustache b/hideout-mastodon/templates/beanValidationPathParams.mustache similarity index 100% rename from hideout-core/templates/beanValidationPathParams.mustache rename to hideout-mastodon/templates/beanValidationPathParams.mustache diff --git a/hideout-core/templates/beanValidationQueryParams.mustache b/hideout-mastodon/templates/beanValidationQueryParams.mustache similarity index 100% rename from hideout-core/templates/beanValidationQueryParams.mustache rename to hideout-mastodon/templates/beanValidationQueryParams.mustache diff --git a/hideout-core/templates/bodyParams.mustache b/hideout-mastodon/templates/bodyParams.mustache similarity index 100% rename from hideout-core/templates/bodyParams.mustache rename to hideout-mastodon/templates/bodyParams.mustache diff --git a/hideout-core/templates/dataClass.mustache b/hideout-mastodon/templates/dataClass.mustache similarity index 100% rename from hideout-core/templates/dataClass.mustache rename to hideout-mastodon/templates/dataClass.mustache diff --git a/hideout-core/templates/dataClassOptVar.mustache b/hideout-mastodon/templates/dataClassOptVar.mustache similarity index 100% rename from hideout-core/templates/dataClassOptVar.mustache rename to hideout-mastodon/templates/dataClassOptVar.mustache diff --git a/hideout-core/templates/dataClassReqVar.mustache b/hideout-mastodon/templates/dataClassReqVar.mustache similarity index 100% rename from hideout-core/templates/dataClassReqVar.mustache rename to hideout-mastodon/templates/dataClassReqVar.mustache diff --git a/hideout-core/templates/enumClass.mustache b/hideout-mastodon/templates/enumClass.mustache similarity index 100% rename from hideout-core/templates/enumClass.mustache rename to hideout-mastodon/templates/enumClass.mustache diff --git a/hideout-core/templates/exceptions.mustache b/hideout-mastodon/templates/exceptions.mustache similarity index 100% rename from hideout-core/templates/exceptions.mustache rename to hideout-mastodon/templates/exceptions.mustache diff --git a/hideout-core/templates/formParams.mustache b/hideout-mastodon/templates/formParams.mustache similarity index 100% rename from hideout-core/templates/formParams.mustache rename to hideout-mastodon/templates/formParams.mustache diff --git a/hideout-core/templates/generatedAnnotation.mustache b/hideout-mastodon/templates/generatedAnnotation.mustache similarity index 100% rename from hideout-core/templates/generatedAnnotation.mustache rename to hideout-mastodon/templates/generatedAnnotation.mustache diff --git a/hideout-core/templates/headerParams.mustache b/hideout-mastodon/templates/headerParams.mustache similarity index 100% rename from hideout-core/templates/headerParams.mustache rename to hideout-mastodon/templates/headerParams.mustache diff --git a/hideout-core/templates/homeController.mustache b/hideout-mastodon/templates/homeController.mustache similarity index 100% rename from hideout-core/templates/homeController.mustache rename to hideout-mastodon/templates/homeController.mustache diff --git a/hideout-core/templates/interfaceOptVar.mustache b/hideout-mastodon/templates/interfaceOptVar.mustache similarity index 100% rename from hideout-core/templates/interfaceOptVar.mustache rename to hideout-mastodon/templates/interfaceOptVar.mustache diff --git a/hideout-core/templates/interfaceReqVar.mustache b/hideout-mastodon/templates/interfaceReqVar.mustache similarity index 100% rename from hideout-core/templates/interfaceReqVar.mustache rename to hideout-mastodon/templates/interfaceReqVar.mustache diff --git a/hideout-core/templates/libraries/spring-boot/README.mustache b/hideout-mastodon/templates/libraries/spring-boot/README.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/README.mustache rename to hideout-mastodon/templates/libraries/spring-boot/README.mustache diff --git a/hideout-core/templates/libraries/spring-boot/application.mustache b/hideout-mastodon/templates/libraries/spring-boot/application.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/application.mustache rename to hideout-mastodon/templates/libraries/spring-boot/application.mustache diff --git a/hideout-core/templates/libraries/spring-boot/buildGradle-sb3-Kts.mustache b/hideout-mastodon/templates/libraries/spring-boot/buildGradle-sb3-Kts.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/buildGradle-sb3-Kts.mustache rename to hideout-mastodon/templates/libraries/spring-boot/buildGradle-sb3-Kts.mustache diff --git a/hideout-core/templates/libraries/spring-boot/buildGradleKts.mustache b/hideout-mastodon/templates/libraries/spring-boot/buildGradleKts.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/buildGradleKts.mustache rename to hideout-mastodon/templates/libraries/spring-boot/buildGradleKts.mustache diff --git a/hideout-core/templates/libraries/spring-boot/defaultBasePath.mustache b/hideout-mastodon/templates/libraries/spring-boot/defaultBasePath.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/defaultBasePath.mustache rename to hideout-mastodon/templates/libraries/spring-boot/defaultBasePath.mustache diff --git a/hideout-core/templates/libraries/spring-boot/pom-sb3.mustache b/hideout-mastodon/templates/libraries/spring-boot/pom-sb3.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/pom-sb3.mustache rename to hideout-mastodon/templates/libraries/spring-boot/pom-sb3.mustache diff --git a/hideout-core/templates/libraries/spring-boot/pom.mustache b/hideout-mastodon/templates/libraries/spring-boot/pom.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/pom.mustache rename to hideout-mastodon/templates/libraries/spring-boot/pom.mustache diff --git a/hideout-core/templates/libraries/spring-boot/settingsGradle.mustache b/hideout-mastodon/templates/libraries/spring-boot/settingsGradle.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/settingsGradle.mustache rename to hideout-mastodon/templates/libraries/spring-boot/settingsGradle.mustache diff --git a/hideout-core/templates/libraries/spring-boot/springBootApplication.mustache b/hideout-mastodon/templates/libraries/spring-boot/springBootApplication.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/springBootApplication.mustache rename to hideout-mastodon/templates/libraries/spring-boot/springBootApplication.mustache diff --git a/hideout-core/templates/libraries/spring-boot/swagger-ui.mustache b/hideout-mastodon/templates/libraries/spring-boot/swagger-ui.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-boot/swagger-ui.mustache rename to hideout-mastodon/templates/libraries/spring-boot/swagger-ui.mustache diff --git a/hideout-core/templates/libraries/spring-cloud/README.mustache b/hideout-mastodon/templates/libraries/spring-cloud/README.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-cloud/README.mustache rename to hideout-mastodon/templates/libraries/spring-cloud/README.mustache diff --git a/hideout-core/templates/libraries/spring-cloud/apiClient.mustache b/hideout-mastodon/templates/libraries/spring-cloud/apiClient.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-cloud/apiClient.mustache rename to hideout-mastodon/templates/libraries/spring-cloud/apiClient.mustache diff --git a/hideout-core/templates/libraries/spring-cloud/apiKeyRequestInterceptor.mustache b/hideout-mastodon/templates/libraries/spring-cloud/apiKeyRequestInterceptor.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-cloud/apiKeyRequestInterceptor.mustache rename to hideout-mastodon/templates/libraries/spring-cloud/apiKeyRequestInterceptor.mustache diff --git a/hideout-core/templates/libraries/spring-cloud/buildGradle-sb3-Kts.mustache b/hideout-mastodon/templates/libraries/spring-cloud/buildGradle-sb3-Kts.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-cloud/buildGradle-sb3-Kts.mustache rename to hideout-mastodon/templates/libraries/spring-cloud/buildGradle-sb3-Kts.mustache diff --git a/hideout-core/templates/libraries/spring-cloud/buildGradleKts.mustache b/hideout-mastodon/templates/libraries/spring-cloud/buildGradleKts.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-cloud/buildGradleKts.mustache rename to hideout-mastodon/templates/libraries/spring-cloud/buildGradleKts.mustache diff --git a/hideout-core/templates/libraries/spring-cloud/clientConfiguration.mustache b/hideout-mastodon/templates/libraries/spring-cloud/clientConfiguration.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-cloud/clientConfiguration.mustache rename to hideout-mastodon/templates/libraries/spring-cloud/clientConfiguration.mustache diff --git a/hideout-core/templates/libraries/spring-cloud/pom-sb3.mustache b/hideout-mastodon/templates/libraries/spring-cloud/pom-sb3.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-cloud/pom-sb3.mustache rename to hideout-mastodon/templates/libraries/spring-cloud/pom-sb3.mustache diff --git a/hideout-core/templates/libraries/spring-cloud/pom.mustache b/hideout-mastodon/templates/libraries/spring-cloud/pom.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-cloud/pom.mustache rename to hideout-mastodon/templates/libraries/spring-cloud/pom.mustache diff --git a/hideout-core/templates/libraries/spring-cloud/settingsGradle.mustache b/hideout-mastodon/templates/libraries/spring-cloud/settingsGradle.mustache similarity index 100% rename from hideout-core/templates/libraries/spring-cloud/settingsGradle.mustache rename to hideout-mastodon/templates/libraries/spring-cloud/settingsGradle.mustache diff --git a/hideout-core/templates/methodBody.mustache b/hideout-mastodon/templates/methodBody.mustache similarity index 100% rename from hideout-core/templates/methodBody.mustache rename to hideout-mastodon/templates/methodBody.mustache diff --git a/hideout-core/templates/model.mustache b/hideout-mastodon/templates/model.mustache similarity index 100% rename from hideout-core/templates/model.mustache rename to hideout-mastodon/templates/model.mustache diff --git a/hideout-core/templates/modelMutable.mustache b/hideout-mastodon/templates/modelMutable.mustache similarity index 100% rename from hideout-core/templates/modelMutable.mustache rename to hideout-mastodon/templates/modelMutable.mustache diff --git a/hideout-core/templates/openapi.mustache b/hideout-mastodon/templates/openapi.mustache similarity index 100% rename from hideout-core/templates/openapi.mustache rename to hideout-mastodon/templates/openapi.mustache diff --git a/hideout-core/templates/optionalDataType.mustache b/hideout-mastodon/templates/optionalDataType.mustache similarity index 100% rename from hideout-core/templates/optionalDataType.mustache rename to hideout-mastodon/templates/optionalDataType.mustache diff --git a/hideout-core/templates/pathParams.mustache b/hideout-mastodon/templates/pathParams.mustache similarity index 100% rename from hideout-core/templates/pathParams.mustache rename to hideout-mastodon/templates/pathParams.mustache diff --git a/hideout-core/templates/queryParams.mustache b/hideout-mastodon/templates/queryParams.mustache similarity index 100% rename from hideout-core/templates/queryParams.mustache rename to hideout-mastodon/templates/queryParams.mustache diff --git a/hideout-core/templates/returnTypes.mustache b/hideout-mastodon/templates/returnTypes.mustache similarity index 100% rename from hideout-core/templates/returnTypes.mustache rename to hideout-mastodon/templates/returnTypes.mustache diff --git a/hideout-core/templates/returnValue.mustache b/hideout-mastodon/templates/returnValue.mustache similarity index 100% rename from hideout-core/templates/returnValue.mustache rename to hideout-mastodon/templates/returnValue.mustache diff --git a/hideout-core/templates/service.mustache b/hideout-mastodon/templates/service.mustache similarity index 100% rename from hideout-core/templates/service.mustache rename to hideout-mastodon/templates/service.mustache diff --git a/hideout-core/templates/serviceImpl.mustache b/hideout-mastodon/templates/serviceImpl.mustache similarity index 100% rename from hideout-core/templates/serviceImpl.mustache rename to hideout-mastodon/templates/serviceImpl.mustache diff --git a/hideout-core/templates/springdocDocumentationConfig.mustache b/hideout-mastodon/templates/springdocDocumentationConfig.mustache similarity index 100% rename from hideout-core/templates/springdocDocumentationConfig.mustache rename to hideout-mastodon/templates/springdocDocumentationConfig.mustache diff --git a/hideout-core/templates/springfoxDocumentationConfig.mustache b/hideout-mastodon/templates/springfoxDocumentationConfig.mustache similarity index 100% rename from hideout-core/templates/springfoxDocumentationConfig.mustache rename to hideout-mastodon/templates/springfoxDocumentationConfig.mustache diff --git a/hideout-core/templates/typeInfoAnnotation.mustache b/hideout-mastodon/templates/typeInfoAnnotation.mustache similarity index 100% rename from hideout-core/templates/typeInfoAnnotation.mustache rename to hideout-mastodon/templates/typeInfoAnnotation.mustache diff --git a/settings.gradle.kts b/settings.gradle.kts index c2d9aa85..65982597 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,6 +21,7 @@ rootProject.name = "hideout" includeBuild("hideout-core") includeBuild("hideout-worker") +includeBuild("hideout-mastodon") dependencyResolutionManagement { repositories {