From c67f7627873b0dce25b04e9fefe5a47addadfc79 Mon Sep 17 00:00:00 2001 From: Benjamin Confino Date: Wed, 29 May 2024 21:29:02 +0100 Subject: [PATCH] test multipart encoding with new fields --- .../openapi/annotations/media/Encoding.java | 3 +- .../airlines/resources/ZepplinResource.java | 37 ++++++++++++++++++- .../openapi/tck/AirlinesAppTest.java | 14 +++++++ 3 files changed, 52 insertions(+), 2 deletions(-) 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 7601a550..810a246f 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,17 +13,25 @@ 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.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.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 org.eclipse.microprofile.openapi.apps.airlines.model.User; +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; @@ -58,7 +66,9 @@ public Response headZepplin(@RequestBody(ref = "#/paths/~1zepplins~1{id}/delete/ @GET @Path("{id}") - @APIResponse(responseCode = "200", description = "Review deleted") + @APIResponse(responseCode = "200", description = "Review deleted", + content = @Content(encoding = @Encoding(name = "enigma", style = "pipeDelimited", explode = true, + allowReserved = true, contentType = "multipart/form-data"))) @APIResponse(responseCode = "404", description = "Review not found") @Operation(summary = "Deprecate outdated airship technology", operationId = "deprecateZepplin") @Produces("text/plain") @@ -66,4 +76,29 @@ public Response headZepplin(@RequestBody(ref = "#/paths/~1zepplins~1{id}/delete/ public Response getZepplin(@RequestBody(ref = "#/paths/~1zepplins~1{id}/delete/requestBody") String string) { return Response.ok().build(); } + + @POST + @Path("{id}") + @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 = "application/json", + schema = @Schema(name = "testUser", type = SchemaType.OBJECT, + maxProperties = 1024, minProperties = 1, required = true, + implementation = User.class), + 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 dd525850..08e83541 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 @@ -679,6 +679,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/{id}'.post.requestBody.content.'application/json'.encoding.allergies"; + String specialRequestsEncoding = + "paths.'/zepplins/{id}'.post.requestBody.content.'application/json'.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")