diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/annotations/media/Encoding.java b/api/src/main/java/org/eclipse/microprofile/openapi/annotations/media/Encoding.java index 7d5dd78d..f23e1ffe 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/annotations/media/Encoding.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/annotations/media/Encoding.java @@ -58,7 +58,8 @@ /** * Style describes how the encoding value will be serialized depending on the type of the parameter value. This - * property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded. + * property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded or + * multipart/form-data. *

* Default values include: form, spaceDelimited, pipeDelimited, and deepObject. *

diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/ZepplinResource.java b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/ZepplinResource.java index 8c1afc72..fa2a47df 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/ZepplinResource.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/ZepplinResource.java @@ -13,20 +13,28 @@ package org.eclipse.microprofile.openapi.apps.airlines.resources; +import java.util.List; + import org.eclipse.microprofile.openapi.annotations.Operation; import org.eclipse.microprofile.openapi.annotations.enums.ParameterIn; import org.eclipse.microprofile.openapi.annotations.enums.ParameterStyle; import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Encoding; import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.media.SchemaProperty; import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; +import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement; import org.eclipse.microprofile.openapi.annotations.security.SecurityScheme; +import jakarta.ws.rs.Consumes; import jakarta.ws.rs.DELETE; import jakarta.ws.rs.GET; import jakarta.ws.rs.HEAD; +import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.Response; @@ -71,4 +79,35 @@ public Response headZepplin() { public Response getZepplin() { return Response.ok().build(); } + + @POST + @APIResponse(responseCode = "200", description = "Review posted") + @APIResponse(responseCode = "404", description = "Review not found") + @Operation(summary = "Post by Zepplin", operationId = "postZepplin") + @Produces("text/plain") + @SecurityRequirement(name = "mutualTLSScheme", scopes = "zepplinScope") + @Consumes("multipart/form-data") + public Response postZepplin( + @RequestBody(description = "Record of a new user to be created in the system.", required = true, + content = @Content(mediaType = "multipart/form-data", + schema = @Schema(properties = { + @SchemaProperty(name = "passenger", description = "the passanger", + type = SchemaType.STRING), + @SchemaProperty(name = "allergies", + description = "Does the passenger have any allergies", + type = SchemaType.ARRAY), + @SchemaProperty(name = "specialRequests", + description = "Does the passenger have any special requests", + type = SchemaType.OBJECT) + }), + encoding = { + @Encoding(name = "allergies", + allowReserved = true, explode = true, + style = "pipeDelimited"), + @Encoding(name = "specialRequests", + allowReserved = true, explode = true, + style = "spaceDelimited") + })) List zeeplinUsers) { + return Response.ok().build(); + } } diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java index 8f5092bc..db57d16a 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java @@ -711,6 +711,20 @@ public void testEncodingResponses(String type) { vr.body(t + "style", equalTo("form")); vr.body(t + "explode", equalTo(true)); vr.body(t + "allowReserved", equalTo(true)); + + // Test style, explode and allowReserved when @Consumes is "multipart/form-data" + String allergiesEncoding = + "paths.'/zepplins'.post.requestBody.content.'multipart/form-data'.encoding.allergies"; + String specialRequestsEncoding = + "paths.'/zepplins'.post.requestBody.content.'multipart/form-data'.encoding.specialRequests"; + + vr.body(allergiesEncoding + ".style", equalTo("pipeDelimited")); + vr.body(allergiesEncoding + ".explode", equalTo(true)); + vr.body(allergiesEncoding + ".allowReserved", equalTo(true)); + + vr.body(specialRequestsEncoding + ".style", equalTo("spaceDelimited")); + vr.body(specialRequestsEncoding + ".explode", equalTo(true)); + vr.body(specialRequestsEncoding + ".allowReserved", equalTo(true)); } @Test(dataProvider = "formatProvider")