Rework the CDS Json schema 39/104839/1
authorsebdet <sebastien.determe@intl.att.com>
Wed, 1 Apr 2020 09:58:07 +0000 (11:58 +0200)
committersebdet <sebastien.determe@intl.att.com>
Wed, 1 Apr 2020 09:58:07 +0000 (11:58 +0200)
Rework a bit the CDS Json schema, so that the payload info is good now

Issue-ID: CLAMP-805
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Change-Id: I84d543987f421e3185c2783fc6cd779302658a1f

src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
src/test/resources/tosca/new-converter/tosca_apex_with_metadata.json

index b1c8890..b81e46b 100644 (file)
@@ -110,19 +110,40 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
                 }
             }
         }
-        addToJsonArray(childObject, "enum", schemaAnyOf);
+        addToJsonArray(childObject, "anyOf", schemaAnyOf);
     }
 
     private static JsonObject createPayloadProperty(JsonObject workFlow, JsonObject controllerProperties) {
         JsonObject payloadResult = new JsonObject();
 
-        payloadResult.addProperty("artifact_name", controllerProperties.get("sdnc_model_name").getAsString());
-        payloadResult.addProperty("artifact_version", controllerProperties.get("sdnc_model_version").getAsString());
-        payloadResult.addProperty("mode", "async");
-        payloadResult.add("data", workFlow.getAsJsonObject("inputs"));
+        payloadResult.add("artifact_name",
+                createAnyOfJsonProperty("artifact_name", controllerProperties.get("sdnc_model_name").getAsString()));
+        payloadResult.add("artifact_version",
+                createAnyOfJsonProperty("artifact_version",
+                        controllerProperties.get("sdnc_model_version").getAsString()));
+        payloadResult.add("mode", createAnyOfJsonProperty("mode", "async"));
+
+        payloadResult.add("data", createAnyOfJsonObject("data", workFlow.getAsJsonObject("inputs")));
         return payloadResult;
     }
 
+    private static JsonObject createAnyOfJsonProperty(String name, String defaultValue) {
+        JsonObject result = new JsonObject();
+        result.addProperty("title", name);
+        result.addProperty("type", "string");
+        result.addProperty("default", defaultValue);
+        result.addProperty("readOnly", "True");
+        return result;
+    }
+
+    private static JsonObject createAnyOfJsonObject(String name, JsonObject allProperties) {
+        JsonObject result = new JsonObject();
+        result.addProperty("title", name);
+        result.addProperty("type", "object");
+        result.add("properties", allProperties);
+        return result;
+    }
+
     private static void addToJsonArray(JsonObject childObject, String section, JsonArray value) {
         if (childObject.getAsJsonArray(section) != null) {
             childObject.getAsJsonArray(section).addAll(value);
index 687e9b2..4cb5bd8 100644 (file)
               "payload": {
                 "type": "object",
                 "description": "Name/value pairs of payload information passed by Policy to the actor",
-                "enum": [
+                "anyOf": [
                   {
                     "title": "resource-assignment",
                     "properties": {
-                      "artifact_name": "baseconfiguration",
-                      "artifact_version": "1.0.0",
-                      "mode": "async",
+                      "artifact_name": {
+                        "title": "artifact_name",
+                        "type": "string",
+                        "default": "baseconfiguration",
+                        "readOnly": "True"
+                      },
+                      "artifact_version": {
+                        "title": "artifact_version",
+                        "type": "string",
+                        "default": "1.0.0",
+                        "readOnly": "True"
+                      },
+                      "mode": {
+                        "title": "mode",
+                        "type": "string",
+                        "default": "async",
+                        "readOnly": "True"
+                      },
                       "data": {
-                        "resource-assignment-properties": {
-                          "request-id": "",
-                          "service-instance-id": "",
-                          "vnf-id": "",
-                          "action-name": "",
-                          "scope-type": "",
-                          "hostname": "",
-                          "vnf_name": ""
+                        "title": "data",
+                        "type": "object",
+                        "properties": {
+                          "resource-assignment-properties": {
+                            "request-id": "",
+                            "service-instance-id": "",
+                            "vnf-id": "",
+                            "action-name": "",
+                            "scope-type": "",
+                            "hostname": "",
+                            "vnf_name": ""
+                          }
                         }
                       }
                     }
                   {
                     "title": "activate",
                     "properties": {
-                      "artifact_name": "baseconfiguration",
-                      "artifact_version": "1.0.0",
-                      "mode": "async",
+                      "artifact_name": {
+                        "title": "artifact_name",
+                        "type": "string",
+                        "default": "baseconfiguration",
+                        "readOnly": "True"
+                      },
+                      "artifact_version": {
+                        "title": "artifact_version",
+                        "type": "string",
+                        "default": "1.0.0",
+                        "readOnly": "True"
+                      },
+                      "mode": {
+                        "title": "mode",
+                        "type": "string",
+                        "default": "async",
+                        "readOnly": "True"
+                      },
                       "data": {
-                        "resource-assignment-properties": {
-                          "request-id": "",
-                          "service-instance-id": "",
-                          "vnf-id": "",
-                          "action-name": "",
-                          "scope-type": "",
-                          "hostname": "",
-                          "vnf_name": ""
+                        "title": "data",
+                        "type": "object",
+                        "properties": {
+                          "resource-assignment-properties": {
+                            "request-id": "",
+                            "service-instance-id": "",
+                            "vnf-id": "",
+                            "action-name": "",
+                            "scope-type": "",
+                            "hostname": "",
+                            "vnf_name": ""
+                          }
                         }
                       }
                     }
                   {
                     "title": "activate-restconf",
                     "properties": {
-                      "artifact_name": "baseconfiguration",
-                      "artifact_version": "1.0.0",
-                      "mode": "async",
+                      "artifact_name": {
+                        "title": "artifact_name",
+                        "type": "string",
+                        "default": "baseconfiguration",
+                        "readOnly": "True"
+                      },
+                      "artifact_version": {
+                        "title": "artifact_version",
+                        "type": "string",
+                        "default": "1.0.0",
+                        "readOnly": "True"
+                      },
+                      "mode": {
+                        "title": "mode",
+                        "type": "string",
+                        "default": "async",
+                        "readOnly": "True"
+                      },
                       "data": {
-                        "resource-assignment-properties": {
-                          "request-id": "",
-                          "service-instance-id": "",
-                          "vnf-id": "",
-                          "action-name": "",
-                          "scope-type": "",
-                          "hostname": "",
-                          "vnf_name": ""
+                        "title": "data",
+                        "type": "object",
+                        "properties": {
+                          "resource-assignment-properties": {
+                            "request-id": "",
+                            "service-instance-id": "",
+                            "vnf-id": "",
+                            "action-name": "",
+                            "scope-type": "",
+                            "hostname": "",
+                            "vnf_name": ""
+                          }
                         }
                       }
                     }
                   {
                     "title": "activate-cli",
                     "properties": {
-                      "artifact_name": "baseconfiguration",
-                      "artifact_version": "1.0.0",
-                      "mode": "async",
+                      "artifact_name": {
+                        "title": "artifact_name",
+                        "type": "string",
+                        "default": "baseconfiguration",
+                        "readOnly": "True"
+                      },
+                      "artifact_version": {
+                        "title": "artifact_version",
+                        "type": "string",
+                        "default": "1.0.0",
+                        "readOnly": "True"
+                      },
+                      "mode": {
+                        "title": "mode",
+                        "type": "string",
+                        "default": "async",
+                        "readOnly": "True"
+                      },
                       "data": {
-                        "resource-assignment-properties": {
-                          "request-id": "",
-                          "service-instance-id": "",
-                          "vnf-id": "",
-                          "action-name": "",
-                          "scope-type": "",
-                          "hostname": "",
-                          "vnf_name": ""
+                        "title": "data",
+                        "type": "object",
+                        "properties": {
+                          "resource-assignment-properties": {
+                            "request-id": "",
+                            "service-instance-id": "",
+                            "vnf-id": "",
+                            "action-name": "",
+                            "scope-type": "",
+                            "hostname": "",
+                            "vnf_name": ""
+                          }
                         }
                       }
                     }
                   {
                     "title": "assign-activate",
                     "properties": {
-                      "artifact_name": "baseconfiguration",
-                      "artifact_version": "1.0.0",
-                      "mode": "async",
+                      "artifact_name": {
+                        "title": "artifact_name",
+                        "type": "string",
+                        "default": "baseconfiguration",
+                        "readOnly": "True"
+                      },
+                      "artifact_version": {
+                        "title": "artifact_version",
+                        "type": "string",
+                        "default": "1.0.0",
+                        "readOnly": "True"
+                      },
+                      "mode": {
+                        "title": "mode",
+                        "type": "string",
+                        "default": "async",
+                        "readOnly": "True"
+                      },
                       "data": {
-                        "resource-assignment-properties": {
-                          "request-id": "",
-                          "service-instance-id": "",
-                          "vnf-id": "",
-                          "action-name": "",
-                          "scope-type": "",
-                          "hostname": "",
-                          "vnf_name": ""
+                        "title": "data",
+                        "type": "object",
+                        "properties": {
+                          "resource-assignment-properties": {
+                            "request-id": "",
+                            "service-instance-id": "",
+                            "vnf-id": "",
+                            "action-name": "",
+                            "scope-type": "",
+                            "hostname": "",
+                            "vnf_name": ""
+                          }
                         }
                       }
                     }
                   {
                     "title": "imperative-test-wf",
                     "properties": {
-                      "artifact_name": "baseconfiguration",
-                      "artifact_version": "1.0.0",
-                      "mode": "async",
+                      "artifact_name": {
+                        "title": "artifact_name",
+                        "type": "string",
+                        "default": "baseconfiguration",
+                        "readOnly": "True"
+                      },
+                      "artifact_version": {
+                        "title": "artifact_version",
+                        "type": "string",
+                        "default": "1.0.0",
+                        "readOnly": "True"
+                      },
+                      "mode": {
+                        "title": "mode",
+                        "type": "string",
+                        "default": "async",
+                        "readOnly": "True"
+                      },
                       "data": {
-                        "resource-assignment-properties": {
-                          "request-id": "",
-                          "service-instance-id": "",
-                          "vnf-id": "",
-                          "action-name": "",
-                          "scope-type": "",
-                          "hostname": "",
-                          "vnf_name": ""
+                        "title": "data",
+                        "type": "object",
+                        "properties": {
+                          "resource-assignment-properties": {
+                            "request-id": "",
+                            "service-instance-id": "",
+                            "vnf-id": "",
+                            "action-name": "",
+                            "scope-type": "",
+                            "hostname": "",
+                            "vnf_name": ""
+                          }
                         }
                       }
                     }