Remove Bierman02 support from sal-rest-docgen
[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 static java.util.Objects.requireNonNull;
11
12 import java.util.Optional;
13 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
14
15 /**
16  * Base class for an RFC 8040 implementation.
17  *
18  * @author Thomas Pantelis
19  */
20 public abstract class BaseYangSwaggerGeneratorRFC8040 extends BaseYangSwaggerGenerator {
21     private final String basePath;
22
23     protected BaseYangSwaggerGeneratorRFC8040(final Optional<DOMSchemaService> schemaService) {
24         this(schemaService, "rests");
25     }
26
27     protected BaseYangSwaggerGeneratorRFC8040(final Optional<DOMSchemaService> schemaService, final String basePath) {
28         super(schemaService);
29         this.basePath = requireNonNull(basePath);
30     }
31
32     @Override
33     protected String getPathVersion() {
34         return "rfc8040";
35     }
36
37     @Override
38     public String getResourcePath(final String resourceType, final String context) {
39         if (isData(resourceType)) {
40             return "/" + basePath + "/data" + context;
41         }
42         return "/" + basePath + "/operations" + context;
43     }
44
45     @Override
46     public String getResourcePathPart(final String resourceType) {
47         if (isData(resourceType)) {
48             return "data";
49         }
50         return "operations";
51     }
52
53     private static boolean isData(final String dataStore) {
54         return "config".contains(dataStore) || "operational".contains(dataStore);
55     }
56
57     @Override
58     protected ListPathBuilder newListPathBuilder() {
59         return new ListPathBuilder() {
60             private String prefix = "=";
61
62             @Override
63             public String nextParamIdentifier(final String key) {
64                 final String str = prefix + "{" + key + "}";
65                 prefix = ",";
66                 return str;
67             }
68         };
69     }
70
71     @Override
72     protected void appendPathKeyValue(final StringBuilder builder, final Object value) {
73         builder.deleteCharAt(builder.length() - 1).append("=").append(value).append('/');
74     }
75 }