【发布时间】:2020-09-02 13:33:18
【问题描述】:
我正在尝试使用 Vert.x Web API Contract 使用 OpenAPI 操作定义定义服务接口,在 Rest API 中上传包含其他相关数据的文件,如下所示:-
/api/pets/{petId}/uploadImage:
post:
summary: upload file for pet
operationId: savePetPicture
x-vertx-event-bus: "petstore_manager.myapp"
parameters:
- name: petId
in: path
required: true
description: The id of the pet
schema:
type: string
requestBody:
description: image to be used as pet picture
content:
multipart/form-data:
schema:
type: object
properties:
profileImage:
type: string
format: binary
name:
type: string
我有一个服务接口 PetStoreManagerService,我在其中定义了处理该资源操作的方法。
@WebApiServiceGen
public interface PetStoreManagerService {
void savePetPicture(PetImage body, String petId, OperationRequest operationRequest,
Handler<AsyncResult<OperationResponse>> handler);
}
Model类定义如下
@DataObject(generateConverter = true, publicConverter = false)
public class PetImage {
String name;
Buffer profileImage;
}
我在我的项目中遵循了本教程。 vertx-web-api-service tutorial 我的问题是这个 PetImage 类中 profileImage 的类型应该是什么?我的服务实现类中的 requestBody 为空。
我发现一些帖子在 MainVerticle 类中处理操作
routerFactory.addHandlerByOperationId("savePetPicture", routingContext -> {
Set<FileUpload> fileUploadSet = routingContext.fileUploads();
Iterator<FileUpload> fileUploadIterator = fileUploadSet.iterator();
// ...
我想知道这是否可以在服务类中处理,将请求路由到 PetStoreManagerService 实现类,如教程中所示。
【问题讨论】: