Skip to content

Commit

Permalink
Merge pull request #622 from benjamin-confino/586-model-with-style-an…
Browse files Browse the repository at this point in the history
…d-type

create a model that uses object and space or pipe delimiters
  • Loading branch information
Azquelt authored Jun 5, 2024
2 parents 27b4cc2 + 1999871 commit cb17fe9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
package org.eclipse.microprofile.openapi.apps.airlines.resources;

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.Schema;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement;
import org.eclipse.microprofile.openapi.annotations.security.SecurityScheme;
Expand All @@ -32,7 +37,6 @@
public class ZepplinResource {

@DELETE
@Path("{id}")
@APIResponse(responseCode = "200", description = "Review deleted")
@APIResponse(responseCode = "404", description = "Review not found")
@Operation(summary = "Deprecate outdated airship technology", operationId = "deprecateZepplin")
Expand All @@ -43,23 +47,27 @@ public Response deprecateZepplin(String string) {
}

@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")
@Parameter(name = "string", description = "something about a string", in = ParameterIn.QUERY,
required = true,
schema = @Schema(type = SchemaType.OBJECT), style = ParameterStyle.SPACEDELIMITED)
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")
@Parameter(name = "string", description = "something about a string", in = ParameterIn.QUERY,
required = true,
schema = @Schema(type = SchemaType.OBJECT), style = ParameterStyle.PIPEDELIMITED)
public Response getZepplin() {
return Response.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ public OpenAPI buildModel() {
.description(
"Indicates that the deletion event was processed successfully")))))
.paths(OASFactory.createObject(Paths.class)
.addPathItem("/zepplins/{id}", OASFactory.createObject(PathItem.class)
.addPathItem("/zepplins", OASFactory.createObject(PathItem.class)
.HEAD(OASFactory.createObject(Operation.class)
.requestBody(OASFactory.createRequestBody()
.ref("#/paths/~1zepplins~1{id}/delete/requestBody")))
.ref("#/paths/~1zepplins/delete/requestBody")))
.GET(OASFactory.createObject(Operation.class)
.requestBody(OASFactory.createRequestBody()
.ref("#/paths/~1zepplins~1{id}/delete/requestBody")))
.ref("#/paths/~1zepplins/delete/requestBody")))
.DELETE(OASFactory.createObject(Operation.class)
.requestBody(OASFactory.createRequestBody()
.description("Something about a zepplin.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,21 @@ public void testParameter(String type) {
testBookingIdMethods(vr);
testReviewIdMethods(vr);
testUserLoginMethods(vr);
testParameterWithObjectAndStyle(vr);
}

private void testParameterWithObjectAndStyle(ValidatableResponse vr) {
String headParameters = "paths.'/zepplins'.head.parameters";
String getParameters = "paths.'/zepplins'.get.parameters";

vr.body(headParameters, hasSize(1));
vr.body(getParameters, hasSize(1));

vr.body(headParameters + "[0].schema.type", equalTo("object"));
vr.body(getParameters + "[0].schema.type", equalTo("object"));

vr.body(headParameters + "[0].style", equalTo("spaceDelimited"));
vr.body(getParameters + "[0].style", equalTo("pipeDelimited"));
}

private void testUserLoginMethods(ValidatableResponse vr) {
Expand Down Expand Up @@ -550,7 +565,7 @@ public void testSecurityRequirement(String type) {
hasEntry(equalTo("userApiKey"), empty()),
hasEntry(equalTo("userBearerHttp"), empty()))));

vr.body("paths.'/zepplins/{id}'.delete.security[0].mutualTLSScheme[0]", equalTo("zepplinScope"));
vr.body("paths.'/zepplins'.delete.security[0].mutualTLSScheme[0]", equalTo("zepplinScope"));
}

@Test(dataProvider = "formatProvider")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ public void testWebhooks(String type) {
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'.delete.requestBody.description", equalTo("Something about a zepplin."));
vr.body("paths.'/zepplins'.head.requestBody.$ref", equalTo("#/paths/~1zepplins/delete/requestBody"));
vr.body("paths.'/zepplins'.get.requestBody.$ref", equalTo("#/paths/~1zepplins/delete/requestBody"));

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

0 comments on commit cb17fe9

Please sign in to comment.