Test JSON representations of responses in OpenApi 91/107391/29
authorŠimon Ukuš <simon.ukus@pantheon.tech>
Fri, 11 Aug 2023 12:48:15 +0000 (14:48 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Wed, 4 Oct 2023 14:19:15 +0000 (14:19 +0000)
We did not have any tests that would provide a higher overview
of the responses sent back to clients. Such view gives us an idea
about the generated output.

These tests verify the full response of each endpoint by comparing
the results to prepared JSONs.

JIRA: NETCONF-1131
Change-Id: I008f01e3c11593f5a2d0f53843bc4d5639abda1a
Signed-off-by: Šimon Ukuš <simon.ukus@pantheon.tech>
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
restconf/restconf-openapi/pom.xml
restconf/restconf-openapi/src/test/java/org/opendaylight/restconf/openapi/impl/SwaggerDocumentTest.java [new file with mode: 0644]
restconf/restconf-openapi/src/test/resources/openapi-document/controller-all.json [new file with mode: 0644]
restconf/restconf-openapi/src/test/resources/openapi-document/controller-toaster.json [new file with mode: 0644]
restconf/restconf-openapi/src/test/resources/openapi-document/device-all.json [new file with mode: 0644]
restconf/restconf-openapi/src/test/resources/openapi-document/device-toaster.json [new file with mode: 0644]
restconf/restconf-openapi/src/test/resources/openapi-document/toaster.yang [new file with mode: 0644]

index 695e3314c1658d800e2b8652c9926edf33b2672d..39719761c4f524f8475b3bfe731d9d6b2d16866c 100644 (file)
       <artifactId>jersey-server</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.skyscreamer</groupId>
+      <artifactId>jsonassert</artifactId>
+      <version>1.5.1</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>yang-test-util</artifactId>
diff --git a/restconf/restconf-openapi/src/test/java/org/opendaylight/restconf/openapi/impl/SwaggerDocumentTest.java b/restconf/restconf-openapi/src/test/java/org/opendaylight/restconf/openapi/impl/SwaggerDocumentTest.java
new file mode 100644 (file)
index 0000000..7013248
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.openapi.impl;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Optional;
+import org.glassfish.jersey.internal.util.collection.ImmutableMultivaluedMap;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.restconf.openapi.DocGenTestHelper;
+import org.opendaylight.restconf.openapi.api.OpenApiService;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.skyscreamer.jsonassert.JSONCompareMode;
+
+public class SwaggerDocumentTest {
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+    /**
+     * We want flexibility in comparing the resulting JSONs by not enforcing strict ordering of array contents.
+     * This comparison mode allows us to do that and also to restrict extensibility (extensibility = additional fields)
+     */
+    private static final JSONCompareMode IGNORE_ORDER = JSONCompareMode.NON_EXTENSIBLE;
+    private static final String TOASTER = "toaster";
+    private static final String TOASTER_REV = "2009-11-20";
+    private static final YangInstanceIdentifier INSTANCE_ID = YangInstanceIdentifier.builder()
+        .node(QName.create("", "nodes"))
+        .node(QName.create("", "node"))
+        .nodeWithKey(QName.create("", "node"), QName.create("", "id"), "123").build();
+
+    private static OpenApiService openApiService;
+
+    @BeforeClass
+    public static void beforeClass() {
+        final var schemaService = mock(DOMSchemaService.class);
+        final var context = YangParserTestUtils.parseYangResource("/openapi-document/toaster.yang");
+        when(schemaService.getGlobalContext()).thenReturn(context);
+
+        final var mountPoint = mock(DOMMountPoint.class);
+        when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(schemaService));
+
+        final var service = mock(DOMMountPointService.class);
+        when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
+
+        final var mountPointRFC8040 = new MountPointOpenApiGeneratorRFC8040(schemaService, service);
+        final var openApiGeneratorRFC8040 = new OpenApiGeneratorRFC8040(schemaService);
+        mountPointRFC8040.getMountPointOpenApi().onMountPointCreated(INSTANCE_ID);
+        openApiService = new OpenApiServiceImpl(mountPointRFC8040, openApiGeneratorRFC8040);
+    }
+
+    /**
+     * Tests the swagger document that is result of the call to the '/single' endpoint.
+     */
+    @Test
+    public void getAllModulesDocTest() throws Exception {
+        final var getAllController = DocGenTestHelper.createMockUriInfo("http://localhost:8181/openapi/api/v3/single");
+        final var controllerDocAll = openApiService.getAllModulesDoc(getAllController).getEntity();
+
+        final var jsonControllerDoc = MAPPER.writeValueAsString(controllerDocAll);
+        final var expectedJson = MAPPER.writeValueAsString(MAPPER.readTree(
+            getClass().getClassLoader().getResourceAsStream("openapi-document/controller-all.json")));
+        JSONAssert.assertEquals(expectedJson, jsonControllerDoc, IGNORE_ORDER);
+    }
+
+    /**
+     * Tests the swagger document that is result of the call to the '/toaster(2009-11-20)' endpoint.
+     */
+    @Test
+    public void getDocByModuleTest() throws Exception {
+        final var getToasterController = DocGenTestHelper.createMockUriInfo("http://localhost:8181/openapi/api/v3/toaster(2009-11-20)");
+        final var controllerDocToaster = openApiService.getDocByModule(TOASTER, TOASTER_REV, getToasterController);
+
+        final var jsonControllerDoc = MAPPER.writeValueAsString(controllerDocToaster.getEntity());
+        final var expectedJson = MAPPER.writeValueAsString(MAPPER.readTree(
+            getClass().getClassLoader().getResourceAsStream("openapi-document/controller-toaster.json")));
+        JSONAssert.assertEquals(expectedJson, jsonControllerDoc, IGNORE_ORDER);
+    }
+
+    /**
+     * Tests the swagger document that is result of the call to the '/mounts/1' endpoint.
+     */
+    @Test
+    public void getMountDocTest() throws Exception {
+        final var getAllDevice = DocGenTestHelper.createMockUriInfo("http://localhost:8181/openapi/api/v3/mounts/1");
+        when(getAllDevice.getQueryParameters()).thenReturn(ImmutableMultivaluedMap.empty());
+        final var deviceDocAll = openApiService.getMountDoc("1", getAllDevice);
+
+        final var jsonDeviceDoc = MAPPER.writeValueAsString(deviceDocAll.getEntity());
+        final var expectedJson = MAPPER.writeValueAsString(MAPPER.readTree(
+            getClass().getClassLoader().getResourceAsStream("openapi-document/device-all.json")));
+        JSONAssert.assertEquals(expectedJson, jsonDeviceDoc, IGNORE_ORDER);
+    }
+
+    /**
+     * Tests the swagger document that is result of the call to the '/mounts/1/toaster(2009-11-20)' endpoint.
+     */
+    @Test
+    public void getMountDocByModuleTest() throws Exception {
+        final var getToasterDevice = DocGenTestHelper.createMockUriInfo("http://localhost:8181/openapi/api/v3/mounts/1/toaster(2009-11-20)");
+        final var deviceDocToaster = openApiService.getMountDocByModule("1", TOASTER, TOASTER_REV, getToasterDevice);
+
+        final var jsonDeviceDoc = MAPPER.writeValueAsString(deviceDocToaster.getEntity());
+        final var expectedJson = MAPPER.writeValueAsString(MAPPER.readTree(
+            getClass().getClassLoader().getResourceAsStream("openapi-document/device-toaster.json")));
+        JSONAssert.assertEquals(expectedJson, jsonDeviceDoc, IGNORE_ORDER);
+    }
+}
diff --git a/restconf/restconf-openapi/src/test/resources/openapi-document/controller-all.json b/restconf/restconf-openapi/src/test/resources/openapi-document/controller-all.json
new file mode 100644 (file)
index 0000000..36c6da0
--- /dev/null
@@ -0,0 +1,411 @@
+{
+  "openapi": "3.0.3",
+  "info": {
+    "version": "1.0.0",
+    "title": "Controller modules of RESTCONF",
+    "description": "We are providing full API for configurational data which can be edited (by POST, PUT, PATCH and DELETE).\nFor operational data we only provide GET API.\n\nFor majority of request you can see only config data in examples. That’s because we can show only one example\nper request. The exception when you can see operational data in example is when data are representing\noperational (config false) container with no config data in it."
+  },
+  "servers": [
+    {
+      "url": "http://localhost:8181/"
+    }
+  ],
+  "paths": {
+    "/rests/operations/toaster:cancel-toast": {
+      "post": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "cancel-toast_input",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "type": "object"
+                  }
+                },
+                "type": "object"
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "xml": {
+                  "name": "input"
+                },
+                "type": "object"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC cancel-toast success"
+          }
+        },
+        "description": "Stop making toast, if any is being made.\nA 'resource-denied' error will be returned\nif the toaster service is disabled.",
+        "summary": "POST - Controller - toaster - cancel-toast"
+      }
+    },
+    "/rests/data/toaster:toaster": {
+      "get": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [
+          {
+            "name": "content",
+            "in": "query",
+            "required": false,
+            "schema": {
+              "enum": [
+                "config",
+                "nonconfig",
+                "all"
+              ],
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "200",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "properties": {
+                    "toaster": {
+                      "$ref": "#/components/schemas/toaster_toaster",
+                      "type": "object"
+                    }
+                  }
+                }
+              },
+              "application/xml": {
+                "schema": {
+                  "$ref": "#/components/schemas/toaster_toaster"
+                }
+              }
+            }
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "GET - Controller - toaster - toaster"
+      },
+      "put": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "toaster:toaster": {
+                    "$ref": "#/components/schemas/toaster_toaster",
+                    "type": "object"
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "Updated"
+          },
+          "201": {
+            "description": "Created"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "PUT - toaster - Controller - toaster"
+      },
+      "post": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/json": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.\n\nNote:\nIn example payload, you can see only the first data node child of the resource to be created, following the\nguidelines of RFC 8040, which allows us to create only one resource in POST request.\n",
+        "summary": "POST - Controller - toaster - toaster"
+      },
+      "delete": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "responses": {
+          "204": {
+            "description": "Deleted"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "DELETE - Controller - toaster - toaster"
+      },
+      "patch": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/yang-data+xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            },
+            "application/yang-data+json": {
+              "schema": {
+                "properties": {
+                  "toaster:toaster": {
+                    "$ref": "#/components/schemas/toaster_toaster",
+                    "type": "object"
+                  }
+                }
+              }
+            }
+          }
+        },
+        "responses": {
+          "200": {
+            "description": "OK"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "PATCH - toaster - Controller - toaster"
+      }
+    },
+    "/rests/operations/toaster:make-toast": {
+      "post": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "make-toast_input",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "$ref": "#/components/schemas/toaster_make-toast_input",
+                    "type": "object"
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_make-toast_input"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC make-toast success"
+          }
+        },
+        "description": "Make some toast.\nThe toastDone notification will be sent when\nthe toast is finished.\nAn 'in-use' error will be returned if toast\nis already being made.\nA 'resource-denied' error will be returned\nif the toaster service is disabled.",
+        "summary": "POST - Controller - toaster - make-toast"
+      }
+    },
+    "/rests/operations/toaster:restock-toaster": {
+      "post": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "restock-toaster_input",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "$ref": "#/components/schemas/toaster_restock-toaster_input",
+                    "type": "object"
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_restock-toaster_input"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC restock-toaster success"
+          }
+        },
+        "description": "Restocks the toaster with the amount of bread specified.",
+        "summary": "POST - Controller - toaster - restock-toaster"
+      }
+    }
+  },
+  "components": {
+    "schemas": {
+      "hash-brown": {
+        "enum": [
+          "hash-brown"
+        ],
+        "description": "Hash browned potatos.",
+        "title": "hash-brown",
+        "type": "string"
+      },
+      "toaster_make-toast_input": {
+        "properties": {
+          "toasterDoneness": {
+            "default": 5,
+            "description": "This variable controls how well-done is the\nensuing toast. It should be on a scale of 1 to 10.\nToast made at 10 generally is considered unfit\nfor human consumption; toast made at 1 is warmed\nlightly.",
+            "type": "integer",
+            "example": 1,
+            "format": "int64"
+          },
+          "toasterToastType": {
+            "$ref": "#/components/schemas/toast-type"
+          }
+        },
+        "xml": {
+          "name": "input"
+        },
+        "title": "toaster_make-toast_input",
+        "type": "object"
+      },
+      "toast-type": {
+        "enum": [
+          "toast-type",
+          "wheat-bread",
+          "frozen-bagel",
+          "white-bread",
+          "wonder-bread",
+          "hash-brown",
+          "frozen-waffle"
+        ],
+        "description": "Base for all bread types supported by the toaster.\nNew bread types not listed here nay be added in the\nfuture.",
+        "title": "toast-type",
+        "type": "string"
+      },
+      "frozen-bagel": {
+        "enum": [
+          "frozen-bagel"
+        ],
+        "description": "Frozen bagel.",
+        "title": "frozen-bagel",
+        "type": "string"
+      },
+      "toaster_restock-toaster_input": {
+        "properties": {
+          "amountOfBreadToStock": {
+            "description": "Indicates the amount of bread to re-stock",
+            "type": "integer",
+            "example": 0,
+            "format": "int64"
+          }
+        },
+        "xml": {
+          "name": "input"
+        },
+        "title": "toaster_restock-toaster_input",
+        "type": "object"
+      },
+      "frozen-waffle": {
+        "enum": [
+          "frozen-waffle"
+        ],
+        "description": "Frozen waffle.",
+        "title": "frozen-waffle",
+        "type": "string"
+      },
+      "white-bread": {
+        "enum": [
+          "white-bread"
+        ],
+        "description": "White bread.",
+        "title": "white-bread",
+        "type": "string"
+      },
+      "wheat-bread": {
+        "enum": [
+          "wheat-bread"
+        ],
+        "description": "Wheat bread.",
+        "title": "wheat-bread",
+        "type": "string"
+      },
+      "wonder-bread": {
+        "enum": [
+          "wonder-bread"
+        ],
+        "description": "Wonder bread.",
+        "title": "wonder-bread",
+        "type": "string"
+      },
+      "toaster_toaster": {
+        "properties": {
+          "darknessFactor": {
+            "default": 1000,
+            "description": "The darkness factor. Basically, the number of ms to multiple the doneness value by.",
+            "type": "integer",
+            "example": 0,
+            "format": "int64"
+          }
+        },
+        "xml": {
+          "name": "toaster",
+          "namespace": "http://netconfcentral.org/ns/toaster"
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "title": "toaster_toaster",
+        "type": "object"
+      }
+    },
+    "securitySchemes": {
+      "basicAuth": {
+        "scheme": "basic",
+        "type": "http"
+      }
+    }
+  },
+  "security": [
+    {
+      "basicAuth": []
+    }
+  ]
+}
diff --git a/restconf/restconf-openapi/src/test/resources/openapi-document/controller-toaster.json b/restconf/restconf-openapi/src/test/resources/openapi-document/controller-toaster.json
new file mode 100644 (file)
index 0000000..a9a869a
--- /dev/null
@@ -0,0 +1,451 @@
+{
+  "openapi": "3.0.3",
+  "info": {
+    "version": "1.0.0",
+    "title": "toaster",
+    "description": "We are providing full API for configurational data which can be edited (by POST, PUT, PATCH and DELETE).\nFor operational data we only provide GET API.\n\nFor majority of request you can see only config data in examples. That’s because we can show only one example\nper request. The exception when you can see operational data in example is when data are representing\noperational (config false) container with no config data in it."
+  },
+  "servers": [
+    {
+      "url": "http://localhost:8181/"
+    }
+  ],
+  "paths": {
+    "/rests/data": {
+      "post": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster_module",
+          "content": {
+            "application/json": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_module"
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_module"
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          }
+        },
+        "description": "YANG version of the TOASTER-MIB.\n\nNote:\nIn example payload, you can see only the first data node child of the resource to be created, following the\nguidelines of RFC 8040, which allows us to create only one resource in POST request.\n",
+        "summary": "POST - Controller - toaster - toaster_module"
+      }
+    },
+    "/rests/operations/toaster:cancel-toast": {
+      "post": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "cancel-toast_input",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "type": "object"
+                  }
+                },
+                "type": "object"
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "xml": {
+                  "name": "input"
+                },
+                "type": "object"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC cancel-toast success"
+          }
+        },
+        "description": "Stop making toast, if any is being made.\nA 'resource-denied' error will be returned\nif the toaster service is disabled.",
+        "summary": "POST - Controller - toaster - cancel-toast"
+      }
+    },
+    "/rests/data/toaster:toaster": {
+      "get": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [
+          {
+            "name": "content",
+            "in": "query",
+            "required": false,
+            "schema": {
+              "enum": [
+                "config",
+                "nonconfig",
+                "all"
+              ],
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "200",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "properties": {
+                    "toaster": {
+                      "$ref": "#/components/schemas/toaster_toaster",
+                      "type": "object"
+                    }
+                  }
+                }
+              },
+              "application/xml": {
+                "schema": {
+                  "$ref": "#/components/schemas/toaster_toaster"
+                }
+              }
+            }
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "GET - Controller - toaster - toaster"
+      },
+      "put": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "toaster:toaster": {
+                    "$ref": "#/components/schemas/toaster_toaster",
+                    "type": "object"
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "Updated"
+          },
+          "201": {
+            "description": "Created"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "PUT - toaster - Controller - toaster"
+      },
+      "post": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/json": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.\n\nNote:\nIn example payload, you can see only the first data node child of the resource to be created, following the\nguidelines of RFC 8040, which allows us to create only one resource in POST request.\n",
+        "summary": "POST - Controller - toaster - toaster"
+      },
+      "delete": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "responses": {
+          "204": {
+            "description": "Deleted"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "DELETE - Controller - toaster - toaster"
+      },
+      "patch": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/yang-data+xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            },
+            "application/yang-data+json": {
+              "schema": {
+                "properties": {
+                  "toaster:toaster": {
+                    "$ref": "#/components/schemas/toaster_toaster",
+                    "type": "object"
+                  }
+                }
+              }
+            }
+          }
+        },
+        "responses": {
+          "200": {
+            "description": "OK"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "PATCH - toaster - Controller - toaster"
+      }
+    },
+    "/rests/operations/toaster:make-toast": {
+      "post": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "make-toast_input",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "$ref": "#/components/schemas/toaster_make-toast_input",
+                    "type": "object"
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_make-toast_input"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC make-toast success"
+          }
+        },
+        "description": "Make some toast.\nThe toastDone notification will be sent when\nthe toast is finished.\nAn 'in-use' error will be returned if toast\nis already being made.\nA 'resource-denied' error will be returned\nif the toaster service is disabled.",
+        "summary": "POST - Controller - toaster - make-toast"
+      }
+    },
+    "/rests/operations/toaster:restock-toaster": {
+      "post": {
+        "tags": [
+          "Controller toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "restock-toaster_input",
+          "content": {
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "$ref": "#/components/schemas/toaster_restock-toaster_input",
+                    "type": "object"
+                  }
+                }
+              }
+            },
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_restock-toaster_input"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC restock-toaster success"
+          }
+        },
+        "description": "Restocks the toaster with the amount of bread specified.",
+        "summary": "POST - Controller - toaster - restock-toaster"
+      }
+    }
+  },
+  "components": {
+    "schemas": {
+      "hash-brown": {
+        "enum": [
+          "hash-brown"
+        ],
+        "description": "Hash browned potatos.",
+        "title": "hash-brown",
+        "type": "string"
+      },
+      "toaster_make-toast_input": {
+        "properties": {
+          "toasterDoneness": {
+            "default": 5,
+            "description": "This variable controls how well-done is the\nensuing toast. It should be on a scale of 1 to 10.\nToast made at 10 generally is considered unfit\nfor human consumption; toast made at 1 is warmed\nlightly.",
+            "type": "integer",
+            "example": 1,
+            "format": "int64"
+          },
+          "toasterToastType": {
+            "$ref": "#/components/schemas/toast-type"
+          }
+        },
+        "xml": {
+          "name": "input"
+        },
+        "title": "toaster_make-toast_input",
+        "type": "object"
+      },
+      "toast-type": {
+        "enum": [
+          "toast-type",
+          "white-bread",
+          "wonder-bread",
+          "hash-brown",
+          "frozen-waffle",
+          "wheat-bread",
+          "frozen-bagel"
+        ],
+        "description": "Base for all bread types supported by the toaster.\nNew bread types not listed here nay be added in the\nfuture.",
+        "title": "toast-type",
+        "type": "string"
+      },
+      "toaster_module": {
+        "properties": {
+          "toaster": {
+            "$ref": "#/components/schemas/toaster_toaster"
+          }
+        },
+        "description": "YANG version of the TOASTER-MIB.",
+        "title": "toaster_module",
+        "type": "object"
+      },
+      "frozen-bagel": {
+        "enum": [
+          "frozen-bagel"
+        ],
+        "description": "Frozen bagel.",
+        "title": "frozen-bagel",
+        "type": "string"
+      },
+      "toaster_restock-toaster_input": {
+        "properties": {
+          "amountOfBreadToStock": {
+            "description": "Indicates the amount of bread to re-stock",
+            "type": "integer",
+            "example": 0,
+            "format": "int64"
+          }
+        },
+        "xml": {
+          "name": "input"
+        },
+        "title": "toaster_restock-toaster_input",
+        "type": "object"
+      },
+      "frozen-waffle": {
+        "enum": [
+          "frozen-waffle"
+        ],
+        "description": "Frozen waffle.",
+        "title": "frozen-waffle",
+        "type": "string"
+      },
+      "white-bread": {
+        "enum": [
+          "white-bread"
+        ],
+        "description": "White bread.",
+        "title": "white-bread",
+        "type": "string"
+      },
+      "wheat-bread": {
+        "enum": [
+          "wheat-bread"
+        ],
+        "description": "Wheat bread.",
+        "title": "wheat-bread",
+        "type": "string"
+      },
+      "wonder-bread": {
+        "enum": [
+          "wonder-bread"
+        ],
+        "description": "Wonder bread.",
+        "title": "wonder-bread",
+        "type": "string"
+      },
+      "toaster_toaster": {
+        "properties": {
+          "darknessFactor": {
+            "default": 1000,
+            "description": "The darkness factor. Basically, the number of ms to multiple the doneness value by.",
+            "type": "integer",
+            "example": 0,
+            "format": "int64"
+          }
+        },
+        "xml": {
+          "name": "toaster",
+          "namespace": "http://netconfcentral.org/ns/toaster"
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "title": "toaster_toaster",
+        "type": "object"
+      }
+    },
+    "securitySchemes": {
+      "basicAuth": {
+        "scheme": "basic",
+        "type": "http"
+      }
+    }
+  },
+  "security": [
+    {
+      "basicAuth": []
+    }
+  ]
+}
diff --git a/restconf/restconf-openapi/src/test/resources/openapi-document/device-all.json b/restconf/restconf-openapi/src/test/resources/openapi-document/device-all.json
new file mode 100644 (file)
index 0000000..0a40535
--- /dev/null
@@ -0,0 +1,439 @@
+{
+  "openapi": "3.0.3",
+  "info": {
+    "version": "1.0.0",
+    "title": "123 modules of RESTCONF",
+    "description": "We are providing full API for configurational data which can be edited (by POST, PUT, PATCH and DELETE).\nFor operational data we only provide GET API.\n\nFor majority of request you can see only config data in examples. That’s because we can show only one example\nper request. The exception when you can see operational data in example is when data are representing\noperational (config false) container with no config data in it."
+  },
+  "servers": [
+    {
+      "url": "http://localhost:8181/"
+    }
+  ],
+  "paths": {
+    "/rests/operations/nodes/node=123/yang-ext:mount/toaster:make-toast": {
+      "post": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "make-toast_input",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_make-toast_input"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "$ref": "#/components/schemas/toaster_make-toast_input",
+                    "type": "object"
+                  }
+                }
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC make-toast success"
+          }
+        },
+        "description": "Make some toast.\nThe toastDone notification will be sent when\nthe toast is finished.\nAn 'in-use' error will be returned if toast\nis already being made.\nA 'resource-denied' error will be returned\nif the toaster service is disabled.",
+        "summary": "POST - 123 - toaster - make-toast"
+      }
+    },
+    "/rests/operations/nodes/node=123/yang-ext:mount": {
+      "get": {
+        "tags": [
+          "123 GET root"
+        ],
+        "responses": {
+          "200": {
+            "description": "OK"
+          }
+        },
+        "description": "Queries the available operations (RPC calls) on the mounted hosted.",
+        "summary": "GET - 123 - datastore - operations"
+      }
+    },
+    "/rests/data/nodes/node=123/yang-ext:mount/toaster:toaster": {
+      "get": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [
+          {
+            "name": "content",
+            "in": "query",
+            "required": false,
+            "schema": {
+              "enum": [
+                "config",
+                "nonconfig",
+                "all"
+              ],
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "200",
+            "content": {
+              "application/xml": {
+                "schema": {
+                  "$ref": "#/components/schemas/toaster_toaster"
+                }
+              },
+              "application/json": {
+                "schema": {
+                  "properties": {
+                    "toaster": {
+                      "$ref": "#/components/schemas/toaster_toaster",
+                      "type": "object"
+                    }
+                  }
+                }
+              }
+            }
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "GET - 123 - toaster - toaster"
+      },
+      "put": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "toaster:toaster": {
+                    "$ref": "#/components/schemas/toaster_toaster",
+                    "type": "object"
+                  }
+                }
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "PUT - toaster - 123 - toaster"
+      },
+      "post": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.\n\nNote:\nIn example payload, you can see only the first data node child of the resource to be created, following the\nguidelines of RFC 8040, which allows us to create only one resource in POST request.\n",
+        "summary": "POST - 123 - toaster - toaster"
+      },
+      "delete": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "responses": {
+          "204": {
+            "description": "Deleted"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "DELETE - 123 - toaster - toaster"
+      },
+      "patch": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/yang-data+json": {
+              "schema": {
+                "properties": {
+                  "toaster:toaster": {
+                    "$ref": "#/components/schemas/toaster_toaster",
+                    "type": "object"
+                  }
+                }
+              }
+            },
+            "application/yang-data+xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "Updated"
+          },
+          "200": {
+            "description": "OK"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "PATCH - toaster - 123 - toaster"
+      }
+    },
+    "/rests/operations/nodes/node=123/yang-ext:mount/toaster:restock-toaster": {
+      "post": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "restock-toaster_input",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_restock-toaster_input"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "$ref": "#/components/schemas/toaster_restock-toaster_input",
+                    "type": "object"
+                  }
+                }
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC restock-toaster success"
+          }
+        },
+        "description": "Restocks the toaster with the amount of bread specified.",
+        "summary": "POST - 123 - toaster - restock-toaster"
+      }
+    },
+    "/rests/data/nodes/node=123/yang-ext:mount": {
+      "get": {
+        "tags": [
+          "123 GET root"
+        ],
+        "responses": {
+          "200": {
+            "description": "OK"
+          }
+        },
+        "description": "Queries the config (startup) datastore on the mounted hosted.",
+        "summary": "GET - 123 - datastore - data"
+      }
+    },
+    "/rests/operations/nodes/node=123/yang-ext:mount/toaster:cancel-toast": {
+      "post": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "cancel-toast_input",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "xml": {
+                  "name": "input"
+                },
+                "type": "object"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "type": "object"
+                  }
+                },
+                "type": "object"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC cancel-toast success"
+          }
+        },
+        "description": "Stop making toast, if any is being made.\nA 'resource-denied' error will be returned\nif the toaster service is disabled.",
+        "summary": "POST - 123 - toaster - cancel-toast"
+      }
+    }
+  },
+  "components": {
+    "schemas": {
+      "hash-brown": {
+        "enum": [
+          "hash-brown"
+        ],
+        "description": "Hash browned potatos.",
+        "title": "hash-brown",
+        "type": "string"
+      },
+      "toaster_make-toast_input": {
+        "properties": {
+          "toasterDoneness": {
+            "default": 5,
+            "description": "This variable controls how well-done is the\nensuing toast. It should be on a scale of 1 to 10.\nToast made at 10 generally is considered unfit\nfor human consumption; toast made at 1 is warmed\nlightly.",
+            "type": "integer",
+            "example": 1,
+            "format": "int64"
+          },
+          "toasterToastType": {
+            "$ref": "#/components/schemas/toast-type"
+          }
+        },
+        "xml": {
+          "name": "input"
+        },
+        "title": "toaster_make-toast_input",
+        "type": "object"
+      },
+      "toast-type": {
+        "enum": [
+          "toast-type",
+          "hash-brown",
+          "white-bread",
+          "frozen-waffle",
+          "wheat-bread",
+          "wonder-bread",
+          "frozen-bagel"
+        ],
+        "description": "Base for all bread types supported by the toaster.\nNew bread types not listed here nay be added in the\nfuture.",
+        "title": "toast-type",
+        "type": "string"
+      },
+      "frozen-bagel": {
+        "enum": [
+          "frozen-bagel"
+        ],
+        "description": "Frozen bagel.",
+        "title": "frozen-bagel",
+        "type": "string"
+      },
+      "toaster_restock-toaster_input": {
+        "properties": {
+          "amountOfBreadToStock": {
+            "description": "Indicates the amount of bread to re-stock",
+            "type": "integer",
+            "example": 0,
+            "format": "int64"
+          }
+        },
+        "xml": {
+          "name": "input"
+        },
+        "title": "toaster_restock-toaster_input",
+        "type": "object"
+      },
+      "frozen-waffle": {
+        "enum": [
+          "frozen-waffle"
+        ],
+        "description": "Frozen waffle.",
+        "title": "frozen-waffle",
+        "type": "string"
+      },
+      "white-bread": {
+        "enum": [
+          "white-bread"
+        ],
+        "description": "White bread.",
+        "title": "white-bread",
+        "type": "string"
+      },
+      "wheat-bread": {
+        "enum": [
+          "wheat-bread"
+        ],
+        "description": "Wheat bread.",
+        "title": "wheat-bread",
+        "type": "string"
+      },
+      "wonder-bread": {
+        "enum": [
+          "wonder-bread"
+        ],
+        "description": "Wonder bread.",
+        "title": "wonder-bread",
+        "type": "string"
+      },
+      "toaster_toaster": {
+        "properties": {
+          "darknessFactor": {
+            "default": 1000,
+            "description": "The darkness factor. Basically, the number of ms to multiple the doneness value by.",
+            "type": "integer",
+            "example": 0,
+            "format": "int64"
+          }
+        },
+        "xml": {
+          "name": "toaster",
+          "namespace": "http://netconfcentral.org/ns/toaster"
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "title": "toaster_toaster",
+        "type": "object"
+      }
+    },
+    "securitySchemes": {
+      "basicAuth": {
+        "scheme": "basic",
+        "type": "http"
+      }
+    }
+  },
+  "security": [
+    {
+      "basicAuth": []
+    }
+  ]
+}
diff --git a/restconf/restconf-openapi/src/test/resources/openapi-document/device-toaster.json b/restconf/restconf-openapi/src/test/resources/openapi-document/device-toaster.json
new file mode 100644 (file)
index 0000000..4353b7d
--- /dev/null
@@ -0,0 +1,451 @@
+{
+  "openapi": "3.0.3",
+  "info": {
+    "version": "1.0.0",
+    "title": "toaster",
+    "description": "We are providing full API for configurational data which can be edited (by POST, PUT, PATCH and DELETE).\nFor operational data we only provide GET API.\n\nFor majority of request you can see only config data in examples. That’s because we can show only one example\nper request. The exception when you can see operational data in example is when data are representing\noperational (config false) container with no config data in it."
+  },
+  "servers": [
+    {
+      "url": "http://localhost:8181/"
+    }
+  ],
+  "paths": {
+    "/rests/operations/nodes/node=123/yang-ext:mount/toaster:make-toast": {
+      "post": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "make-toast_input",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_make-toast_input"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "$ref": "#/components/schemas/toaster_make-toast_input",
+                    "type": "object"
+                  }
+                }
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC make-toast success"
+          }
+        },
+        "description": "Make some toast.\nThe toastDone notification will be sent when\nthe toast is finished.\nAn 'in-use' error will be returned if toast\nis already being made.\nA 'resource-denied' error will be returned\nif the toaster service is disabled.",
+        "summary": "POST - 123 - toaster - make-toast"
+      }
+    },
+    "/rests/data/nodes/node=123/yang-ext:mount/toaster:toaster": {
+      "get": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [
+          {
+            "name": "content",
+            "in": "query",
+            "required": false,
+            "schema": {
+              "enum": [
+                "config",
+                "nonconfig",
+                "all"
+              ],
+              "type": "string"
+            }
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "200",
+            "content": {
+              "application/xml": {
+                "schema": {
+                  "$ref": "#/components/schemas/toaster_toaster"
+                }
+              },
+              "application/json": {
+                "schema": {
+                  "properties": {
+                    "toaster": {
+                      "$ref": "#/components/schemas/toaster_toaster",
+                      "type": "object"
+                    }
+                  }
+                }
+              }
+            }
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "GET - 123 - toaster - toaster"
+      },
+      "put": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "toaster:toaster": {
+                    "$ref": "#/components/schemas/toaster_toaster",
+                    "type": "object"
+                  }
+                }
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          },
+          "204": {
+            "description": "Updated"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "PUT - toaster - 123 - toaster"
+      },
+      "post": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.\n\nNote:\nIn example payload, you can see only the first data node child of the resource to be created, following the\nguidelines of RFC 8040, which allows us to create only one resource in POST request.\n",
+        "summary": "POST - 123 - toaster - toaster"
+      },
+      "delete": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "responses": {
+          "204": {
+            "description": "Deleted"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "DELETE - 123 - toaster - toaster"
+      },
+      "patch": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster",
+          "content": {
+            "application/yang-data+json": {
+              "schema": {
+                "properties": {
+                  "toaster:toaster": {
+                    "$ref": "#/components/schemas/toaster_toaster",
+                    "type": "object"
+                  }
+                }
+              }
+            },
+            "application/yang-data+xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_toaster"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "Updated"
+          },
+          "200": {
+            "description": "OK"
+          }
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "summary": "PATCH - toaster - 123 - toaster"
+      }
+    },
+    "/rests/operations/nodes/node=123/yang-ext:mount/toaster:cancel-toast": {
+      "post": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "cancel-toast_input",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "xml": {
+                  "name": "input"
+                },
+                "type": "object"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "type": "object"
+                  }
+                },
+                "type": "object"
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC cancel-toast success"
+          }
+        },
+        "description": "Stop making toast, if any is being made.\nA 'resource-denied' error will be returned\nif the toaster service is disabled.",
+        "summary": "POST - 123 - toaster - cancel-toast"
+      }
+    },
+    "/rests/operations/nodes/node=123/yang-ext:mount/toaster:restock-toaster": {
+      "post": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "restock-toaster_input",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_restock-toaster_input"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "properties": {
+                  "input": {
+                    "$ref": "#/components/schemas/toaster_restock-toaster_input",
+                    "type": "object"
+                  }
+                }
+              }
+            }
+          }
+        },
+        "responses": {
+          "204": {
+            "description": "RPC restock-toaster success"
+          }
+        },
+        "description": "Restocks the toaster with the amount of bread specified.",
+        "summary": "POST - 123 - toaster - restock-toaster"
+      }
+    },
+    "/rests/data/nodes/node=123/yang-ext:mount": {
+      "post": {
+        "tags": [
+          "123 toaster"
+        ],
+        "parameters": [],
+        "requestBody": {
+          "description": "toaster_module",
+          "content": {
+            "application/xml": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_module"
+              }
+            },
+            "application/json": {
+              "schema": {
+                "$ref": "#/components/schemas/toaster_module"
+              }
+            }
+          }
+        },
+        "responses": {
+          "201": {
+            "description": "Created"
+          }
+        },
+        "description": "YANG version of the TOASTER-MIB.\n\nNote:\nIn example payload, you can see only the first data node child of the resource to be created, following the\nguidelines of RFC 8040, which allows us to create only one resource in POST request.\n",
+        "summary": "POST - 123 - toaster - toaster_module"
+      }
+    }
+  },
+  "components": {
+    "schemas": {
+      "hash-brown": {
+        "enum": [
+          "hash-brown"
+        ],
+        "description": "Hash browned potatos.",
+        "title": "hash-brown",
+        "type": "string"
+      },
+      "toaster_make-toast_input": {
+        "properties": {
+          "toasterDoneness": {
+            "default": 5,
+            "description": "This variable controls how well-done is the\nensuing toast. It should be on a scale of 1 to 10.\nToast made at 10 generally is considered unfit\nfor human consumption; toast made at 1 is warmed\nlightly.",
+            "type": "integer",
+            "example": 1,
+            "format": "int64"
+          },
+          "toasterToastType": {
+            "$ref": "#/components/schemas/toast-type"
+          }
+        },
+        "xml": {
+          "name": "input"
+        },
+        "title": "toaster_make-toast_input",
+        "type": "object"
+      },
+      "toast-type": {
+        "enum": [
+          "toast-type",
+          "wonder-bread",
+          "frozen-waffle",
+          "frozen-bagel",
+          "hash-brown",
+          "white-bread",
+          "wheat-bread"
+        ],
+        "description": "Base for all bread types supported by the toaster.\nNew bread types not listed here nay be added in the\nfuture.",
+        "title": "toast-type",
+        "type": "string"
+      },
+      "toaster_module": {
+        "properties": {
+          "toaster": {
+            "$ref": "#/components/schemas/toaster_toaster"
+          }
+        },
+        "description": "YANG version of the TOASTER-MIB.",
+        "title": "toaster_module",
+        "type": "object"
+      },
+      "frozen-bagel": {
+        "enum": [
+          "frozen-bagel"
+        ],
+        "description": "Frozen bagel.",
+        "title": "frozen-bagel",
+        "type": "string"
+      },
+      "toaster_restock-toaster_input": {
+        "properties": {
+          "amountOfBreadToStock": {
+            "description": "Indicates the amount of bread to re-stock",
+            "type": "integer",
+            "example": 0,
+            "format": "int64"
+          }
+        },
+        "xml": {
+          "name": "input"
+        },
+        "title": "toaster_restock-toaster_input",
+        "type": "object"
+      },
+      "frozen-waffle": {
+        "enum": [
+          "frozen-waffle"
+        ],
+        "description": "Frozen waffle.",
+        "title": "frozen-waffle",
+        "type": "string"
+      },
+      "white-bread": {
+        "enum": [
+          "white-bread"
+        ],
+        "description": "White bread.",
+        "title": "white-bread",
+        "type": "string"
+      },
+      "wheat-bread": {
+        "enum": [
+          "wheat-bread"
+        ],
+        "description": "Wheat bread.",
+        "title": "wheat-bread",
+        "type": "string"
+      },
+      "wonder-bread": {
+        "enum": [
+          "wonder-bread"
+        ],
+        "description": "Wonder bread.",
+        "title": "wonder-bread",
+        "type": "string"
+      },
+      "toaster_toaster": {
+        "properties": {
+          "darknessFactor": {
+            "default": 1000,
+            "description": "The darkness factor. Basically, the number of ms to multiple the doneness value by.",
+            "type": "integer",
+            "example": 0,
+            "format": "int64"
+          }
+        },
+        "xml": {
+          "name": "toaster",
+          "namespace": "http://netconfcentral.org/ns/toaster"
+        },
+        "description": "Top-level container for all toaster database objects.",
+        "title": "toaster_toaster",
+        "type": "object"
+      }
+    },
+    "securitySchemes": {
+      "basicAuth": {
+        "scheme": "basic",
+        "type": "http"
+      }
+    }
+  },
+  "security": [
+    {
+      "basicAuth": []
+    }
+  ]
+}
diff --git a/restconf/restconf-openapi/src/test/resources/openapi-document/toaster.yang b/restconf/restconf-openapi/src/test/resources/openapi-document/toaster.yang
new file mode 100644 (file)
index 0000000..3eac91c
--- /dev/null
@@ -0,0 +1,199 @@
+module toaster {
+
+  yang-version 1;
+
+  namespace
+    "http://netconfcentral.org/ns/toaster";
+
+  prefix toast;
+
+  organization "Netconf Central";
+
+  contact
+    "Andy Bierman <andy@netconfcentral.org>";
+
+  description
+    "YANG version of the TOASTER-MIB.";
+
+  revision "2009-11-20" {
+    description
+      "Toaster module in progress.";
+  }
+
+  identity toast-type {
+    description
+      "Base for all bread types supported by the toaster.
+      New bread types not listed here nay be added in the
+      future.";
+  }
+
+  identity white-bread {
+    base toast:toast-type;
+    description "White bread.";
+  }
+
+  identity wheat-bread {
+    base toast-type;
+    description "Wheat bread.";
+  }
+
+  identity wonder-bread {
+    base toast-type;
+    description "Wonder bread.";
+  }
+
+  identity frozen-waffle {
+    base toast-type;
+    description "Frozen waffle.";
+  }
+
+  identity frozen-bagel {
+    base toast-type;
+    description "Frozen bagel.";
+  }
+
+  identity hash-brown {
+    base toast-type;
+    description "Hash browned potatos.";
+  }
+
+  typedef DisplayString {
+    type string {
+      length "0 .. 255";
+    }
+    description
+      "YANG version of the SMIv2 DisplayString TEXTUAL-CONVENTION.";
+    reference
+      "RFC 2579, section 2.";
+
+  }
+
+  container toaster {
+    presence
+    "Indicates the toaster service is available";
+    description
+      "Top-level container for all toaster database objects.";
+    leaf toasterManufacturer {
+      type DisplayString;
+      config false;
+      mandatory true;
+      description
+        "The name of the toaster's manufacturer. For instance,
+        Microsoft Toaster.";
+    }
+
+    leaf toasterModelNumber {
+      type DisplayString;
+      config false;
+      mandatory true;
+      description
+        "The name of the toaster's model. For instance,
+        Radiant Automatic.";
+    }
+
+    leaf toasterStatus {
+      type enumeration {
+        enum "up" {
+          value 1;
+          description
+            "The toaster knob position is up.
+            No toast is being made now.";
+        }
+        enum "down" {
+          value 2;
+          description
+            "The toaster knob position is down.
+            Toast is being made now.";
+        }
+      }
+      config false;
+      mandatory true;
+      description
+        "This variable indicates the current state of
+        the toaster.";
+    }
+
+    leaf darknessFactor {
+      type uint32;
+      config true;
+      default 1000;
+      description
+        "The darkness factor. Basically, the number of ms to multiple the doneness value by.";
+    }
+  } // container toaster
+
+  rpc make-toast {
+    description
+      "Make some toast.
+      The toastDone notification will be sent when
+      the toast is finished.
+      An 'in-use' error will be returned if toast
+      is already being made.
+      A 'resource-denied' error will be returned
+      if the toaster service is disabled.";
+    input {
+      leaf toasterDoneness {
+        type uint32 {
+          range "1 .. 10";
+        }
+        default '5';
+        description
+          "This variable controls how well-done is the
+          ensuing toast. It should be on a scale of 1 to 10.
+          Toast made at 10 generally is considered unfit
+          for human consumption; toast made at 1 is warmed
+          lightly.";
+      }
+
+      leaf toasterToastType {
+        type identityref {
+          base toast:toast-type;
+        }
+        default 'wheat-bread';
+        description
+          "This variable informs the toaster of the type of
+          material that is being toasted. The toaster
+          uses this information, combined with
+          toasterDoneness, to compute for how
+          long the material must be toasted to achieve
+          the required doneness.";
+      }
+    }
+  } // rpc make-toast
+
+  rpc cancel-toast {
+    description
+      "Stop making toast, if any is being made.
+      A 'resource-denied' error will be returned
+      if the toaster service is disabled.";
+  } // rpc cancel-toast
+
+  rpc restock-toaster {
+    description
+      "Restocks the toaster with the amount of bread specified.";
+
+    input {
+      leaf amountOfBreadToStock {
+        type uint32;
+        description
+          "Indicates the amount of bread to re-stock";
+      }
+    }
+  }
+
+  notification toasterOutOfBread {
+    description
+      "Indicates that the toaster has run of out bread.";
+  } // notification toasterOutOfStock
+
+  notification toasterRestocked {
+    description
+      "Indicates that the toaster has run of out bread.";
+    leaf amountOfBread {
+      type uint32;
+      description
+        "Indicates the amount of bread that was re-stocked";
+    }
+  } // notification toasterOutOfStock
+
+} // module toaster