Make swagger generators configurable
[netconf.git] / restconf / sal-rest-docgen / src / main / java / org / opendaylight / netconf / sal / rest / doc / impl / BaseYangSwaggerGeneratorRFC8040.java
1 /*
2  * Copyright (c) 2018 Inocybe Technologies 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 package org.opendaylight.netconf.sal.rest.doc.impl;
9
10 import java.util.Optional;
11 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
12
13 /**
14  * Base class for an RFC 8040 implementation.
15  *
16  * @author Thomas Pantelis
17  */
18 public abstract class BaseYangSwaggerGeneratorRFC8040 extends BaseYangSwaggerGenerator {
19
20     private static final String DEFAULT_BASE_PATH = "rests";
21     private final String basePath;
22
23     protected BaseYangSwaggerGeneratorRFC8040(final Optional<DOMSchemaService> schemaService) {
24         super(schemaService);
25         this.basePath = DEFAULT_BASE_PATH;
26     }
27
28     protected BaseYangSwaggerGeneratorRFC8040(final Optional<DOMSchemaService> schemaService, final String basePath) {
29         super(schemaService);
30         this.basePath = basePath;
31     }
32
33     @Override
34     public String getDataStorePath(final String dataStore, final String context) {
35         if ("config".contains(dataStore) || "operational".contains(dataStore)) {
36             return "/" + basePath + "/data" + context;
37         }
38         return "/" + basePath + "/operations" + context;
39     }
40
41     @Override
42     public String getContent(final String dataStore) {
43         if ("operational".contains(dataStore)) {
44             return "?content=nonconfig";
45         } else if ("config".contains(dataStore)) {
46             return "?content=config";
47         } else {
48             return "";
49         }
50     }
51
52     @Override
53     protected ListPathBuilder newListPathBuilder() {
54         return new ListPathBuilder() {
55             private String prefix = "=";
56
57             @Override
58             public String nextParamIdentifier(String key) {
59                 String str = prefix + "{" + key + "}";
60                 prefix = ",";
61                 return str;
62             }
63         };
64     }
65
66     @Override
67     protected void appendPathKeyValue(StringBuilder builder, Object value) {
68         builder.deleteCharAt(builder.length() - 1).append("=").append(value).append('/');
69     }
70 }