Skip to content

Add documentation about file upload for springdoc 2 #81

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

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/docs/asciidoc/faq.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,35 @@ public OpenApiCustomizer customerGlobalHeaderOpenApiCustomizer() {

=== Is file upload supported ?
* The library supports the main file types: `MultipartFile`, `@RequestPart`, `FilePart`
* You can upload a file as follows:

[source,java]
----
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Encoding;
import io.swagger.v3.oas.annotations.parameters.RequestBody;

@PostMapping(value = "/upload", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<?> upload(@Parameter(description = "file") final MultipartFile file) {
return null;
}

@PostMapping(value = "/uploadFileWithQuery", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<?> uploadFileWithQuery(@Parameter(description = "file") @RequestPart("file") final MultipartFile file,
@Parameter(description = "An extra query parameter") @RequestParam String name) {
return null;
}

@PostMapping(value = "/uploadFileWithJson", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}, produces = {
MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> uploadFileWithJson(
@RequestBody(content = @Content(encoding = @Encoding(name = "jsonRequest", contentType = MediaType.APPLICATION_JSON_VALUE)))
@Parameter(description = "An extra JSON payload sent with file") @RequestPart("jsonRequest") final JsonRequest jsonRequest,
@RequestPart("file") final MultipartFile file) {
return null;
}
----

=== Can I use `@Parameter` inside `@Operation` annotation?
* Yes, it's supported
Expand Down