Skip to content

Commit

Permalink
test multipart encoding with new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-confino committed May 31, 2024
1 parent cbf27af commit c67f762
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* Default values include: form, spaceDelimited, pipeDelimited, and deepObject.
* </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,12 +66,39 @@ 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")
@SecurityRequirement(name = "mutualTLSScheme", scopes = "zepplinScope")
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<String> zeeplinUsers) {
return Response.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c67f762

Please sign in to comment.