Skip to content

Commit

Permalink
Merge pull request #616 from benjamin-confino/591-request-body
Browse files Browse the repository at this point in the history
Test for `requestBody` in Operations which don't support a request body
  • Loading branch information
Azquelt authored May 31, 2024
2 parents 3ba3a3f + b7f400a commit ce4a6a9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
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 +38,29 @@ 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(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() {
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() {
return Response.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,19 @@ public OpenAPI buildModel() {
.description(
"Indicates that the deletion event was processed successfully")))))
.paths(OASFactory.createObject(Paths.class)
.addPathItem("/zepplins/{id}", OASFactory.createObject(PathItem.class)
.HEAD(OASFactory.createObject(Operation.class)
.requestBody(OASFactory.createRequestBody()
.ref("#/paths/~1zepplins~1{id}/delete/requestBody")))
.GET(OASFactory.createObject(Operation.class)
.requestBody(OASFactory.createRequestBody()
.ref("#/paths/~1zepplins~1{id}/delete/requestBody")))
.DELETE(OASFactory.createObject(Operation.class)
.requestBody(OASFactory.createRequestBody()
.description("Something about a zepplin.")
.content(OASFactory.createObject(Content.class)
.addMediaType("mediaType", OASFactory
.createObject(MediaType.class))))))
.addPathItem("/modelReader/airlines", OASFactory.createObject(PathItem.class)
.GET(OASFactory.createObject(Operation.class)
.summary("Retrieve all available airlines")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,15 @@ public void testWebhooks(String type) {
equalTo("Indicates that the deletion event was processed successfully"));

}

@Test(dataProvider = "formatProvider")
public void testRequestBodyInOperations(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());
}
}

0 comments on commit ce4a6a9

Please sign in to comment.