-
I've just updated to the latest Quarkus LTS version and now use Can anyone explain in simple terms :-) how to use OpenAPI with this example: https://quarkus.io/guides/rest#multipart With "use" I mean that I want an upload button in Swagger UI for the I see some bugs here, but I haven't managed to use |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
Please note that I'm away for the rest of the week, so please be patient :-) |
Beta Was this translation helpful? Give feedback.
-
@MikeEdgar - can you help ? |
Beta Was this translation helpful? Give feedback.
-
@cristalp , be sure to set |
Beta Was this translation helpful? Give feedback.
-
Ok, so this is what I get in OpenAPI: From @Path("multipart")
public class MultipartResource {
public static class Person {
public String firstName;
public String lastName;
}
@POST
public void multipart(@RestForm final String description,
@RestForm("image") final FileUpload file,
@RestForm @PartType(MediaType.APPLICATION_JSON) final Person person) {
// do something
}
} I get /api/multipart:
post:
tags:
- Multipart Resource
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
description:
type: string
image:
$ref: "#/components/schemas/FileUpload"
person:
$ref: "#/components/schemas/Person"
encoding:
person:
contentType: application/json
responses:
"201":
description: Created I don't get an upload button for Now, for the one with @Path("multipart")
public class MultipartResource {
public static class Person {
public String firstName;
public String lastName;
}
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void multipart(@RestForm final String description,
@RestForm("image") final FileUpload file,
@RestForm @PartType(MediaType.APPLICATION_JSON) final Person person) {
// do something
}
} I get /api/multipart:
post:
tags:
- Multipart Resource
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
description:
type: string
image:
$ref: "#/components/schemas/FileUpload"
person:
$ref: "#/components/schemas/Person"
encoding:
person:
contentType: application/json
responses:
"201":
description: Created There still no upload button for In both cases, FileUpload:
type: object |
Beta Was this translation helpful? Give feedback.
-
I searched around some more and came up with this. Is this the right way to do it? @Path("multipart")
public class MultipartResource {
public static class Person {
public String firstName;
public String lastName;
}
@Schema(type = SchemaType.STRING, format = "binary")
public static class UploadItemSchema {
}
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void multipart(@RestForm final String description,
@RestForm("image") @Schema(implementation = UploadItemSchema.class) final FileUpload file,
@RestForm @PartType(MediaType.APPLICATION_JSON) final Person person) {
System.out.println("description: " + description);
System.out.println("person.firstName: " + person.firstName);
System.out.println("person.lastName: " + person.lastName); //TODO remove System.out
System.out.println("file.fileName: " + file.fileName());
System.out.println("file.contentType: " + file.contentType());
System.out.println("file.size: " + file.size());
}
} In OpenAPI: /api/multipart:
post:
tags:
- Multipart Resource
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
description:
type: string
image:
$ref: "#/components/schemas/UploadItemSchema"
person:
$ref: "#/components/schemas/Person"
encoding:
person:
contentType: application/json
responses:
"201":
description: Created
...
UploadItemSchema:
format: binary
type: string It certainly works, see the output:
|
Beta Was this translation helpful? Give feedback.
Ok, the LTS is using SmallRye 3.10 and the
FileUpload
support came in 3.11. You can continue using the work-around you posted or try using configuration if it is a more widespread issue in your app, to limit the number of changes.