Fix logic of POST schema reference creation 91/107491/1
authorYaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
Wed, 23 Aug 2023 16:59:57 +0000 (19:59 +0300)
committerYaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
Fri, 25 Aug 2023 10:20:09 +0000 (13:20 +0300)
After implementing the 'Use first child in POST payloads' changes,
list child nodes no longer include a 'key' value in example payloads.

Removed unnecessary 'post' prefix from schema references
for lists and containers child nodes in POST requests,
enabling the use of a valid schema.

JIRA: NETCONF-1054
Change-Id: I26a07e1ad04a0d08567c31d48d24f19349dd8022
Signed-off-by: Yaroslav Lastivka <yaroslav.lastivka@pantheon.tech>
(cherry picked from commit 65c1945627ad388d4239f4a951aa9d4efc2dba74)

restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/model/builder/OperationBuilder.java
restconf/sal-rest-docgen/src/test/java/org/opendaylight/netconf/sal/rest/doc/impl/ApiDocGeneratorRFC8040Test.java
restconf/sal-rest-docgen/src/test/java/org/opendaylight/netconf/sal/rest/doc/impl/PostPayloadTest.java

index 15501eea7ba291f8f0f8978a10b7e19cb2ee38d1..af7c3650e345bbfe967f9288fbfd9a5a20bd4ac2 100644 (file)
@@ -92,7 +92,7 @@ public final class OperationBuilder {
         final DataSchemaNode childNode = getListOrContainerChildNode(Optional.ofNullable(node));
         if (childNode != null && childNode.isConfiguration()) {
             final String childNodeName = childNode.getQName().getLocalName();
-            final String cleanChildDefName = parentName + "_" + nodeName + CONFIG + "_" + childNodeName + POST_SUFFIX;
+            final String cleanChildDefName = parentName + "_" + nodeName + CONFIG + "_" + childNodeName;
             final String childDefName = cleanChildDefName + discriminator;
             final String childXmlDefName = cleanChildDefName + XML_SUFFIX + discriminator;
             insertPostRequestBodyParameter(childNode, parameters, value, childDefName, childXmlDefName, childNodeName,
index 155df2bed471f61c3cb16d8b61349c2137f4b30d..122fa61848eb57d38739273601fb596a01f80f62 100644 (file)
@@ -338,8 +338,8 @@ public final class ApiDocGeneratorRFC8040Test extends AbstractApiDocTest {
             ApiDocServiceImpl.OAversion.V3_0);
         final var jsonNodeToaster = doc.getPaths().get("/rests/data/toaster2:toaster");
         verifyPostRequestRef(jsonNodeToaster.path("post"),
-            "#/components/schemas/toaster2_toaster_config_toasterSlot_post",
-            "#/components/schemas/toaster2_toaster_config_toasterSlot_post_xml", LIST);
+            "#/components/schemas/toaster2_toaster_config_toasterSlot",
+            "#/components/schemas/toaster2_toaster_config_toasterSlot_xml", LIST);
         verifyRequestRef(jsonNodeToaster.path("put"), "#/components/schemas/toaster2_config_toaster_TOP",
                 "#/components/schemas/toaster2_config_toaster");
         verifyRequestRef(jsonNodeToaster.path("get"), "#/components/schemas/toaster2_toaster_TOP",
@@ -347,8 +347,8 @@ public final class ApiDocGeneratorRFC8040Test extends AbstractApiDocTest {
 
         final var jsonNodeToasterSlot = doc.getPaths().get("/rests/data/toaster2:toaster/toasterSlot={slotId}");
         verifyPostRequestRef(jsonNodeToasterSlot.path("post"),
-                "#/components/schemas/toaster2_toaster_toasterSlot_config_slotInfo_post",
-                "#/components/schemas/toaster2_toaster_toasterSlot_config_slotInfo_post_xml", CONTAINER);
+                "#/components/schemas/toaster2_toaster_toasterSlot_config_slotInfo",
+                "#/components/schemas/toaster2_toaster_toasterSlot_config_slotInfo_xml", CONTAINER);
         verifyRequestRef(jsonNodeToasterSlot.path("put"),
                 "#/components/schemas/toaster2_toaster_config_toasterSlot_TOP",
                 "#/components/schemas/toaster2_toaster_config_toasterSlot");
@@ -367,8 +367,8 @@ public final class ApiDocGeneratorRFC8040Test extends AbstractApiDocTest {
                 "#/components/schemas/toaster2_toaster_toasterSlot_slotInfo");
 
         final var jsonNodeLst = doc.getPaths().get("/rests/data/toaster2:lst");
-        verifyPostRequestRef(jsonNodeLst.path("post"), "#/components/schemas/toaster2_lst_config_cont1_post",
-                "#/components/schemas/toaster2_lst_config_cont1_post_xml", CONTAINER);
+        verifyPostRequestRef(jsonNodeLst.path("post"), "#/components/schemas/toaster2_lst_config_cont1",
+                "#/components/schemas/toaster2_lst_config_cont1_xml", CONTAINER);
         verifyRequestRef(jsonNodeLst.path("put"), "#/components/schemas/toaster2_config_lst_TOP",
                 "#/components/schemas/toaster2_config_lst");
         verifyRequestRef(jsonNodeLst.path("get"), "#/components/schemas/toaster2_lst_TOP",
index 388db76ab1b561fd2554772898ff4e6aba8ca88d..b931369443e6c60a8b06c349781f60498cdf3e21 100644 (file)
@@ -46,34 +46,34 @@ public class PostPayloadTest extends AbstractApiDocTest {
         final var path1 = "/rests/data/container-test:cont";
         assertNotNull(containerDoc.getPaths().get(path1));
         final var jsonRef1 = getJsonRef(containerDoc, path1);
-        assertEquals("{\"cont1\":{\"$ref\":\"#/components/schemas/container-test_cont_config_cont1_post\"}}",
+        assertEquals("{\"cont1\":{\"$ref\":\"#/components/schemas/container-test_cont_config_cont1\"}}",
             jsonRef1);
         final var xmlRef1 = getXmlRef(containerDoc, path1);
-        assertEquals("#/components/schemas/container-test_cont_config_cont1_post_xml", xmlRef1);
+        assertEquals("#/components/schemas/container-test_cont_config_cont1_xml", xmlRef1);
 
         final var path2 = "/rests/data/container-test:cont/cont1";
         assertNotNull(containerDoc.getPaths().get(path2));
         final var jsonRef2 = getJsonRef(containerDoc, path2);
         assertEquals("{\"list4\":{\"type\":\"array\",\"items\":{\"$ref\":\""
-            + "#/components/schemas/container-test_cont_cont1_config_list4_post\"}}}", jsonRef2);
+            + "#/components/schemas/container-test_cont_cont1_config_list4\"}}}", jsonRef2);
         final var xmlRef2 = getXmlRef(containerDoc, path2);
-        assertEquals("#/components/schemas/container-test_cont_cont1_config_list4_post_xml", xmlRef2);
+        assertEquals("#/components/schemas/container-test_cont_cont1_config_list4_xml", xmlRef2);
 
         final var path3 = "/rests/data/container-test:cont/cont1/list4={key4}";
         assertNotNull(containerDoc.getPaths().get(path3));
         final var jsonRef3 = getJsonRef(containerDoc, path3);
         assertEquals("{\"cont2\":{\"$ref\":\"#/components/schemas/"
-                + "container-test_cont_cont1_list4_config_cont2_post\"}}", jsonRef3);
+                + "container-test_cont_cont1_list4_config_cont2\"}}", jsonRef3);
         final var xmlRef3 = getXmlRef(containerDoc, path3);
-        assertEquals("#/components/schemas/container-test_cont_cont1_list4_config_cont2_post_xml", xmlRef3);
+        assertEquals("#/components/schemas/container-test_cont_cont1_list4_config_cont2_xml", xmlRef3);
 
         final var path4 = "/rests/data/container-test:cont/cont1/list4={key4}/cont2";
         assertNotNull(containerDoc.getPaths().get(path4));
         final var jsonRef4 = getJsonRef(containerDoc, path4);
         assertEquals("{\"list5\":{\"type\":\"array\",\"items\":{\"$ref\":\""
-                + "#/components/schemas/container-test_cont_cont1_list4_cont2_config_list5_post\"}}}", jsonRef4);
+                + "#/components/schemas/container-test_cont_cont1_list4_cont2_config_list5\"}}}", jsonRef4);
         final var xmlRef4 = getXmlRef(containerDoc, path4);
-        assertEquals("#/components/schemas/container-test_cont_cont1_list4_cont2_config_list5_post_xml", xmlRef4);
+        assertEquals("#/components/schemas/container-test_cont_cont1_list4_cont2_config_list5_xml", xmlRef4);
     }
 
     @Test
@@ -82,17 +82,17 @@ public class PostPayloadTest extends AbstractApiDocTest {
         assertNotNull(listDoc.getPaths().get(path1));
         final var jsonRef1 = getJsonRef(listDoc, path1);
         assertEquals("{\"list1\":{\"type\":\"array\",\"items\":{\"$ref\":\""
-            + "#/components/schemas/list-test_cont_config_list1_post\"}}}", jsonRef1);
+            + "#/components/schemas/list-test_cont_config_list1\"}}}", jsonRef1);
         final var xmlRef1 = getXmlRef(listDoc, path1);
-        assertEquals("#/components/schemas/list-test_cont_config_list1_post_xml", xmlRef1);
+        assertEquals("#/components/schemas/list-test_cont_config_list1_xml", xmlRef1);
 
         final var path2 = "/rests/data/list-test:cont/list2={key2}";
         assertNotNull(listDoc.getPaths().get(path2));
         final var jsonRef2 = getJsonRef(listDoc, path2);
         assertEquals("{\"list3\":{\"type\":\"array\",\"items\":{\"$ref\":\""
-            + "#/components/schemas/list-test_cont_list2_config_list3_post\"}}}", jsonRef2);
+            + "#/components/schemas/list-test_cont_list2_config_list3\"}}}", jsonRef2);
         final var xmlRef2 = getXmlRef(listDoc, path2);
-        assertEquals("#/components/schemas/list-test_cont_list2_config_list3_post_xml", xmlRef2);
+        assertEquals("#/components/schemas/list-test_cont_list2_config_list3_xml", xmlRef2);
     }
 
     private static String getJsonRef(final OpenApiObject openApiObject, final String path) {