Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nexgus opened this issue Apr 25, 2023 · 2 comments
Open

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

nexgus opened this issue Apr 25, 2023 · 2 comments

Comments

@nexgus
Copy link

nexgus commented Apr 25, 2023

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
Copy link

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

@turnarond
Copy link

It does work!! 3q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants