2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.schemagen.genxsd;
23 import java.util.StringTokenizer;
24 import org.apache.commons.lang3.StringUtils;
25 import org.onap.aai.schemagen.GenerateXsd;
26 import org.onap.aai.setup.SchemaVersion;
28 public class PatchOperation {
29 private String useOpId;
30 private String xmlRootElementName;
33 private String pathParams;
34 private String prefixForPatch;
35 private SchemaVersion version;
36 private String basePath;
38 public PatchOperation(String useOpId, String xmlRootElementName, String tag, String path,
39 String pathParams, SchemaVersion v, String basePath) {
41 this.useOpId = useOpId;
42 this.xmlRootElementName = xmlRootElementName;
45 this.pathParams = pathParams;
46 this.prefixForPatch = "";
48 this.basePath = basePath;
51 public void setPrefixForPatchRef(String prefixForPatchRef) {
52 this.prefixForPatch = prefixForPatchRef;
55 public String toString() {
57 st = new StringTokenizer(path, "/");
58 //a valid tag is necessary
59 if (StringUtils.isEmpty(tag)) {
62 if (path.contains("/relationship/")) { // filter paths with relationship-list
65 if (path.endsWith("/relationship-list")) {
68 if (path.startsWith("/search")) {
71 //No Patch operation paths end with "relationship"
73 if (path.endsWith("/relationship")) {
76 if (!path.endsWith("}")) {
80 StringBuilder pathSb = new StringBuilder();
81 StringBuilder relationshipExamplesSb = new StringBuilder();
82 if (path.endsWith("/relationship")) {
83 pathSb.append(" ").append(path).append(":\n");
85 pathSb.append(" patch:\n");
86 pathSb.append(" tags:\n");
87 pathSb.append(" - ").append(tag).append("\n");
89 if (path.endsWith("/relationship")) {
90 pathSb.append(" summary: see node definition for valid relationships\n");
92 relationshipExamplesSb.append("[See Examples](apidocs").append(basePath)
93 .append("/relations/").append(version.toString()).append("/").append(useOpId)
95 pathSb.append(" summary: update an existing ").append(xmlRootElementName)
97 pathSb.append(" description: |\n");
98 pathSb.append(" Update an existing ").append(xmlRootElementName)
100 pathSb.append(" #\n");
102 " Note: Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
103 pathSb.append(" The PUT operation will entirely replace an existing object.\n");
105 " The PATCH operation sends a \"description of changes\" for an existing object. The entire set of changes must be applied. An error result means no change occurs.\n");
106 pathSb.append(" #\n");
107 pathSb.append(" Other differences between PUT and PATCH are:\n");
108 pathSb.append(" #\n");
110 " - For PATCH, you can send any of the values shown in sample REQUEST body. There are no required values.\n");
112 " - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
114 " - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
116 pathSb.append(" operationId: Update").append(useOpId).append("\n");
117 pathSb.append(" consumes:\n");
118 pathSb.append(" - application/json\n");
119 pathSb.append(" produces:\n");
120 pathSb.append(" - application/json\n");
121 pathSb.append(" responses:\n");
122 pathSb.append(" \"default\":\n");
123 pathSb.append(" ").append(GenerateXsd.getResponsesUrl());
124 pathSb.append(" parameters:\n");
125 pathSb.append(pathParams); // for nesting
126 pathSb.append(" - name: body\n");
127 pathSb.append(" in: body\n");
128 pathSb.append(" description: ").append(xmlRootElementName)
129 .append(" object that needs to be updated.")
130 .append(relationshipExamplesSb.toString()).append("\n");
131 pathSb.append(" required: true\n");
132 pathSb.append(" schema:\n");
133 pathSb.append(" $ref: \"#/definitions/").append(prefixForPatch)
134 .append(xmlRootElementName).append("\"\n");
135 return pathSb.toString();