From f433d606d6dee9ee02d61e4df1de5f1dd3c526c5 Mon Sep 17 00:00:00 2001 From: Andrew Rouse Date: Thu, 14 Apr 2022 13:56:59 +0100 Subject: [PATCH] Tests for hidden schemas * 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 --- .../openapi/apps/airlines/model/User.java | 11 +++++++++++ .../apps/airlines/resources/UserResource.java | 13 +++++++++++++ .../microprofile/openapi/tck/AirlinesAppTest.java | 8 ++++++++ .../openapi/tck/OASConfigExcludeClassTest.java | 2 +- .../openapi/tck/OASConfigExcludeClassesTest.java | 2 +- .../openapi/tck/OASConfigExcludePackageTest.java | 2 +- 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/model/User.java b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/model/User.java index 82f12456e..7599e41ba 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/model/User.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/model/User.java @@ -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. * @@ -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; + } + } diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/UserResource.java b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/UserResource.java index 146e4e21d..7b1a6beef 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/UserResource.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/airlines/resources/UserResource.java @@ -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; + } + } diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java index 7662f75c7..bc2b64af2 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java @@ -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; @@ -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 @@ -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 diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludeClassTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludeClassTest.java index 44a79901a..b293a25cb 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludeClassTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludeClassTest.java @@ -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()); diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludeClassesTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludeClassesTest.java index 14623e6da..285538837 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludeClassesTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludeClassesTest.java @@ -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()); diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludePackageTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludePackageTest.java index 7e3a21eb2..dd8adffcb 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludePackageTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASConfigExcludePackageTest.java @@ -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());