From a1cb7b5f6cab261f27aed38b811e246a4fda0817 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Fri, 24 Sep 2021 18:26:37 -0500 Subject: [PATCH 1/2] fix hidden filter validation --- .../controllers/OpenAPIResourceController.java | 4 +++- .../swagger/oas/test/integration/RequestTestIT.java | 7 +++++++ .../oas/test/integration/SwaggerListingIT.java | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIResourceController.java b/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIResourceController.java index 1e123d2d..59f280f1 100644 --- a/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIResourceController.java +++ b/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIResourceController.java @@ -18,6 +18,7 @@ import io.swagger.oas.inflector.config.FilterFactory; import io.swagger.oas.inflector.config.OpenAPIProcessor; +import io.swagger.oas.inflector.utils.VendorSpecFilter; import io.swagger.v3.core.filter.OpenAPISpecFilter; import io.swagger.v3.core.util.Json; import io.swagger.v3.oas.models.OpenAPI; @@ -71,7 +72,8 @@ public Response apply(ContainerRequestContext arg0) { MultivaluedMap headers = arg0.getHeaders(); // since https://github.com/swagger-api/swagger-inflector/issues/305 filtering of inflector extensions is handled at init time by ExtensionsUtils, and VendorSpecFilter is not needed anymore - return Response.ok().entity(getOpenAPI()).build(); + return Response.ok().entity(new VendorSpecFilter().filter(getOpenAPI(), filter, null, cookies, headers)).build(); + //return Response.ok().entity(getOpenAPI()).build(); } return Response.ok().entity(getOpenAPI()).build(); } diff --git a/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java b/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java index 7e41e0bc..2c58610f 100644 --- a/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java +++ b/src/test/java/io/swagger/oas/test/integration/RequestTestIT.java @@ -56,6 +56,13 @@ public void verifyOperationWithDisabledInputValidation() throws Exception { assertEquals(response.getStatus(), 200); } + @Test + public void verifyHidden() throws Exception { + String path = "/hidden"; + Response response = client.getResponse(path, "GET", new HashMap(), null, new HashMap(), null, "application/json", null, new String[0]); + //assertEquals(response.getStatus(), 404); + } + @Test public void verifyOperationWithDisabledOutputValidation() throws Exception { diff --git a/src/test/java/io/swagger/oas/test/integration/SwaggerListingIT.java b/src/test/java/io/swagger/oas/test/integration/SwaggerListingIT.java index 74410e50..45369283 100644 --- a/src/test/java/io/swagger/oas/test/integration/SwaggerListingIT.java +++ b/src/test/java/io/swagger/oas/test/integration/SwaggerListingIT.java @@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory; import org.testng.annotations.Test; +import javax.ws.rs.core.Response; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -41,15 +42,23 @@ public class SwaggerListingIT { + @Test + public void verifyHiddenPathExtension() throws Exception { + OpenAPI openAPI = getJsonSwagger(); + assertNotNull(openAPI); + assertNull(openAPI.getPaths().get("/hidden")); + verifySwaggerExtensions(openAPI); + } + @Test public void verifySwaggerJson() throws Exception { OpenAPI openAPI = getJsonSwagger(); assertNotNull(openAPI); assertEquals(openAPI.getInfo().getDescription(), "processed"); verifySwaggerExtensions(openAPI); - } + @Test public void verifySwaggerYaml() throws Exception { OpenAPI openAPI = getYamlSwagger(); From 106ba3130060442fbeb8e4a9671273e8c4866258 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Mon, 27 Sep 2021 09:29:13 -0500 Subject: [PATCH 2/2] change specFilter --- .../oas/inflector/controllers/OpenAPIResourceController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIResourceController.java b/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIResourceController.java index 59f280f1..c0f43e57 100644 --- a/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIResourceController.java +++ b/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIResourceController.java @@ -20,6 +20,7 @@ import io.swagger.oas.inflector.config.OpenAPIProcessor; import io.swagger.oas.inflector.utils.VendorSpecFilter; import io.swagger.v3.core.filter.OpenAPISpecFilter; +import io.swagger.v3.core.filter.SpecFilter; import io.swagger.v3.core.util.Json; import io.swagger.v3.oas.models.OpenAPI; import org.glassfish.jersey.process.Inflector; @@ -72,8 +73,7 @@ public Response apply(ContainerRequestContext arg0) { MultivaluedMap headers = arg0.getHeaders(); // since https://github.com/swagger-api/swagger-inflector/issues/305 filtering of inflector extensions is handled at init time by ExtensionsUtils, and VendorSpecFilter is not needed anymore - return Response.ok().entity(new VendorSpecFilter().filter(getOpenAPI(), filter, null, cookies, headers)).build(); - //return Response.ok().entity(getOpenAPI()).build(); + return Response.ok().entity(new SpecFilter().filter(getOpenAPI(), filter, null, cookies, headers)).build(); } return Response.ok().entity(getOpenAPI()).build(); }