Repository: eclipse/microprofile-open-api
Pull request #278 (2018-09-26 05:36:31)

Define behavior of defaultValue in APIResponses
See issue #271

jmini: TCK Tests are pending.

Patch:
diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/responses/APIResponses.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/responses/APIResponses.java
index f73af89..8784e8d 100644
--- a/api/src/main/java/org/eclipse/microprofile/openapi/models/responses/APIResponses.java
+++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/responses/APIResponses.java
@@ -56,24 +56,41 @@ public interface APIResponses extends Constructible, Extensible<APIResponses>, M
 
     /**
      * Returns the default documentation of responses other than the ones declared for specific HTTP response codes in this instance of ApiResponses.
-     *
+     * <p>
+     * Convenience method that is the same as calling {@link #get(Object)} on the map with {@value #DEFAULT} as value for the key.
+     * 
+     * @deprecated since 1.1, use @link {@link #getDefaultValue()} instead
      * @return the default documentation of responses
      **/
+    @Deprecated 
+    default APIResponse getDefault() {
+        return getDefaultValue();
+    }
 
-    APIResponse getDefault();
+    /**
+     * Returns the default documentation of responses other than the ones declared for specific HTTP response codes in this instance of ApiResponses.
+     * <p>
+     * Convenience method that is the same as calling {@link #get(Object)} on the map with {@value #DEFAULT} as value for the key.
+     * 
+     * @return the default documentation of responses
+     **/
+    APIResponse getDefaultValue();
 
     /**
      * Sets the default documentation of responses for this instance of ApiResponses. This will cover all the undeclared responses.
-     *
+     * <p>
+     * Convenience method that is the same as calling {@link #addAPIResponse(String, APIResponse)} with {@value #DEFAULT} as value for the key.
+     * 
      * @param defaultValue the default documentation of responses
      */
-
     void setDefaultValue(APIResponse defaultValue);
 
     /**
      * Sets the default documentation of responses for this instance of ApiResponses and return this instance of ApiResponses. This will cover all the
      * undeclared responses.
-     *
+     * <p>
+     * Convenience method that is the same as calling {@link #addAPIResponse(String, APIResponse)} with {@value #DEFAULT} as value for the key.
+     * 
      * @param defaultValue the default documentation of responses
      * @return this ApiResponses instance
      */


Test patch:
diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelConstructionTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelConstructionTest.java
index 1e41557..938550b 100644
--- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelConstructionTest.java
+++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/ModelConstructionTest.java
@@ -536,17 +536,38 @@ public class ModelConstructionTest extends Arquillian {
     public void apiResponsesTest() {
         final APIResponses responses = processConstructible(APIResponses.class);
         
-        final String responseKey = "myResponse";
+        responses.remove(APIResponses.DEFAULT);
+        assertEquals(responses.size(), 0, "The map is expected to contain two entries.");
+        
+        final String responseKey = "200";
         final APIResponse responseValue = createConstructibleInstance(APIResponse.class);
         checkSameObject(responses, responses.addAPIResponse(responseKey, responseValue));
         checkMapEntry(responses, responseKey, responseValue);
         
-        final String responseKey2 = "myResponse2";
+        final String responseKey2 = "4XX";
         final APIResponse responseValue2 = createConstructibleInstance(APIResponse.class);
         assertNull(responses.put(responseKey2, responseValue2), "No previous mapping expected.");
         checkMapEntry(responses, responseKey2, responseValue2);
         
         assertEquals(responses.size(), 2, "The map is expected to contain two entries.");
+        
+        assertNull(responses.getDefaultValue(), "No default value expected.");
+        final String responseKey3 = APIResponses.DEFAULT;
+        final APIResponse responseValue3 = createConstructibleInstance(APIResponse.class);
+        assertNull(responses.put(responseKey3, responseValue3), "No previous mapping expected.");
+        checkMapEntry(responses, responseKey3, responseValue3);
+        checkSameObject(responseValue3, responses.getDefaultValue());
+        
+        assertEquals(responses.size(), 3, "The map is expected to contain two entries.");
+        
+        responses.setDefaultValue(null);
+        assertNull(responses.get(APIResponses.DEFAULT), "No default value expected.");
+        assertNull(responses.getDefaultValue(), "No default value expected.");
+        
+        final APIResponse responseValue4 = createConstructibleInstance(APIResponse.class);
+        responses.setDefaultValue(responseValue4);
+        checkMapEntry(responses, APIResponses.DEFAULT, responseValue4);
+        checkSameObject(responseValue4, responses.getDefaultValue());
     }
     
     @Test