Skip to content

Commit

Permalink
Tests for hidden schemas
Browse files Browse the repository at this point in the history
* Test that a field annotated with @Schema(hidden = true) is not
  included in the schema for the enclosing class
* Test that a resource method parameter annotated with @QueryParam and
  @Schema(hidden = true) creates a parameter with no schema in the
  openapi document
* Test that a resource method parameter annotated with @Schema(hidden =
  true) creates a request body with no schema in the openapi document
  • Loading branch information
Azquelt committed Apr 14, 2022
1 parent f537bfc commit f433d60
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
Expand Up @@ -48,6 +48,9 @@ public class User {
@Schema(required = true, example = "1")
private int status;

@Schema(hidden = true)
private String undocumentedProperty;

/**
* Creates a User instance with the parameters specified.
*
Expand Down Expand Up @@ -279,4 +282,12 @@ public void setUserStatus(int status) {
this.status = status;
}

public String getUndocumentedProperty() {
return undocumentedProperty;
}

public void setUndocumentedProperty(String undocumentedProperty) {
this.undocumentedProperty = undocumentedProperty;
}

}
Expand Up @@ -242,4 +242,17 @@ public Response loginUser(
public Response logoutUser() {
return Response.ok().entity("").build();
}

/**
* Operation to test hiding of request body and parameter schemas
*
* @return a user
*/
@POST
@Path("/special")
public User specialOperation(@Schema(hidden = true) User body,
@Schema(hidden = true) @QueryParam("param1") String param1) {
return body;
}

}
Expand Up @@ -23,11 +23,14 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
Expand Down Expand Up @@ -281,6 +284,10 @@ public void testOperationUserResource(String type) {
equalTo("This changes the password for the logged in user."));
vr.body("paths.'/user/{username}'.patch.operationId", equalTo("changePassword"));
vr.body("paths.'/user/{username}'.patch.parameters", hasSize(3));

// Operation with hidden schemas
vr.body("paths.'/user/special'.post.requestBody.content.'application/json'.schema", is(nullValue()));
vr.body("paths.'/user/special'.post.parameters[0].schema", is(nullValue()));
}

@RunAsClient
Expand Down Expand Up @@ -664,6 +671,7 @@ public void testSchema(String type) {
vr.body("paths.'/user'.post.requestBody.content.'application/json'.schema.maxProperties", equalTo(1024));
vr.body("paths.'/user'.post.requestBody.content.'application/json'.schema.minProperties", equalTo(1));
vr.body("components.schemas.User.required", hasItems("id", "username", "password")); // requiredProperties
vr.body("components.schemas.User", not(hasItem("undocumentedProperty"))); // hidden property
vr.body("components.schemas.Gender.enum", hasItems("Male", "Female", "Other"));

// Array properties
Expand Down
Expand Up @@ -47,7 +47,7 @@ public void testExcludedClass(String type) throws InterruptedException {
vr.body("openapi", startsWith("3.0."));
vr.body("info.title", equalTo("AirlinesRatingApp API"));
vr.body("info.version", equalTo("1.0"));
vr.body("paths.", aMapWithSize(11));
vr.body("paths.", aMapWithSize(12));
vr.body("paths.'/reviews'", nullValue());
vr.body("paths.'/reviews/{id}'", nullValue());
vr.body("paths.'/reviews/users/{user}'", nullValue());
Expand Down
Expand Up @@ -48,7 +48,7 @@ public void testExcludedClasses(String type) throws InterruptedException {
vr.body("info.title", equalTo("AirlinesRatingApp API"));
vr.body("info.version", equalTo("1.0"));

vr.body("paths.", aMapWithSize(10));
vr.body("paths.", aMapWithSize(11));
vr.body("paths.'/reviews'", nullValue());
vr.body("paths.'/reviews/{id}'", nullValue());
vr.body("paths.'/reviews/users/{user}'", nullValue());
Expand Down
Expand Up @@ -47,7 +47,7 @@ public void testExcludePackage(String type) throws InterruptedException {
vr.body("openapi", startsWith("3.0."));
vr.body("info.title", equalTo("AirlinesRatingApp API"));
vr.body("info.version", equalTo("1.0"));
vr.body("paths", aMapWithSize(14));
vr.body("paths", aMapWithSize(15));
vr.body("paths.'/bookings'", nullValue());
vr.body("paths.'/bookings/{id}'", nullValue());

Expand Down

0 comments on commit f433d60

Please sign in to comment.