Add response body example for ROOT operations GET 21/113121/5
authorYaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
Fri, 16 Aug 2024 10:02:00 +0000 (13:02 +0300)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Wed, 2 Oct 2024 06:38:05 +0000 (06:38 +0000)
Hardcoded top-level container "ietf-restconf:operations" for
the OpenAPI-generated example.
Implemented fixed structure to ensure proper schema generation
for both JSON and XML.
Updated unit tests (UT) accordingly to reflect
the new changes.

JIRA: NETCONF-1343
Change-Id: I4aa9f4d782eee929cd49b445913683c3cd1ea33b
Signed-off-by: Yaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
14 files changed:
restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/model/GetRootEntity.java
restconf/restconf-openapi/src/test/resources/operational-document/controller-all.json
restconf/restconf-openapi/src/test/resources/operational-document/device-all.json
restconf/restconf-openapi/src/test/resources/toaster-document/controller-all.json
restconf/restconf-openapi/src/test/resources/toaster-document/device-all.json
restconf/restconf-openapi/src/test/resources/yang-document/controller-all-depth-one.json
restconf/restconf-openapi/src/test/resources/yang-document/controller-all-width-and-depth-one.json
restconf/restconf-openapi/src/test/resources/yang-document/controller-all-width-one.json
restconf/restconf-openapi/src/test/resources/yang-document/controller-all.json
restconf/restconf-openapi/src/test/resources/yang-document/controller-offset3&limit5.json
restconf/restconf-openapi/src/test/resources/yang-document/device-all-depth-one.json
restconf/restconf-openapi/src/test/resources/yang-document/device-all-width-and-depth-one.json
restconf/restconf-openapi/src/test/resources/yang-document/device-all-width-one.json
restconf/restconf-openapi/src/test/resources/yang-document/device-all.json

index 35f54ca27eff7d01efcaea211d8c8ddd315f1ee4..5ab71933e72b044392ee31ff6a462c929a5f5c3b 100644 (file)
@@ -18,6 +18,7 @@ import javax.ws.rs.core.MediaType;
 import org.eclipse.jdt.annotation.NonNull;
 
 public final class GetRootEntity extends GetEntity {
+    private static final String OPERATIONS = "operations";
     private static final String DATA = "data";
     private static final String CONTROLLER = "Controller";
     private static final String NETCONF_STATE = "#/components/schemas/ietf-netconf-monitoring_netconf-state";
@@ -44,8 +45,10 @@ public final class GetRootEntity extends GetEntity {
                     supported by the server, some session-specific data and statistical data.""");
             }
         } else {
-            generator.writeStringField(DESCRIPTION,
-                "Queries the available operations (RPC calls) on the mounted hosted.");
+            generator.writeStringField(DESCRIPTION, """
+                The example demonstrates only top-level container "ietf-restconf:operations".
+                The request returns a list of all available operations on the mounted
+                host, showcasing the structure of RPCs that can be executed.""");
         }
         generator.writeObjectFieldStart(RESPONSES);
         generator.writeObjectFieldStart(String.valueOf(OK.getStatusCode()));
@@ -66,6 +69,11 @@ public final class GetRootEntity extends GetEntity {
             }
             generator.writeEndObject(); // end of state
         }
+        if (type.equals(OPERATIONS)) {
+            generator.writeObjectFieldStart("ietf-restconf:operations");
+            generator.writeStringField(TYPE, OBJECT);
+            generator.writeEndObject(); // end of ietf-restconf:operations
+        }
         generator.writeEndObject(); // end of properties
         generator.writeEndObject(); // end of json schema
         generator.writeEndObject(); //end of json
@@ -78,6 +86,14 @@ public final class GetRootEntity extends GetEntity {
                 generator.writeStringField(REF, NETCONF_STATE);
             }
         }
+        if (type.equals(OPERATIONS)) {
+            generator.writeStringField(TYPE, OBJECT);
+            // Define the root XML element and namespace
+            generator.writeObjectFieldStart("xml");
+            generator.writeStringField(NAME, OPERATIONS);
+            generator.writeStringField("namespace", "urn:ietf:params:xml:ns:yang:ietf-restconf");
+            generator.writeEndObject(); // end of xml for root
+        }
         generator.writeEndObject(); // end of xml schema
         generator.writeEndObject(); // end of xml
         generator.writeEndObject(); //end of content
@@ -88,7 +104,7 @@ public final class GetRootEntity extends GetEntity {
         generator.writeArrayFieldStart("tags");
         generator.writeString(deviceName() + " root");
         generator.writeEndArray(); //end of tags
-        if (!type.equals("operations")) {
+        if (!type.equals(OPERATIONS)) {
             generateParams(generator);
         }
         generator.writeEndObject(); //end of get
index bd7921517f341378fdb04b754d1c689f361e29b6..52243e3a37a34362dc2712e94117e2c27485d85d 100644 (file)
     },
     "/rests/operations": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index 75a3eadcbbb84feff45a167da38c16dfde0f934c..f01af0391d3e24f715a4f30a52106f4f1898a7ac 100644 (file)
     },
     "/rests/operations/nodes/node=123/yang-ext:mount": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index 20614a3cc27e37e10291934c0454db0b616f6805..d4abb51c88f9239a08eaf262c0c0158a077745cc 100644 (file)
     },
     "/rests/operations": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index 6f2eb80a15b1e0a3c8f00bdaf65e3e1c0042a093..14dd52f50f165909b898cbe8bc5537951298938a 100644 (file)
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
           }
         },
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "summary": "GET - 123 - datastore - operations"
       }
     },
index 3771215c414bcab9e2c0e2b9b3c0fe3ff0bc9bcb..c25fb2a28a169139271d2607afcf4e819a08d87c 100644 (file)
     },
     "/rests/operations": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index 9c7578c2d89c4f4bd0ee9690e4b12160d99bad84..9941ca06bf9a24eaecf68201cc8d6443ec641382 100644 (file)
     },
     "/rests/operations": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index 0c75aac88295f9b2edceac059de6b4442575952e..747f810d9b08a33aa1335b79c55879381fafc531 100644 (file)
     },
     "/rests/operations": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index 920abffd55d07c1d2405eafdb2dab79cd3040ace..4b9611c69e34c45393588f748c8251cd50edfb02 100644 (file)
     },
     "/rests/operations": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {}
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
+                  }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index 8cbe276f66fa94ee7a62c7e06341dc372d27cd30..30559dd17b6d2ab333e638e8cda6937f798657ba 100644 (file)
     },
     "/rests/operations": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index 5505f188eeb0c5470231c108f331957fe198ce92..2dde7bd074459b4a14a417f159684c00a6ca4175 100644 (file)
     },
     "/rests/operations/nodes/node=123/yang-ext:mount": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index 40900c81dc01ae1f526d8457b7714f7f28fda781..7537a09696063a6d6a2c51e2abf8a0ae163d2879 100644 (file)
     },
     "/rests/operations/nodes/node=123/yang-ext:mount": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index fd549a4710421e808b21d1773670d0e5987f8826..d5edeff7a685a41a41df9424aeff5d78a289ce55 100644 (file)
     },
     "/rests/operations/nodes/node=123/yang-ext:mount": {
       "get": {
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
index f3d9e01c2dc5c4ead30f00b9e3d3fb37b65b47a8..43ddc86ed85dbb86a735b1c340cec923a8eae1a9 100644 (file)
         "responses": {
           "200": {
             "description": "OK",
-            "content": {
-              "application/json": {
-                "schema": {
-                  "properties": {
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "properties" : {
+                    "ietf-restconf:operations" : {
+                      "type" : "object"
+                    }
                   }
                 }
               },
-              "application/xml": {
-                "schema": {
+              "application/xml" : {
+                "schema" : {
+                  "type" : "object",
+                  "xml" : {
+                    "name" : "operations",
+                    "namespace" : "urn:ietf:params:xml:ns:yang:ietf-restconf"
+                  }
                 }
               }
             }
           }
         },
-        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "description": "The example demonstrates only top-level container \"ietf-restconf:operations\".\nThe request returns a list of all available operations on the mounted\nhost, showcasing the structure of RPCs that can be executed.",
         "summary": "GET - 123 - datastore - operations"
       }
     },