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 java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.controller.sal.rest.doc.swagger.Operation;
14 import org.opendaylight.controller.sal.rest.doc.swagger.Parameter;
15 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 public final class OperationBuilder {
22 public static final String OPERATIONAL = "(operational)";
23 public static final String CONFIG = "(config)";
28 public static class Get {
30 protected Operation spec;
31 protected DataSchemaNode schemaNode;
32 private final String METHOD_NAME = "GET";
34 public Get(DataSchemaNode node, boolean isConfig) {
35 this.schemaNode = node;
36 spec = new Operation();
37 spec.setMethod(METHOD_NAME);
38 spec.setNickname(METHOD_NAME + "-" + node.getQName().getLocalName());
39 spec.setType((isConfig ? CONFIG : OPERATIONAL) + node.getQName().getLocalName());
40 spec.setNotes(node.getDescription());
43 public Get pathParams(List<Parameter> params) {
44 List<Parameter> pathParameters = new ArrayList<>(params);
45 spec.setParameters(pathParameters);
49 public Operation build() {
57 public static class Put {
58 protected Operation spec;
59 protected DataSchemaNode schemaNode;
60 private final String METHOD_NAME = "PUT";
62 public Put(DataSchemaNode node) {
63 this.schemaNode = node;
64 spec = new Operation();
65 spec.setType(CONFIG + node.getQName().getLocalName());
66 spec.setNotes(node.getDescription());
69 public Put pathParams(List<Parameter> params) {
70 List<Parameter> parameters = new ArrayList<>(params);
71 Parameter payload = new Parameter();
72 payload.setParamType("body");
73 payload.setType(CONFIG + schemaNode.getQName().getLocalName());
74 parameters.add(payload);
75 spec.setParameters(parameters);
79 public Operation build() {
80 spec.setMethod(METHOD_NAME);
81 spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
89 public static final class Post extends Put {
91 private final String METHOD_NAME = "POST";
93 public Post(DataSchemaNode node) {
98 public Operation build() {
99 spec.setMethod(METHOD_NAME);
100 spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
108 public static final class Delete extends Get {
109 private final String METHOD_NAME = "DELETE";
111 public Delete(DataSchemaNode node) {
116 public Operation build() {
117 spec.setMethod(METHOD_NAME);
118 spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());