Update swagger generator to OpenAPI 3.0
[netconf.git] / restconf / sal-rest-docgen / src / main / java / org / opendaylight / netconf / sal / rest / doc / util / JsonUtil.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.netconf.sal.rest.doc.util;
10
11 import com.fasterxml.jackson.databind.JsonNode;
12 import com.fasterxml.jackson.databind.node.ArrayNode;
13 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
14 import com.fasterxml.jackson.databind.node.ObjectNode;
15 import java.util.Iterator;
16 import java.util.Map;
17
18 public final class JsonUtil {
19     private JsonUtil() {
20
21     }
22
23     public static ArrayNode copy(ArrayNode source) {
24         ArrayNode result = JsonNodeFactory.instance.arrayNode();
25         for (JsonNode jsonNode : source) {
26             result.add(jsonNode);
27         }
28         return result;
29     }
30
31     public static void addFields(final ObjectNode node, final Iterator<Map.Entry<String, JsonNode>> fields) {
32         while (fields.hasNext()) {
33             final Map.Entry<String, JsonNode> field = fields.next();
34             node.set(field.getKey(), field.getValue());
35         }
36     }
37 }