GERONIMO-6689 serialize default response as any response
authorRomain Manni-Bucau <rmannibucau@gmail.com>
Mon, 21 Jan 2019 13:57:57 +0000 (14:57 +0100)
committerRomain Manni-Bucau <rmannibucau@gmail.com>
Mon, 21 Jan 2019 13:57:57 +0000 (14:57 +0100)
geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/model/APIResponsesImpl.java
geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/impl/serialization/SerializationTest.java [new file with mode: 0644]

index ea13e42..6c65ea2 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.geronimo.microprofile.openapi.impl.model;
 import java.util.LinkedHashMap;
 
 import javax.enterprise.inject.Vetoed;
-import javax.json.bind.annotation.JsonbProperty;
+import javax.json.bind.annotation.JsonbTransient;
 
 import org.eclipse.microprofile.openapi.models.responses.APIResponse;
 import org.eclipse.microprofile.openapi.models.responses.APIResponses;
@@ -27,8 +27,6 @@ import org.eclipse.microprofile.openapi.models.responses.APIResponses;
 @Vetoed
 public class APIResponsesImpl extends LinkedHashMap<String, APIResponse> implements APIResponses {
 
-    private APIResponse _default;
-
     public APIResponses addAPIResponse(final String name, final APIResponse item) {
         return addApiResponse(name, item);
     }
@@ -40,15 +38,14 @@ public class APIResponsesImpl extends LinkedHashMap<String, APIResponse> impleme
     }
 
     @Override
-    @JsonbProperty("default")
+    @JsonbTransient
     public APIResponse getDefault() {
-        return _default;
+        return get("default");
     }
 
     @Override
-    @JsonbProperty("default")
     public void setDefaultValue(final APIResponse _defaultValue) {
-        this._default = _defaultValue;
+        addApiResponse("default", _defaultValue);
     }
 
     @Override
diff --git a/geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/impl/serialization/SerializationTest.java b/geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/impl/serialization/SerializationTest.java
new file mode 100644 (file)
index 0000000..408e12b
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.microprofile.openapi.impl.serialization;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.json.bind.Jsonb;
+import javax.json.bind.JsonbBuilder;
+
+import org.apache.geronimo.microprofile.openapi.impl.loader.yaml.Yaml;
+import org.apache.geronimo.microprofile.openapi.impl.model.APIResponseImpl;
+import org.apache.geronimo.microprofile.openapi.impl.model.APIResponsesImpl;
+import org.eclipse.microprofile.openapi.models.responses.APIResponses;
+import org.testng.annotations.Test;
+
+public class SerializationTest {
+    @Test
+    public void defaultResponse() throws Exception {
+        final APIResponses responses = new APIResponsesImpl()
+                .defaultValue(new APIResponseImpl().description("test"))
+                .addApiResponse("200", new APIResponseImpl().description("ok"));
+        try (final Jsonb jsonb = JsonbBuilder.create()) {
+            assertEquals("{\"default\":{\"description\":\"test\"},\"200\":{\"description\":\"ok\"}}", jsonb.toJson(responses));
+        }
+        assertEquals("---\ndefault:\n  description: \"test\"\n200:\n  description: \"ok\"\n", Yaml.getObjectMapper().writeValueAsString(responses));
+    }
+}