X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-docgen%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fdoc%2Fmodel%2Fbuilder%2FOperationBuilder.java;h=38c5f7264adf0a8551382c91b8e557d2013df0ac;hp=9a33ee31b371cb99febb084da4198f83e74fa97c;hb=8f74013feeb888c639d1d4998b0b3bf26b23b9f7;hpb=81bbe76bd26399118d028663d08e464ce6b7d040 diff --git a/opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/model/builder/OperationBuilder.java b/opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/model/builder/OperationBuilder.java index 9a33ee31b3..38c5f7264a 100644 --- a/opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/model/builder/OperationBuilder.java +++ b/opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/model/builder/OperationBuilder.java @@ -9,27 +9,23 @@ package org.opendaylight.controller.sal.rest.doc.model.builder; import java.util.ArrayList; import java.util.List; - import org.opendaylight.controller.sal.rest.doc.swagger.Operation; import org.opendaylight.controller.sal.rest.doc.swagger.Parameter; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; +import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -/** - * - */ public final class OperationBuilder { public static final String OPERATIONAL = "(operational)"; public static final String CONFIG = "(config)"; - /** - * - */ public static class Get { protected Operation spec; protected DataSchemaNode schemaNode; - private final String METHOD_NAME = "GET"; + private static final String METHOD_NAME = "GET"; public Get(DataSchemaNode node, boolean isConfig) { this.schemaNode = node; @@ -51,26 +47,23 @@ public final class OperationBuilder { } } - /** - * - */ public static class Put { protected Operation spec; - protected DataSchemaNode schemaNode; - private final String METHOD_NAME = "PUT"; + protected String nodeName; + private static final String METHOD_NAME = "PUT"; - public Put(DataSchemaNode node) { - this.schemaNode = node; + public Put(String nodeName, final String description) { + this.nodeName = nodeName; spec = new Operation(); - spec.setType(CONFIG + node.getQName().getLocalName()); - spec.setNotes(node.getDescription()); + spec.setType(CONFIG + nodeName); + spec.setNotes(description); } public Put pathParams(List params) { List parameters = new ArrayList<>(params); Parameter payload = new Parameter(); payload.setParamType("body"); - payload.setType(CONFIG + schemaNode.getQName().getLocalName()); + payload.setType(CONFIG + nodeName); parameters.add(payload); spec.setParameters(parameters); return this; @@ -78,35 +71,54 @@ public final class OperationBuilder { public Operation build() { spec.setMethod(METHOD_NAME); - spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName()); + spec.setNickname(METHOD_NAME + "-" + nodeName); return spec; } } - /** - * - */ public static final class Post extends Put { - private final String METHOD_NAME = "POST"; + public static final String METHOD_NAME = "POST"; + private final DataNodeContainer dataNodeContainer; - public Post(DataSchemaNode node) { - super(node); + public Post(final String nodeName, final String description, final DataNodeContainer dataNodeContainer) { + super(nodeName, description); + this.dataNodeContainer = dataNodeContainer; + spec.setType(CONFIG + nodeName + METHOD_NAME); } @Override public Operation build() { spec.setMethod(METHOD_NAME); - spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName()); + spec.setNickname(METHOD_NAME + "-" + nodeName); return spec; } + + @Override + public Put pathParams(List params) { + List parameters = new ArrayList<>(params); + for (DataSchemaNode node : dataNodeContainer.getChildNodes()) { + if (node instanceof ListSchemaNode || node instanceof ContainerSchemaNode) { + Parameter payload = new Parameter(); + payload.setParamType("body"); + payload.setType(CONFIG + node.getQName().getLocalName()); + payload.setName("**"+CONFIG + node.getQName().getLocalName()); + parameters.add(payload); + } + } + spec.setParameters(parameters); + return this; + + } + + public Post summary(final String summary) { + spec.setSummary(summary); + return this; + } } - /** - * - */ public static final class Delete extends Get { - private final String METHOD_NAME = "DELETE"; + private static final String METHOD_NAME = "DELETE"; public Delete(DataSchemaNode node) { super(node, false);