Change getPathParameters into getPathGetParameters and add
getPathPostParameters.
We assume that all paths present in OpenApi should have at least
GET example in the documentation.
Thus we can use GET operation as a base operation to get number of
parameters in path. We just need to drop 'content' parameter.
For actions and RPCs we can use getPathPostParameters method.
JIRA: NETCONF-1101
Change-Id: I2a0a24a5a567d7dd95b7adf6ec13dddb391fab51
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
Signed-off-by: Samuel Schneider <samuel.schneider@pantheon.tech>
(cherry picked from commit
88403faca52518bc4d9674190f17fe934e6f23d1)
URI_INFO = DocGenTestHelper.createMockUriInfo("http://localhost/path");
}
URI_INFO = DocGenTestHelper.createMockUriInfo("http://localhost/path");
}
- protected static List<String> getPathParameters(final ObjectNode paths, final String path) {
+ protected static List<String> getPathPostParameters(final ObjectNode paths, final String path) {
final var params = new ArrayList<String>();
paths.get(path).get("post").get("parameters").elements()
.forEachRemaining(p -> params.add(p.get("name").asText()));
return params;
}
final var params = new ArrayList<String>();
paths.get(path).get("post").get("parameters").elements()
.forEachRemaining(p -> params.add(p.get("name").asText()));
return params;
}
+
+ /**
+ * Get path parameters names for {@code path} for GET operation.
+ *
+ * @return {@link List} of parameters excluding `content` parameter
+ */
+ public static List<String> getPathGetParameters(final ObjectNode paths, final String path) {
+ final var params = new ArrayList<String>();
+ paths.get(path).get("get").get("parameters").elements()
+ .forEachRemaining(p -> {
+ final String name = p.get("name").asText();
+ if (!"content".equals(name)) {
+ params.add(name);
+ }
+ });
+ return params;
+ }
var pathToList1 = "/rests/data/path-params-test:cont/list1={name}";
assertTrue(doc.getPaths().has(pathToList1));
var pathToList1 = "/rests/data/path-params-test:cont/list1={name}";
assertTrue(doc.getPaths().has(pathToList1));
- assertEquals(List.of("name"), getPathParameters(doc.getPaths(), pathToList1));
+ assertEquals(List.of("name"), getPathGetParameters(doc.getPaths(), pathToList1));
var pathToList2 = "/rests/data/path-params-test:cont/list1={name}/list2={name1}";
assertTrue(doc.getPaths().has(pathToList2));
var pathToList2 = "/rests/data/path-params-test:cont/list1={name}/list2={name1}";
assertTrue(doc.getPaths().has(pathToList2));
- assertEquals(List.of("name", "name1"), getPathParameters(doc.getPaths(), pathToList2));
+ assertEquals(List.of("name", "name1"), getPathGetParameters(doc.getPaths(), pathToList2));
var pathToList3 = "/rests/data/path-params-test:cont/list3={name}";
assertTrue(doc.getPaths().has(pathToList3));
var pathToList3 = "/rests/data/path-params-test:cont/list3={name}";
assertTrue(doc.getPaths().has(pathToList3));
- assertEquals(List.of("name"), getPathParameters(doc.getPaths(), pathToList3));
+ assertEquals(List.of("name"), getPathGetParameters(doc.getPaths(), pathToList3));
var pathToList4 = "/rests/data/path-params-test:cont/list1={name}/list4={name1}";
assertTrue(doc.getPaths().has(pathToList4));
var pathToList4 = "/rests/data/path-params-test:cont/list1={name}/list4={name1}";
assertTrue(doc.getPaths().has(pathToList4));
- assertEquals(List.of("name", "name1"), getPathParameters(doc.getPaths(), pathToList4));
+ assertEquals(List.of("name", "name1"), getPathGetParameters(doc.getPaths(), pathToList4));
var pathToList5 = "/rests/data/path-params-test:cont/list1={name}/cont2";
assertTrue(doc.getPaths().has(pathToList4));
var pathToList5 = "/rests/data/path-params-test:cont/list1={name}/cont2";
assertTrue(doc.getPaths().has(pathToList4));
- assertEquals(List.of("name"), getPathParameters(doc.getPaths(), pathToList5));
+ assertEquals(List.of("name"), getPathGetParameters(doc.getPaths(), pathToList5));
}
private static void verifyThatPropertyDoesNotHaveRequired(final List<String> expected,
}
private static void verifyThatPropertyDoesNotHaveRequired(final List<String> expected,
final var pathWithParameters = "/rests/operations/action-types:list={name}/list-action";
assertTrue(doc.getPaths().has(pathWithParameters));
final var pathWithParameters = "/rests/operations/action-types:list={name}/list-action";
assertTrue(doc.getPaths().has(pathWithParameters));
- assertEquals(List.of("name"), getPathParameters(doc.getPaths(), pathWithParameters));
+ assertEquals(List.of("name"), getPathPostParameters(doc.getPaths(), pathWithParameters));
final var pathWithoutParameters = "/rests/operations/action-types:multi-container/inner-container/action";
assertTrue(doc.getPaths().has(pathWithoutParameters));
final var pathWithoutParameters = "/rests/operations/action-types:multi-container/inner-container/action";
assertTrue(doc.getPaths().has(pathWithoutParameters));
- assertEquals(List.of(), getPathParameters(doc.getPaths(), pathWithoutParameters));
+ assertEquals(List.of(), getPathPostParameters(doc.getPaths(), pathWithoutParameters));
var pathToList1 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list1={name}";
assertTrue(mountPointApi.getPaths().has(pathToList1));
var pathToList1 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list1={name}";
assertTrue(mountPointApi.getPaths().has(pathToList1));
- assertEquals(List.of("name"), getPathParameters(mountPointApi.getPaths(), pathToList1));
+ assertEquals(List.of("name"), getPathGetParameters(mountPointApi.getPaths(), pathToList1));
var pathToList2 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list1={name}/list2={name1}";
assertTrue(mountPointApi.getPaths().has(pathToList2));
var pathToList2 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list1={name}/list2={name1}";
assertTrue(mountPointApi.getPaths().has(pathToList2));
- assertEquals(List.of("name", "name1"), getPathParameters(mountPointApi.getPaths(), pathToList2));
+ assertEquals(List.of("name", "name1"), getPathGetParameters(mountPointApi.getPaths(), pathToList2));
var pathToList3 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list3={name}";
assertTrue(mountPointApi.getPaths().has(pathToList3));
var pathToList3 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list3={name}";
assertTrue(mountPointApi.getPaths().has(pathToList3));
- assertEquals(List.of("name"), getPathParameters(mountPointApi.getPaths(), pathToList3));
+ assertEquals(List.of("name"), getPathGetParameters(mountPointApi.getPaths(), pathToList3));
var pathToList4 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list1={name}/list4={name1}";
assertTrue(mountPointApi.getPaths().has(pathToList4));
var pathToList4 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list1={name}/list4={name1}";
assertTrue(mountPointApi.getPaths().has(pathToList4));
- assertEquals(List.of("name", "name1"), getPathParameters(mountPointApi.getPaths(), pathToList4));
+ assertEquals(List.of("name", "name1"), getPathGetParameters(mountPointApi.getPaths(), pathToList4));
var pathToList5 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list1={name}/cont2";
assertTrue(mountPointApi.getPaths().has(pathToList5));
var pathToList5 = "/rests/data/nodes/node=123/yang-ext:mount/path-params-test:cont/list1={name}/cont2";
assertTrue(mountPointApi.getPaths().has(pathToList5));
- assertEquals(List.of("name"), getPathParameters(mountPointApi.getPaths(), pathToList5));
+ assertEquals(List.of("name"), getPathGetParameters(mountPointApi.getPaths(), pathToList5));
final var pathWithParameters =
"/rests/operations/nodes/node=123/yang-ext:mount/action-types:list={name}/list-action";
assertTrue(mountPointApi.getPaths().has(pathWithParameters));
final var pathWithParameters =
"/rests/operations/nodes/node=123/yang-ext:mount/action-types:list={name}/list-action";
assertTrue(mountPointApi.getPaths().has(pathWithParameters));
- assertEquals(List.of("name"), getPathParameters(mountPointApi.getPaths(), pathWithParameters));
+ assertEquals(List.of("name"), getPathPostParameters(mountPointApi.getPaths(), pathWithParameters));
final var pathWithoutParameters =
"/rests/operations/nodes/node=123/yang-ext:mount/action-types:multi-container/inner-container/action";
assertTrue(mountPointApi.getPaths().has(pathWithoutParameters));
final var pathWithoutParameters =
"/rests/operations/nodes/node=123/yang-ext:mount/action-types:multi-container/inner-container/action";
assertTrue(mountPointApi.getPaths().has(pathWithoutParameters));
- assertEquals(List.of(), getPathParameters(mountPointApi.getPaths(), pathWithoutParameters));
+ assertEquals(List.of(), getPathPostParameters(mountPointApi.getPaths(), pathWithoutParameters));