Skip to content

Add tests for encoding with multipart/form-data #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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;
Expand Down Expand Up @@ -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<String> zeeplinUsers) {
return Response.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading