Repository: springdoc/springdoc-openapi
Pull request #551 (2020-04-08 15:13:07)

Support headers without value (headers = "X-API-VERSION")
Support headers configuration like:
@GetMapping(value = "/student/header3", headers = "X-API-VERSION")


Patch:
diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/MethodAttributes.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/MethodAttributes.java
index f62811291..52dbc0dc1 100644
--- a/springdoc-openapi-common/src/main/java/org/springdoc/core/MethodAttributes.java
+++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/MethodAttributes.java
@@ -147,7 +147,8 @@ public class MethodAttributes {
 		if (ArrayUtils.isNotEmpty(headers))
 			for (String header : headers) {
 				String[] keyValueHeader = header.split("=");
-				this.headers.put(keyValueHeader[0], keyValueHeader[1]);
+				String headerValue = keyValueHeader.length > 1 ? keyValueHeader[1] : "";
+				this.headers.put(keyValueHeader[0], headerValue);
 			}
 	}
 


Test patch:
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app97/HelloController.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app97/HelloController.java
index b97c2e43a..009cac4ab 100644
--- a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app97/HelloController.java
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app97/HelloController.java
@@ -36,4 +36,8 @@ public class HelloController {
 		return new StudentV2("Charlie");
 	}
 
+	@GetMapping(value = "/student/header3", headers = "X-API-VERSION")
+	public StudentV3 headerV3() {
+		return new StudentV3("Tom Charlie");
+	}
 }
diff --git a/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app97/StudentV3.java b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app97/StudentV3.java
new file mode 100644
index 000000000..aa3fc0b21
--- /dev/null
+++ b/springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app97/StudentV3.java
@@ -0,0 +1,13 @@
+package test.org.springdoc.api.app97;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class StudentV3 {
+
+	@JsonProperty("name")
+	private String name;
+
+	public StudentV3(String name) {
+		this.name = name;
+	}
+}
diff --git a/springdoc-openapi-webmvc-core/src/test/resources/results/app97.json b/springdoc-openapi-webmvc-core/src/test/resources/results/app97.json
index 5ebd9e7e5..5061bfb20 100644
--- a/springdoc-openapi-webmvc-core/src/test/resources/results/app97.json
+++ b/springdoc-openapi-webmvc-core/src/test/resources/results/app97.json
@@ -11,6 +11,38 @@
     }
   ],
   "paths": {
+    "/api/student/header3": {
+      "get": {
+        "tags": [
+          "hello-controller"
+        ],
+        "operationId": "headerV3",
+        "parameters": [
+          {
+            "name": "X-API-VERSION",
+            "in": "header",
+            "schema": {
+              "type": "string",
+              "enum": [
+                ""
+              ]
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "default response",
+            "content": {
+              "*/*": {
+                "schema": {
+                  "$ref": "#/components/schemas/StudentV3"
+                }
+              }
+            }
+          }
+        }
+      }
+    },
     "/api/student/header2": {
       "get": {
         "tags": [
@@ -78,6 +110,14 @@
   },
   "components": {
     "schemas": {
+      "StudentV3": {
+        "type": "object",
+        "properties": {
+          "name": {
+            "type": "string"
+          }
+        }
+      },
       "StudentV2": {
         "type": "object",
         "properties": {