guardrail-dev / guardrail-dev/guardrail
Support multiple content types on single path
- Dominant language
- Scala
- Stars
- 541
- Forks
- 138
- PR merge metrics
- No merged PRs in 30d
Description
Given the following OpenAPI `requestBody` definition for an endpoint:
```yaml
paths:
/reports:
post:
x-jvm-package: reports
summary: Create a new report
operationId: createReport
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- name
- path
properties:
name:
type: string
path:
type: string
multipart/form-data:
schema:
type: object
required:
- name
- file
properties:
name:
type: string
file:
type: string
format: binary
responses:
201:
description: Report created
content:
application/json:
schema:
$ref: "#/components/schemas/Report"
```
This would allow a user to create a report either using `application/json` specifying an existing path, or upload a new file using `multipart/form-data`.
This currently generates the following `ReportsResource` in Dropwizard:
```java
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AsyncTimed(name = "create-report")
public void createReport(@FormParam("friendly_name") final String friendlyName,
@FormParam("file") final java.util.Optional file,
final com.fasterxml.jackson.databind.JsonNode body,
@Suspended final AsyncResponse asyncResponse) {
...
}
```
However, I would expect the following:
```java
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AsyncTimed(name = "create-report")
public void createReportApplicationJson(final com.fasterxml.jackson.databind.JsonNode body,
@Suspended final AsyncResponse asyncResponse) {
...
}
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@AsyncTimed(name = "create-report")
public void createReportMultipartFormData(@FormParam("friendly_name") final String friendlyName,
@FormParam("file") final java.util.Optional file,
@Suspended final AsyncResponse asyncResponse) {
...
}
```
since JAX-RS supports content negotiation around multiple methods using the same path but different content types. Naming is just an example, would need to add a prefix/suffix to the method name.
Contributor guide
Assessment
This issue has not been assessed yet.