Skip to content

Commit

Permalink
feat: manually specify sealed class Request parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiinaKin committed Oct 12, 2024
1 parent bb1e6d7 commit 82891b5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {
implementation("io.ktor:ktor-server-default-headers-jvm")
implementation("io.ktor:ktor-server-forwarded-header-jvm")

implementation("io.swagger.parser.v3:swagger-parser:2.1.21")
implementation("io.github.smiley4:ktor-swagger-ui:3.5.0")

implementation("com.ucasoft.ktor:ktor-simple-cache-jvm:$ktorSimpleCacheVersion")
Expand Down
66 changes: 59 additions & 7 deletions app/src/main/kotlin/io/sakurasou/controller/StrategyController.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.sakurasou.controller

import io.github.smiley4.ktorswaggerui.dsl.routing.delete
import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.patch
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.route
import io.github.smiley4.ktorswaggerui.dsl.routing.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
Expand All @@ -23,8 +19,12 @@ import io.sakurasou.controller.vo.StrategyVO
import io.sakurasou.extension.id
import io.sakurasou.extension.pageRequest
import io.sakurasou.extension.success
import io.sakurasou.model.strategy.LocalStrategy
import io.sakurasou.model.strategy.S3Strategy
import io.sakurasou.model.strategy.StrategyConfig
import io.sakurasou.plugins.AuthorizationPlugin
import io.sakurasou.service.strategy.StrategyService
import io.swagger.v3.oas.models.media.Schema

/**
* @author Shiina Kin
Expand Down Expand Up @@ -68,8 +68,60 @@ private fun Route.insertStrategy(controller: StrategyController) {
post({
protected = true
request {
body<StrategyInsertRequest> {
description = "strategy request"
body(Schema<StrategyInsertRequest>().apply {
addProperty("config", Schema<StrategyConfig>().apply {
description = "io/sakurasou/model/strategy/StrategyConfig.kt"
oneOf(
listOf(
Schema<LocalStrategy>().apply {
description = "Local strategy configuration"
addProperty("uploadFolder", Schema<Any>().apply {
type = "string"
})
addProperty("strategyType", Schema<Any>().apply {
type = "string"
})
addProperty("type", Schema<Any>().apply {
type = "string"
description = "same to strategyType"
})
},
Schema<S3Strategy>().apply {
description = "S3 strategy configuration"
addProperty("endpoint", Schema<Any>().apply {
type = "string"
})
addProperty("bucketName", Schema<Any>().apply {
type = "string"
})
addProperty("region", Schema<Any>().apply {
type = "string"
})
addProperty("accessKey", Schema<Any>().apply {
type = "string"
})
addProperty("secretKey", Schema<Any>().apply {
type = "string"
})
addProperty("publicUrl", Schema<Any>().apply {
type = "string"
})
addProperty("strategyType", Schema<Any>().apply {
type = "string"
})
addProperty("type", Schema<Any>().apply {
type = "string"
description = "same to strategyType"
})
}
)
)
})
addProperty("name", Schema<Any>().apply {
type = "string"
})
}) {
description = "`config` need a extra field `type`, same to strategyType"
required = true
}
}
Expand Down

0 comments on commit 82891b5

Please sign in to comment.