You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The rest client also supports request with mime-type multipart/form-data and, if the schema of the request body is known in advance, we can also automatically generate the models of the request bodies.
281
+
282
+
You need to add the following additional dependency to your `pom.xml`:
For any multipart/form-data operation a model for the request body will be generated. Each part of the multipart is a field in this model that is annotated with the following annotations:
290
+
-`javax.ws.rs.FormParam`, where the value parameter denotes the part name,
291
+
-`org.jboss.resteasy.annotations.providers.multipart.PartType`, where the parameter is the jax-rs MediaType of the part (see below for details),
292
+
- and, if the part contains a file, `org.jboss.resteasy.annotations.providers.multipart.PartFilename`, with a default generate value parameter that will be passed as the fileName sub-header in the Content-Disposition header of the part.
293
+
294
+
For example, the model for a request that requires a file, a string and some complex object will look like this:
295
+
```java
296
+
publicclassMultipartBody {
297
+
298
+
@FormParam("file")
299
+
@PartType(MediaType.APPLICATION_OCTET_STREAM)
300
+
@PartFilename("defaultFileName")
301
+
publicFile file;
302
+
303
+
@FormParam("fileName")
304
+
@PartType(MediaType.TEXT_PLAIN)
305
+
publicString fileName;
306
+
307
+
@FormParam("someObject")
308
+
@PartType(MediaType.APPLICATION_JSON)
309
+
publicMyComplexObject someObject;
310
+
}
311
+
```
312
+
313
+
Then in the client the `org.jboss.resteasy.annotations.providers.multipart.MultipartForm` annotation is added in front of the multipart parameter:
See [Quarkus - Using the REST Client with Multipart](https://quarkus.io/guides/rest-client-multipart) and the [RESTEasy JAX-RS specifications](https://docs.jboss.org/resteasy/docs/4.7.5.Final/userguide/html_single/index.html) for more details.
327
+
328
+
Importantly, if some multipart request bodies contain complex objects (i.e. non-primitives) you need to explicitly tell the Open API generator to create models for these objects by setting the `skip-form-model` property corresponding to your spec in the `application.properties` to `false`, e.g.:
### Default content-types according to OpenAPI Specification and limitations
334
+
The [OAS 3.0](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#special-considerations-for-multipart-content) specifies the following default content-types for a multipart:
335
+
- If the property is a primitive, or an array of primitive values, the default Content-Type is `text/plain`
336
+
- If the property is complex, or an array of complex values, the default Content-Type is `application/json`
337
+
- If the property is a `type: string` with `format: binary` or `format: base64` (aka a file object), the default Content-Type is `application/octet-stream`
338
+
339
+
A different content-type may be defined in your api spec, but this is not yet supported in the code generation. Also, this "annotation-oriented" approach of RestEasy (i.e. using `@MultipartForm` to denote the multipart body parameter) does not seem to properly support the unmarshalling of arrays of the same type (e.g. array of files), in these cases it uses Content-Type equal to `application/json`.
340
+
341
+
279
342
## Generating files via InputStream
280
343
281
344
Having the files in the `src/main/openapi` directory will generate the REST stubs by default. Alternatively, you can implement the `io.quarkiverse.openapi.generator.codegen.OpenApiSpecInputProvider`
0 commit comments