oatpp / oatpp-swagger

OpenApi 3.0.0 docs + Swagger UI for oatpp services
https://oatpp.io/
Apache License 2.0
90 stars 51 forks source link

How To Describe File Type for `multipart/form-data` #79

Open nexgus opened 1 year ago

nexgus commented 1 year ago

I want to design an API, say POST /files. By using this API the user can upload single or multiple files. Its content type must be multipart/form-data. Thanks to oatpp, it functions excellent. Now, I try to use oatpp-swagger to describe this API.

I tried to use the following code but it does not work. In more detail, compile ok but not display the GUI as my imagination :-Q.

ENDPOINT_INFO(uploadMultipart) {
    info->summary = "Upload one or more files.";
    info->addConsumes<oatpp::swagger::Binary>("multipart/form-data");
}

I expect I can see something in Swagger GUI to allow a user to upload one or more files by using multipart/form-data but not.

So, how should I do?

dachongziy commented 5 months ago

I want to design an API, say POST /files. By using this API the user can upload single or multiple files. Its content type must be multipart/form-data. Thanks to oatpp, it functions excellent. Now, I try to use oatpp-swagger to describe this API.

I tried to use the following code but it does not work. In more detail, compile ok but not display the GUI as my imagination :-Q.

ENDPOINT_INFO(uploadMultipart) {
    info->summary = "Upload one or more files.";
    info->addConsumes<oatpp::swagger::Binary>("multipart/form-data");
}

I expect I can see something in Swagger GUI to allow a user to upload one or more files by using multipart/form-data but not.

So, how should I do?

First, you should define MultipartDto as below:

class MultipartDto : public oatpp::DTO {

  DTO_INIT(MultipartDto, DTO)

  DTO_FIELD(oatpp::swagger::Binary, file, "file");
};

then the swagger:

  ENDPOINT_INFO(uploadCodeConfig) {
    info->summary = "Upload and Code Generate";
    info->addConsumes<Object<MultipartDto>>("multipart/form-data");
  }

hope this is helpful to you