OpenAPI: do not generate duplicated schemas 10/111010/4
authorSamuel Schneider <samuel.schneider@pantheon.tech>
Mon, 25 Mar 2024 17:23:05 +0000 (18:23 +0100)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Tue, 2 Apr 2024 10:51:25 +0000 (10:51 +0000)
Skip processing of node if it was already processed.
Currently, we generate multiple schemas with different name
for the same node and the last one is used.

JIRA: NETCONF-1270
Change-Id: I817f5d5db9183b0162b663bd2e80f5971ea8366a
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/SchemasStream.java
restconf/restconf-openapi/src/test/resources/yang-document/controller-all.json
restconf/restconf-openapi/src/test/resources/yang-document/controller-duplication-test.json
restconf/restconf-openapi/src/test/resources/yang-document/device-all.json
restconf/restconf-openapi/src/test/resources/yang-document/device-duplication-test.json

index c1efb8da644a6c37cfafc42b75bfc002c63c00ca..603c2383b527c5e2be4820c52e2dec1686731b64 100644 (file)
@@ -183,6 +183,10 @@ public final class SchemasStream extends InputStream {
             final SchemaInferenceStack stack, final DefinitionNames definitionNames,
             final ArrayDeque<SchemaEntity> result, final String parentName, final boolean isParentConfig) {
         if (node instanceof ContainerSchemaNode || node instanceof ListSchemaNode) {
+            if (definitionNames.isListedNode(node)) {
+                // This means schema for this node is already processed
+                return;
+            }
             final var newTitle = title + "_" + node.getQName().getLocalName();
             final var parentNameConfigLocalName = parentName + "_" + node.getQName().getLocalName();
             final var names = List.of(parentNameConfigLocalName);
index 1537833e1c1285eb9c7e483caa2f5002fa6ee043..96bac1010af8d791de8d13fcd20847844b45ca23 100644 (file)
       "duplication-test_test-rpc2_input": {
         "properties": {
           "first": {
-            "$ref": "#/components/schemas/duplication-test_first1"
+            "$ref": "#/components/schemas/duplication-test_first"
           },
           "input-leaf": {
             "description": "",
       "duplication-test_test-rpc_input": {
         "properties": {
           "first": {
-            "$ref": "#/components/schemas/duplication-test_first1"
+            "$ref": "#/components/schemas/duplication-test_first"
           },
           "input-leaf": {
             "description": "",
           "name": "input",
           "namespace": "urn:ietf:params:xml:ns:yang:test:duplication:test"
         }
-      },
-      "duplication-test_first1": {
-        "title": "duplication-test_first",
-        "type": "object",
-        "properties": {},
-        "xml": {
-          "name": "first",
-          "namespace": "urn:ietf:params:xml:ns:yang:test:duplication:service"
-        }
       }
     },
     "securitySchemes": {
index 607f1ea5d03113bcff00a749fe33b1409eb1466f..ea2341c1af97f878c85d06535de818cfbed7c28e 100644 (file)
@@ -94,7 +94,7 @@
             "example": "Some input-leaf"
           },
           "first": {
-            "$ref": "#/components/schemas/duplication-test_first1"
+            "$ref": "#/components/schemas/duplication-test_first"
           }
         },
         "xml": {
             "example": "Some input-leaf"
           },
           "first": {
-            "$ref": "#/components/schemas/duplication-test_first1"
+            "$ref": "#/components/schemas/duplication-test_first"
           }
         },
         "xml": {
           "name": "input",
           "namespace": "urn:ietf:params:xml:ns:yang:test:duplication:test"
         }
-      },
-      "duplication-test_first1": {
-        "title": "duplication-test_first",
-        "type": "object",
-        "properties": {},
-        "xml": {
-          "name": "first",
-          "namespace": "urn:ietf:params:xml:ns:yang:test:duplication:service"
-        }
       }
     },
     "securitySchemes": {
index 9fa4f441550b662fb9409f9ab8340ae261a68181..6a97c2ce294ec765411baeae5f917ba65184a7cb 100644 (file)
       "duplication-test_test-rpc2_input": {
         "properties": {
           "first": {
-            "$ref": "#/components/schemas/duplication-test_first1"
+            "$ref": "#/components/schemas/duplication-test_first"
           },
           "input-leaf": {
             "description": "",
       "duplication-test_test-rpc_input": {
         "properties": {
           "first": {
-            "$ref": "#/components/schemas/duplication-test_first1"
+            "$ref": "#/components/schemas/duplication-test_first"
           },
           "input-leaf": {
             "description": "",
           "name": "input",
           "namespace": "urn:ietf:params:xml:ns:yang:test:duplication:test"
         }
-      },
-      "duplication-test_first1": {
-        "title": "duplication-test_first",
-        "type": "object",
-        "properties": {},
-        "xml": {
-          "name": "first",
-          "namespace": "urn:ietf:params:xml:ns:yang:test:duplication:service"
-        }
       }
     },
     "securitySchemes": {
index decc2497526f14a7f543ac0a478d288bfe46c3ed..106fe112a9d59fb88426cacde78693b8b787c4a2 100644 (file)
@@ -94,7 +94,7 @@
             "example": "Some input-leaf"
           },
           "first": {
-            "$ref": "#/components/schemas/duplication-test_first1"
+            "$ref": "#/components/schemas/duplication-test_first"
           }
         },
         "xml": {
             "example": "Some input-leaf"
           },
           "first": {
-            "$ref": "#/components/schemas/duplication-test_first1"
+            "$ref": "#/components/schemas/duplication-test_first"
           }
         },
         "xml": {
           "name": "input",
           "namespace": "urn:ietf:params:xml:ns:yang:test:duplication:test"
         }
-      },
-      "duplication-test_first1": {
-        "title": "duplication-test_first",
-        "type": "object",
-        "properties": {},
-        "xml": {
-          "name": "first",
-          "namespace": "urn:ietf:params:xml:ns:yang:test:duplication:service"
-        }
       }
     },
     "securitySchemes": {