Skip to content

Commit

Permalink
test for request body in operations that do not support request body
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-confino committed May 15, 2024
1 parent 8676233 commit 228aa0a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@

import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.SecuritySchemeType;
import org.eclipse.microprofile.openapi.annotations.media.Content;
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.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HEAD;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Response;
Expand All @@ -36,7 +40,30 @@ public class ZepplinResource {
@Operation(summary = "Deprecate outdated airship technology", operationId = "deprecateZepplin")
@Produces("text/plain")
@SecurityRequirement(name = "mutualTLSScheme", scopes = "zepplinScope")
public Response deprecateZepplin() {
public Response deprecateZepplin(@RequestBody(description = "Something about a zepplin.",
content = @Content(mediaType = "application/json")) String string) {
return Response.ok().build();
}

@HEAD
@Path("{id}")
@APIResponse(responseCode = "200", description = "Review deleted")
@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 headZepplin(@RequestBody(ref = "#/paths/~1zepplins~1{id}/delete/requestBody") String string) {
return Response.ok().build();
}

@GET
@Path("{id}")
@APIResponse(responseCode = "200", description = "Review deleted")
@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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ public void testOperationUserResource(String type) {
vr.body("paths.'/user/special'.post.parameters[0].schema", is(nullValue()));
}

@Test(dataProvider = "formatProvider")
public void testOperationZepplinResource(String type) {
ValidatableResponse vr = callEndpoint(type);

vr.body("paths.'/zepplins/{id}'.delete.requestBody.description", equalTo("Something about a zepplin."));
vr.body("paths.'/zepplins/{id}'.head.requestBody.$ref", equalTo("#/paths/~1zepplins~1{id}/delete/requestBody"));
vr.body("paths.'/zepplins/{id}'.get.requestBody.$ref", equalTo("#/paths/~1zepplins~1{id}/delete/requestBody"));

vr.body("paths.'/zepplins/{id}'.delete.requestBody.content", notNullValue());
}

@Test(dataProvider = "formatProvider")
public void testAPIResponse(String type) {
ValidatableResponse vr = callEndpoint(type);
Expand Down

0 comments on commit 228aa0a

Please sign in to comment.