processTypeDef(listNode.getType(), listNode, itemsVal, stack);
- props.items(itemsVal.build());
+ final Property itemsValue = itemsVal.build();
+ final Property propsValue = props.build();
+ props.items(itemsValue);
+
+ if (itemsValue.example() != null && propsValue.minItems() != null) {
+ final List<Object> listOfExamples = new ArrayList<>();
+ for (int i = 0; i < propsValue.minItems(); i++) {
+ listOfExamples.add(itemsValue.example());
+ }
+ props.example(listOfExamples);
+ }
props.description(listNode.getDescription().orElse(""));
return props.build();
assertEquals("urn:ietf:params:xml:ns:yang:test:action:types", namespace);
}
+ /**
+ * Test that number of elements in payload is correct.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testLeafListWithMinElementsPayload() {
+ final var doc = generator.getApiDeclaration(MANDATORY_TEST, null, uriInfo);
+ assertNotNull(doc);
+ final var paths = doc.paths();
+ final var path = paths.get("/rests/data/mandatory-test:root-container/mandatory-container");
+ assertNotNull(path);
+ final var requestBody = path.put().requestBody().content();
+ assertNotNull(requestBody);
+ final var jsonRef = requestBody.get("application/json").schema().properties()
+ .get("mandatory-test:mandatory-container").ref();
+ assertNotNull(jsonRef);
+ final var xmlRef = requestBody.get("application/xml").schema().ref();
+ assertNotNull(xmlRef);
+ final var schema = doc.components().schemas().get("mandatory-test_root-container_mandatory-container");
+ assertNotNull(schema);
+ final var minItems = schema.properties().get("leaf-list-with-min-elements").minItems();
+ assertNotNull(minItems);
+ final var listOfExamples = ((List<String>) schema.properties().get("leaf-list-with-min-elements").example());
+ assertNotNull(listOfExamples);
+ assertEquals(jsonRef, xmlRef);
+ assertEquals(listOfExamples.size(), minItems.intValue());
+ }
+
private static void verifyRequestRef(final Operation operation, final String expectedRef, final String nodeType) {
final Map<String, MediaTypeObject> postContent;
if (operation.requestBody() != null) {
assertNotNull(namespace);
assertEquals("urn:ietf:params:xml:ns:yang:test:action:types", namespace);
}
+
+ /**
+ * Test that number of elements in payload is correct.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testLeafListWithMinElementsPayloadOnMountPoint() throws Exception {
+ final var mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
+ openApi.onMountPointCreated(INSTANCE_ID);
+ final var mountPointApi = openApi.getMountPointApi(mockInfo, 1L, null);
+ assertNotNull(mountPointApi);
+ final var paths = mountPointApi.paths();
+ final var path =
+ paths.get("/rests/data/nodes/node=123/yang-ext:mount/mandatory-test:root-container/mandatory-container");
+ assertNotNull(path);
+ final var requestBody = path.put().requestBody().content();
+ assertNotNull(requestBody);
+ final var jsonRef = requestBody.get("application/json").schema().properties()
+ .get("mandatory-test:mandatory-container").ref();
+ assertNotNull(jsonRef);
+ final var xmlRef = requestBody.get("application/xml").schema().ref();
+ assertNotNull(xmlRef);
+ final var schema =
+ mountPointApi.components().schemas().get("mandatory-test_root-container_mandatory-container");
+ assertNotNull(schema);
+ final var minItems = schema.properties().get("leaf-list-with-min-elements").minItems();
+ assertNotNull(minItems);
+ final var listOfExamples = ((List<String>) schema.properties().get("leaf-list-with-min-elements").example());
+ assertNotNull(listOfExamples);
+ assertEquals(jsonRef, xmlRef);
+ assertEquals(listOfExamples.size(), minItems.intValue());
+ }
}