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=========================================================
20 package org.onap.aai.schemagen.genxsd;
22 import org.apache.commons.lang3.StringUtils;
23 import org.onap.aai.schemagen.GenerateXsd;
25 import java.util.StringTokenizer;
27 public class PatchOperation {
28 private String useOpId;
29 private String xmlRootElementName;
32 private String pathParams;
34 public PatchOperation(String useOpId, String xmlRootElementName, String tag, String path, String pathParams) {
36 this.useOpId = useOpId;
37 this.xmlRootElementName = xmlRootElementName;
40 this.pathParams = pathParams;
43 public String toString() {
45 st = new StringTokenizer(path, "/");
46 //a valid tag is necessary
47 if ( StringUtils.isEmpty(tag) ) {
50 if ( path.contains("/relationship/") ) { // filter paths with relationship-list
53 if ( path.endsWith("/relationship-list")) {
56 if ( path.startsWith("/search")) {
59 //No Patch operation paths end with "relationship"
61 if (path.endsWith("/relationship") ) {
64 if (!path.endsWith("}")) {
68 StringBuffer pathSb = new StringBuffer();
69 StringBuffer relationshipExamplesSb = new StringBuffer();
70 if ( path.endsWith("/relationship") ) {
71 pathSb.append(" " + path + ":\n" );
73 pathSb.append(" patch:\n");
74 pathSb.append(" tags:\n");
75 pathSb.append(" - " + tag + "\n");
77 if ( path.endsWith("/relationship") ) {
78 pathSb.append(" summary: see node definition for valid relationships\n");
79 relationshipExamplesSb.append("[See Examples](apidocs/relations/"+GenerateXsd.getAPIVersion()+"/"+useOpId+".json)");
81 pathSb.append(" summary: update an existing " + xmlRootElementName + "\n");
82 pathSb.append(" description: |\n");
83 pathSb.append(" Update an existing " + xmlRootElementName + "\n");
84 pathSb.append(" #\n");
85 pathSb.append(" Note: Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
86 pathSb.append(" The PUT operation will entirely replace an existing object.\n");
87 pathSb.append(" 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");
88 pathSb.append(" #\n");
89 pathSb.append(" Other differences between PUT and PATCH are:\n");
90 pathSb.append(" #\n");
91 pathSb.append(" - For PATCH, you can send any of the values shown in sample REQUEST body. There are no required values.\n");
92 pathSb.append(" - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
93 pathSb.append(" - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
95 pathSb.append(" operationId: Update" + useOpId + "\n");
96 pathSb.append(" consumes:\n");
97 pathSb.append(" - application/json\n");
98 pathSb.append(" produces:\n");
99 pathSb.append(" - application/json\n");
100 pathSb.append(" responses:\n");
101 pathSb.append(" \"default\":\n");
102 pathSb.append(" " + GenerateXsd.getResponsesUrl());
103 pathSb.append(" parameters:\n");
104 pathSb.append(pathParams); // for nesting
105 pathSb.append(" - name: body\n");
106 pathSb.append(" in: body\n");
107 pathSb.append(" description: " + xmlRootElementName + " object that needs to be updated."+relationshipExamplesSb.toString()+"\n");
108 pathSb.append(" required: true\n");
109 pathSb.append(" schema:\n");
110 pathSb.append(" $ref: \"#/patchDefinitions/" + xmlRootElementName + "\"\n");
111 return pathSb.toString();