【发布时间】:2022-12-10 06:24:23
【问题描述】:
我有一个用 OpenAPI 描述的 API,它将在 Java/Kotlin 中实现,所以我使用 kotlin-spring generation 进行代码生成,使用 OpenAPI 3.0.2 和插件“org.openapi.generator”版本“ 6.2.1"
我的问题是模式中包含将要上传的文件的字段始终命名为file,而不是尊重我指定的名称attachments,也许这是我不知道的标准,但这是一个已经在使用 attachments 的现有 API,我想保留该名称。
这是模式:
/emails/send:
post:
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/EmailSendResponse'
description: Response from the send email request.
operationId: sendEmail
requestBody:
required: true
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/EmailSendRequest'
和请求模式:
EmailSendRequest:
title: Email send request
description: Contains the data required to send an email.
required:
- success
- failureReason
type: object
properties:
from:
type: string
to:
type: string
subject:
type: string
content:
type: string
contentType:
type: string
enum:
- HTML
- TEXT
bcc:
type: string
tags:
type: array
items:
type: string
category:
type: string
attachments:
type: array
items:
type: string
format: binary
这是在 Java 中生成的 API 方法:
@RequestMapping(
method = [RequestMethod.POST],
value = ["/emails/send"],
produces = ["application/json"],
consumes = ["multipart/form-data"]
)
fun sendEmail(@Parameter(description = "") @RequestParam(value = "from", required = false) from: kotlin.String? ,@Parameter(description = "") @RequestParam(value = "to", required = false) to: kotlin.String? ,@Parameter(description = "") @RequestParam(value = "subject", required = false) subject: kotlin.String? ,@Parameter(description = "") @RequestParam(value = "content", required = false) content: kotlin.String? ,@Parameter(description = "", schema = Schema(allowableValues = ["HTML", "TEXT"])) @RequestParam(value = "contentType", required = false) contentType: kotlin.String? ,@Parameter(description = "") @RequestParam(value = "bcc", required = false) bcc: kotlin.String? ,@Parameter(description = "") @RequestParam(value = "tags", required = false) tags: kotlin.collections.List<kotlin.String>? ,@Parameter(description = "") @RequestParam(value = "category", required = false) category: kotlin.String? ,@Parameter(description = "file detail") @RequestPart("file") attachments: kotlin.collections.List<org.springframework.core.io.Resource>?): ResponseEntity<EmailSendResponse> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
如您所见,它生成的是 @RequestPart("file") 而不是 @RequestPart("attachments")
有什么线索吗?我一直在查看文档,但找不到任何内容。
谢谢!
【问题讨论】:
标签: kotlin openapi openapi-generator