Repository: eclipse/microprofile-open-api (java)

Issue:
Several TCK test cases require header `style` set to default value `simple`
There are several TCK test cases that require a header's `style` value is set to `simple`, which is the OAS default for headers [1]. Given that it is the default and is even omitted from the OAS spec examples, it appears this check should be removed from these tests.

A few examples:
- [org.eclipse.microprofile.openapi.tck.FilterTest.testFilterHeader(String)](https://github.com/eclipse/microprofile-open-api/blob/112b7b16806982223d638f415d2979beaf89f6a8/tck/src/main/java/org/eclipse/microprofile/openapi/tck/FilterTest.java#L164)
- [org.eclipse.microprofile.openapi.tck.AirlinesAppTest.testHeaderInAPIResponse(String)](https://github.com/eclipse/microprofile-open-api/blob/112b7b16806982223d638f415d2979beaf89f6a8/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java#L933)
- [org.eclipse.microprofile.openapi.tck.AirlinesAppTest.testHeaderInComponents(String)](https://github.com/eclipse/microprofile-open-api/blob/112b7b16806982223d638f415d2979beaf89f6a8/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java#L991)
- [org.eclipse.microprofile.openapi.tck.AirlinesAppTest.testHeaderInEncoding(String)](https://github.com/eclipse/microprofile-open-api/blob/112b7b16806982223d638f415d2979beaf89f6a8/tck/src/main/java/org/eclipse/microprofile/openapi/tck/AirlinesAppTest.java#L958)

[1] https://spec.openapis.org/oas/v3.0.3.html#parameterStyle


Pull request description:
Relax assertions for default header, request body, and response styles
Fixes #661 

Patch:
diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/utils/TCKMatchers.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/utils/TCKMatchers.java
index 61e1207..977aee3 100644
--- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/utils/TCKMatchers.java
+++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/utils/TCKMatchers.java
@@ -15,7 +15,13 @@
  */
 package org.eclipse.microprofile.openapi.tck.utils;
 
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.either;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.isA;
+import static org.hamcrest.Matchers.not;
 import static org.hamcrest.comparator.ComparatorMatcherBuilder.comparedBy;
 
 import java.math.BigDecimal;
@@ -169,4 +175,21 @@ public final class TCKMatchers {
         }
 
     }
+
+    /**
+     * Creates a matcher which matches a map entry with an allowed value or the absence of a map entry from the object.
+     *
+     * @param entryName
+     *            name of the entry in the map
+     * @param value
+     *            a single allowed value in the map entry, if present
+     * @return the matcher
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> Matcher<T> hasOptionalEntry(String entryName, Object value) {
+        Matcher<T> hasEntry = (Matcher<T>) hasEntry(entryName, value);
+        Matcher<T> entryMissing = (Matcher<T>) not(hasKey(entryName));
+
+        return allOf(isA(java.util.Map.class), either(hasEntry).or(entryMissing));
+    }
 }


Test patch:
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 db57d16..a01a280 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
@@ -16,6 +16,7 @@
 
 package org.eclipse.microprofile.openapi.tck;
 
+import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.hasOptionalEntry;
 import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.itemOrSingleton;
 import static org.hamcrest.Matchers.allOf;
 import static org.hamcrest.Matchers.anEmptyMap;
@@ -408,8 +409,7 @@ public class AirlinesAppTest extends AppTestBase {
         }
 
         bookingParameters = "paths.'/bookings/{id}'.get.parameters";
-        vr.body(bookingParameters + ".findAll { it.name == 'id' }.style", both(hasSize(1)).and(contains("simple")));
-
+        vr.body(bookingParameters + ".findAll { it.name == 'id' }", contains(hasOptionalEntry("style", "simple")));
     }
 
     private void testAvailabilityGetParamater(ValidatableResponse vr) {
@@ -690,7 +690,7 @@ public class AirlinesAppTest extends AppTestBase {
         ValidatableResponse vr = callEndpoint(type);
         String s = "paths.'/user'.post.requestBody.content.'application/json'.encoding.email.";
         vr.body(s + "contentType", equalTo("text/plain"));
-        vr.body(s + "style", equalTo("form"));
+        vr.body(s, hasOptionalEntry("style", "form"));
         vr.body(s + "explode", equalTo(true));
         vr.body(s + "allowReserved", equalTo(true));
         vr.body(s + "x-encoding", equalTo("test-encoding"));
@@ -702,13 +702,13 @@ public class AirlinesAppTest extends AppTestBase {
         String s =
                 "paths.'/user/username/{username}'.put.responses.'200'.content.'application/json'.encoding.password.";
         vr.body(s + "contentType", equalTo("text/plain"));
-        vr.body(s + "style", equalTo("form"));
+        vr.body(s, hasOptionalEntry("style", "form"));
         vr.body(s + "explode", equalTo(true));
         vr.body(s + "allowReserved", equalTo(true));
 
         String t = "paths.'/user/username/{username}'.put.responses.'200'.content.'application/xml'.encoding.password.";
         vr.body(t + "contentType", equalTo("text/plain"));
-        vr.body(t + "style", equalTo("form"));
+        vr.body(t, hasOptionalEntry("style", "form"));
         vr.body(t + "explode", equalTo(true));
         vr.body(t + "allowReserved", equalTo(true));
 
@@ -930,7 +930,7 @@ public class AirlinesAppTest extends AppTestBase {
         vr.body(responseHeader1 + ".required", equalTo(true));
         vr.body(responseHeader1 + ".deprecated", equalTo(true));
         vr.body(responseHeader1 + ".allowEmptyValue", equalTo(true));
-        vr.body(responseHeader1 + ".style", equalTo("simple"));
+        vr.body(responseHeader1, hasOptionalEntry("style", "simple"));
         vr.body(responseHeader1 + ".schema.type", itemOrSingleton("integer"));
 
         String responseHeader2 = "paths.'/reviews/{id}'.get.responses.'200'.headers.responseHeader2";
@@ -939,7 +939,7 @@ public class AirlinesAppTest extends AppTestBase {
         vr.body(responseHeader2 + ".required", equalTo(true));
         vr.body(responseHeader2 + ".deprecated", equalTo(true));
         vr.body(responseHeader2 + ".allowEmptyValue", equalTo(true));
-        vr.body(responseHeader2 + ".style", equalTo("simple"));
+        vr.body(responseHeader2, hasOptionalEntry("style", "simple"));
         vr.body(responseHeader2 + ".schema.type", itemOrSingleton("string"));
     }
 
@@ -955,7 +955,7 @@ public class AirlinesAppTest extends AppTestBase {
         vr.body(testHeader + ".required", equalTo(true));
         vr.body(testHeader + ".deprecated", equalTo(true));
         vr.body(testHeader + ".allowEmptyValue", equalTo(true));
-        vr.body(testHeader + ".style", equalTo("simple"));
+        vr.body(testHeader, hasOptionalEntry("style", "simple"));
         vr.body(testHeader + ".schema.type", itemOrSingleton("integer"));
     }
 
@@ -988,7 +988,7 @@ public class AirlinesAppTest extends AppTestBase {
         vr.body(maxRate + ".required", equalTo(true));
         vr.body(maxRate + ".deprecated", equalTo(true));
         vr.body(maxRate + ".allowEmptyValue", equalTo(true));
-        vr.body(maxRate + ".style", equalTo("simple"));
+        vr.body(maxRate, hasOptionalEntry("style", "simple"));
         vr.body(maxRate + ".schema.type", itemOrSingleton("integer"));
         vr.body(maxRate + ".x-header", equalTo("test-header"));
     }
diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/FilterTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/FilterTest.java
index 70d11bd..2c3c250 100644
--- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/FilterTest.java
+++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/FilterTest.java
@@ -16,6 +16,7 @@
 
 package org.eclipse.microprofile.openapi.tck;
 
+import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.hasOptionalEntry;
 import static org.eclipse.microprofile.openapi.tck.utils.TCKMatchers.itemOrSingleton;
 import static org.hamcrest.Matchers.both;
 import static org.hamcrest.Matchers.contains;
@@ -161,7 +162,7 @@ public class FilterTest extends AppTestBase {
         vr.body(maxRate + ".required", equalTo(true));
         vr.body(maxRate + ".deprecated", equalTo(true));
         vr.body(maxRate + ".allowEmptyValue", equalTo(true));
-        vr.body(maxRate + ".style", equalTo("simple"));
+        vr.body(maxRate, hasOptionalEntry("style", "simple"));
         vr.body(maxRate + ".schema.type", itemOrSingleton("integer"));
     }