Bug 931, Bug 910 - Enhance Restconf Swagger Documentation
[controller.git] / opendaylight / md-sal / sal-rest-docgen / src / main / java / org / opendaylight / controller / sal / rest / doc / model / builder / OperationBuilder.java
index fc890d5a2d53de69cf06aa7de91295e369685dc5..9a33ee31b371cb99febb084da4198f83e74fa97c 100644 (file)
  */
 package org.opendaylight.controller.sal.rest.doc.model.builder;
 
  */
 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.DataSchemaNode;
 
 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.DataSchemaNode;
 
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  *
  */
 public final class OperationBuilder {
 
 /**
  *
  */
 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";
-
-    public Get(DataSchemaNode node){
-      this.schemaNode = node;
-      spec = new Operation();
-      spec.setMethod(METHOD_NAME);
-      spec.setNickname(METHOD_NAME + "-" + node.getQName().getLocalName());
-      spec.setType(node.getQName().getLocalName());
-      spec.setNotes(node.getDescription());
+    public static class Get {
+
+        protected Operation spec;
+        protected DataSchemaNode schemaNode;
+        private final String METHOD_NAME = "GET";
+
+        public Get(DataSchemaNode node, boolean isConfig) {
+            this.schemaNode = node;
+            spec = new Operation();
+            spec.setMethod(METHOD_NAME);
+            spec.setNickname(METHOD_NAME + "-" + node.getQName().getLocalName());
+            spec.setType((isConfig ? CONFIG : OPERATIONAL) + node.getQName().getLocalName());
+            spec.setNotes(node.getDescription());
+        }
+
+        public Get pathParams(List<Parameter> params) {
+            List<Parameter> pathParameters = new ArrayList<>(params);
+            spec.setParameters(pathParameters);
+            return this;
+        }
+
+        public Operation build() {
+            return spec;
+        }
     }
 
     }
 
-    public Get pathParams(List<Parameter> params){
-      List<Parameter> pathParameters = new ArrayList<>(params);
-      spec.setParameters(pathParameters);
-      return this;
-    }
-
-    public Operation build(){
-      return spec;
-    }
-  }
-
-  /**
+    /**
    *
    */
    *
    */
-  public static class Put{
-    protected Operation spec;
-    protected DataSchemaNode schemaNode;
-    private final String METHOD_NAME = "PUT";
-
-    public Put(DataSchemaNode node){
-      this.schemaNode = node;
-      spec = new Operation();
-      spec.setType(node.getQName().getLocalName());
-      spec.setNotes(node.getDescription());
-    }
-
-    public Put pathParams(List<Parameter> params){
-      List<Parameter> parameters = new ArrayList<>(params);
-      Parameter payload = new Parameter();
-      payload.setParamType("body");
-      payload.setType(schemaNode.getQName().getLocalName());
-      parameters.add(payload);
-      spec.setParameters(parameters);
-      return this;
-    }
-
-    public Operation build(){
-      spec.setMethod(METHOD_NAME);
-      spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
-      return spec;
+    public static class Put {
+        protected Operation spec;
+        protected DataSchemaNode schemaNode;
+        private final String METHOD_NAME = "PUT";
+
+        public Put(DataSchemaNode node) {
+            this.schemaNode = node;
+            spec = new Operation();
+            spec.setType(CONFIG + node.getQName().getLocalName());
+            spec.setNotes(node.getDescription());
+        }
+
+        public Put pathParams(List<Parameter> params) {
+            List<Parameter> parameters = new ArrayList<>(params);
+            Parameter payload = new Parameter();
+            payload.setParamType("body");
+            payload.setType(CONFIG + schemaNode.getQName().getLocalName());
+            parameters.add(payload);
+            spec.setParameters(parameters);
+            return this;
+        }
+
+        public Operation build() {
+            spec.setMethod(METHOD_NAME);
+            spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
+            return spec;
+        }
     }
     }
-  }
 
 
-  /**
+    /**
    *
    */
    *
    */
-  public static final class Post extends Put{
+    public static final class Post extends Put {
 
 
-    private final String METHOD_NAME = "POST";
+        private final String METHOD_NAME = "POST";
 
 
-    public Post(DataSchemaNode node){
-      super(node);
-    }
+        public Post(DataSchemaNode node) {
+            super(node);
+        }
 
 
-    public Operation build(){
-      spec.setMethod(METHOD_NAME);
-      spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
-      return spec;
+        @Override
+        public Operation build() {
+            spec.setMethod(METHOD_NAME);
+            spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
+            return spec;
+        }
     }
     }
-  }
 
 
-  /**
+    /**
    *
    */
    *
    */
-  public static final class Delete extends Get {
-    private final String METHOD_NAME = "DELETE";
-
-    public Delete(DataSchemaNode node){
-      super(node);
-    }
-
-    public Operation build(){
-      spec.setMethod(METHOD_NAME);
-      spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
-      spec.setType(null);
-      return spec;
+    public static final class Delete extends Get {
+        private final String METHOD_NAME = "DELETE";
+
+        public Delete(DataSchemaNode node) {
+            super(node, false);
+        }
+
+        @Override
+        public Operation build() {
+            spec.setMethod(METHOD_NAME);
+            spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
+            spec.setType(null);
+            return spec;
+        }
     }
     }
-  }
 }
 }