2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.rest.doc.model.builder;
10 import org.opendaylight.controller.sal.rest.doc.swagger.Operation;
11 import org.opendaylight.controller.sal.rest.doc.swagger.Parameter;
12 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
14 import java.util.ArrayList;
15 import java.util.List;
20 public final class OperationBuilder {
25 public static class Get{
27 protected Operation spec;
28 protected DataSchemaNode schemaNode;
29 private final String METHOD_NAME = "GET";
31 public Get(DataSchemaNode node){
32 this.schemaNode = node;
33 spec = new Operation();
34 spec.setMethod(METHOD_NAME);
35 spec.setNickname(METHOD_NAME + "-" + node.getQName().getLocalName());
36 spec.setType(node.getQName().getLocalName());
37 spec.setNotes(node.getDescription());
40 public Get pathParams(List<Parameter> params){
41 List<Parameter> pathParameters = new ArrayList<>(params);
42 spec.setParameters(pathParameters);
46 public Operation build(){
54 public static class Put{
55 protected Operation spec;
56 protected DataSchemaNode schemaNode;
57 private final String METHOD_NAME = "PUT";
59 public Put(DataSchemaNode node){
60 this.schemaNode = node;
61 spec = new Operation();
62 spec.setType(node.getQName().getLocalName());
63 spec.setNotes(node.getDescription());
66 public Put pathParams(List<Parameter> params){
67 List<Parameter> parameters = new ArrayList<>(params);
68 Parameter payload = new Parameter();
69 payload.setParamType("body");
70 payload.setType(schemaNode.getQName().getLocalName());
71 parameters.add(payload);
72 spec.setParameters(parameters);
76 public Operation build(){
77 spec.setMethod(METHOD_NAME);
78 spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
86 public static final class Post extends Put{
88 private final String METHOD_NAME = "POST";
90 public Post(DataSchemaNode node){
94 public Operation build(){
95 spec.setMethod(METHOD_NAME);
96 spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
104 public static final class Delete extends Get {
105 private final String METHOD_NAME = "DELETE";
107 public Delete(DataSchemaNode node){
111 public Operation build(){
112 spec.setMethod(METHOD_NAME);
113 spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());