Repository: springdoc/springdoc-openapi
Pull request #255 (2019-12-11 15:13:21)

Added ability to ignore param with @Hidden annotation at class level


Patch:
diff --git a/springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/RequestBuilder.java b/springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/RequestBuilder.java
index c11896ed4..b7e2fe527 100644
--- a/springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/RequestBuilder.java
+++ b/springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/RequestBuilder.java
@@ -1,6 +1,8 @@
 package org.springdoc.core;
 
+import io.swagger.v3.oas.annotations.Hidden;
 import io.swagger.v3.oas.models.Operation;
+import org.springframework.core.annotation.AnnotationUtils;
 import org.springframework.http.HttpMethod;
 import org.springframework.stereotype.Component;
 import org.springframework.validation.BindingResult;
@@ -36,7 +38,8 @@ public class RequestBuilder extends AbstractRequestBuilder {
                 || org.springframework.ui.Model.class.equals(paramType)
                 || org.springframework.ui.ModelMap.class.equals(paramType) || RedirectAttributes.class.equals(paramType)
                 || Errors.class.equals(paramType) || BindingResult.class.equals(paramType)
-                || SessionStatus.class.equals(paramType) || UriComponentsBuilder.class.equals(paramType);
+                || SessionStatus.class.equals(paramType) || UriComponentsBuilder.class.equals(paramType)
+                || (AnnotationUtils.findAnnotation(paramType, Hidden.class) != null);
     }
 
     @Override


Test patch:
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/HelloController.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/HelloController.java
new file mode 100644
index 000000000..86ebe1027
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/HelloController.java
@@ -0,0 +1,20 @@
+package test.org.springdoc.api.app66;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Tag(name = "Health" , description = "Health check / ping API")
+@RestController
+public class HelloController {
+
+    @Operation(summary = "Check server status", description = "Check server status, will return 200 with simple string if alive. Do nothing else.")
+    @GetMapping(value = { "/ping", "/health", "/" }, produces = MediaType.TEXT_PLAIN_VALUE)
+    public ResponseEntity<String> ping(UndocumentedClass possiblyInjectedByAspect) {
+        return ResponseEntity.ok("Healthy");
+    }
+
+}
\ No newline at end of file
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/SpringDocApp66Test.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/SpringDocApp66Test.java
new file mode 100644
index 000000000..0eff48526
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/SpringDocApp66Test.java
@@ -0,0 +1,7 @@
+package test.org.springdoc.api.app66;
+
+import test.org.springdoc.api.AbstractSpringDocTest;
+
+public class SpringDocApp66Test extends AbstractSpringDocTest {
+
+}
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/SpringDocTestApp.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/SpringDocTestApp.java
new file mode 100644
index 000000000..d26103daf
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/SpringDocTestApp.java
@@ -0,0 +1,12 @@
+package test.org.springdoc.api.app66;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringDocTestApp {
+
+    public static void main(String[] args) {
+        SpringApplication.run(SpringDocTestApp.class, args);
+    }
+}
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/UndocumentedClass.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/UndocumentedClass.java
new file mode 100644
index 000000000..2e7b18ff9
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app66/UndocumentedClass.java
@@ -0,0 +1,8 @@
+package test.org.springdoc.api.app66;
+
+import io.swagger.v3.oas.annotations.Hidden;
+
+@Hidden
+public class UndocumentedClass {
+
+}
diff --git a/springdoc-openapi-webmvc-core/src/test/resources/results/app66.json b/springdoc-openapi-webmvc-core/src/test/resources/results/app66.json
new file mode 100644
index 000000000..f06cabb6e
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/resources/results/app66.json
@@ -0,0 +1,88 @@
+{
+  "openapi": "3.0.1",
+  "info": {
+    "title": "OpenAPI definition",
+    "version": "v0"
+  },
+  "servers": [
+    {
+      "url": "http://localhost",
+      "description": "Generated server url"
+    }
+  ],
+  "tags": [
+    {
+      "name": "Health",
+      "description": "Health check / ping API"
+    }
+  ],
+  "paths": {
+    "/ping": {
+      "get": {
+        "tags": [
+          "Health"
+        ],
+        "summary": "Check server status",
+        "description": "Check server status, will return 200 with simple string if alive. Do nothing else.",
+        "operationId": "ping",
+        "responses": {
+          "200": {
+            "description": "default response",
+            "content": {
+              "text/plain": {
+                "schema": {
+                  "type": "string"
+                }
+              }
+            }
+          }
+        }
+      }
+    },
+    "/health": {
+      "get": {
+        "tags": [
+          "Health"
+        ],
+        "summary": "Check server status",
+        "description": "Check server status, will return 200 with simple string if alive. Do nothing else.",
+        "operationId": "ping_1",
+        "responses": {
+          "200": {
+            "description": "default response",
+            "content": {
+              "text/plain": {
+                "schema": {
+                  "type": "string"
+                }
+              }
+            }
+          }
+        }
+      }
+    },
+    "/": {
+      "get": {
+        "tags": [
+          "Health"
+        ],
+        "summary": "Check server status",
+        "description": "Check server status, will return 200 with simple string if alive. Do nothing else.",
+        "operationId": "ping_2",
+        "responses": {
+          "200": {
+            "description": "default response",
+            "content": {
+              "text/plain": {
+                "schema": {
+                  "type": "string"
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  },
+  "components": {}
+}
\ No newline at end of file