【发布时间】:2021-03-16 08:07:29
【问题描述】:
我有使用 kotlin ('1.3.50') 编写的 springboot(2.11.RELEASE) webflux 应用程序。我想添加招摇文档。我添加到我的 build.gradle:
compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
我的 Rest 控制器如下所示:
@RestController
@RequestMapping("/path", produces = [MediaType.APPLICATION_JSON_VALUE])
@Validated
class CreditApplicationController @Autowired constructor(
private val creditService: CreditService
) {
@PostMapping(consumes = [MediaType.APPLICATION_JSON_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE])
fun applyCredit(
@Valid @RequestBody request: ApplyCreditRequest,
@OperationId operationId: String
): Mono<ResponseEntity<ApplicationCreditResponse>> {
...
ApplyCreditRequest 是一个简单的 kotlin 数据类
@Validated
data class ApplyCreditRequest(
@get:JsonProperty("application_id", required = true)
@NotBlank(message = "application_id cannot be empty")
val applicationId: String,
@get:JsonProperty("customer_info", required = true)
@field:Valid
val customerInfo: CustomerInfo,
@get:JsonProperty("credit_details", required = true)
@field:Valid
val creditDetails: CreditDetails,
@get:JsonProperty("agent", required = true)
@Valid
val agent: Agent
)
但是,当我转到 swagger 生成的页面时,请求正文显示为字符串。如何让它显示为 ApplyCreditRequest json 我希望它是?
更新:
更新到:
@PostMapping(consumes = [MediaType.APPLICATION_JSON_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE])
fun applyCredit(
@io.swagger.v3.oas.annotations.parameters.RequestBody(
content = [
Content(
schema = Schema(
implementation = ApplyCreditRequest::class
)
)
]
) @Valid @RequestBody request: ApplyCreditRequest,
@OperationId operationId: String
): Mono<ResponseEntity<ApplicationCreditResponse>> {
还是不行
【问题讨论】:
-
尝试使用
@RequestBody(content = @Content(schema = @Schema(implementation = ApplyCreditRequest.class))) -
@DebarghaRoy 仍然不起作用;c
-
抱歉,错过了您使用 Springfox 的事实。我上面分享的内容适用于 Springdoc。
-
您的问题解决了吗?
-
很遗憾,不,我必须创建自己的 swagger.yml 并托管它 - songrgg.github.io/operation/…
标签: spring-boot swagger swagger-ui swagger-2.0 springfox