001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.rest; 018 019import java.util.ArrayList; 020import java.util.Arrays; 021import java.util.List; 022import javax.xml.bind.annotation.XmlAccessType; 023import javax.xml.bind.annotation.XmlAccessorType; 024import javax.xml.bind.annotation.XmlAttribute; 025import javax.xml.bind.annotation.XmlElement; 026import javax.xml.bind.annotation.XmlElementWrapper; 027import javax.xml.bind.annotation.XmlRootElement; 028import javax.xml.bind.annotation.XmlTransient; 029 030import org.apache.camel.spi.Metadata; 031import org.apache.camel.util.ObjectHelper; 032 033/** 034 * To specify the rest operation response headers using Swagger. 035 * <p> 036 * This maps to the Swagger Response Header Object. 037 */ 038@Metadata(label = "rest") 039@XmlRootElement(name = "responseHeader") 040@XmlAccessorType(XmlAccessType.FIELD) 041public class RestOperationResponseHeaderDefinition { 042 043 @XmlTransient 044 private RestOperationResponseMsgDefinition response; 045 046 @XmlAttribute(required = true) 047 private String name; 048 049 @XmlAttribute 050 @Metadata(defaultValue = "") 051 private String description; 052 053 @XmlAttribute 054 @Metadata(defaultValue = "csv") 055 private CollectionFormat collectionFormat; 056 057 @XmlAttribute 058 @Metadata(defaultValue = "string") 059 private String arrayType; 060 061 @XmlAttribute 062 @Metadata(defaultValue = "string") 063 private String dataType; 064 065 @XmlAttribute 066 private String dataFormat; 067 068 @XmlElementWrapper(name = "allowableValues") 069 @XmlElement(name = "value") 070 private List<String> allowableValues; 071 072 public RestOperationResponseHeaderDefinition(RestOperationResponseMsgDefinition response) { 073 this(); 074 this.response = response; 075 } 076 077 public RestOperationResponseHeaderDefinition() { 078 this.collectionFormat = CollectionFormat.csv; 079 this.arrayType = "string"; 080 this.dataType = "string"; 081 } 082 083 /** 084 * Ends the configuration of this response message 085 */ 086 public RestOperationResponseMsgDefinition endResponseHeader() { 087 return response; 088 } 089 090 public String getName() { 091 return name; 092 } 093 094 public void setName(String name) { 095 this.name = name; 096 } 097 098 public String getDescription() { 099 return description; 100 } 101 102 public void setDescription(String description) { 103 this.description = description; 104 } 105 106 public CollectionFormat getCollectionFormat() { 107 return collectionFormat; 108 } 109 110 /** 111 * Sets the Swagger Parameter collection format. 112 */ 113 public void setCollectionFormat(CollectionFormat collectionFormat) { 114 this.collectionFormat = collectionFormat; 115 } 116 117 118 public String getArrayType() { 119 return arrayType; 120 } 121 122 /** 123 * Sets the Swagger Parameter array type. 124 * Required if data type is "array". Describes the type of items in the array. 125 */ 126 public void setArrayType(String arrayType) { 127 this.arrayType = arrayType; 128 } 129 130 public String getDataType() { 131 return dataType; 132 } 133 134 /** 135 * Sets the Swagger header data type. 136 */ 137 public void setDataType(String dataType) { 138 this.dataType = dataType; 139 } 140 141 public String getDataFormat() { 142 return dataFormat; 143 } 144 145 /** 146 * Sets the Swagger Parameter data format. 147 */ 148 public void setDataFormat(String dataFormat) { 149 this.dataFormat = dataFormat; 150 } 151 152 public List<String> getAllowableValues() { 153 if (allowableValues != null) { 154 return allowableValues; 155 } 156 157 return new ArrayList<String>(); 158 } 159 160 /** 161 * Sets the Swagger Parameter list of allowable values. 162 */ 163 public void setAllowableValues(List<String> allowableValues) { 164 this.allowableValues = allowableValues; 165 } 166 167 /** 168 * Name of the parameter. 169 * <p> 170 * This option is mandatory. 171 */ 172 public RestOperationResponseHeaderDefinition name(String name) { 173 setName(name); 174 return this; 175 } 176 177 /** 178 * Description of the parameter. 179 */ 180 public RestOperationResponseHeaderDefinition description(String name) { 181 setDescription(name); 182 return this; 183 } 184 185 /** 186 * Sets the collection format. 187 */ 188 public RestOperationResponseHeaderDefinition collectionFormat(CollectionFormat collectionFormat) { 189 setCollectionFormat(collectionFormat); 190 return this; 191 } 192 193 /** 194 * The data type of the array data type 195 */ 196 public RestOperationResponseHeaderDefinition arrayType(String arrayType) { 197 setArrayType(arrayType); 198 return this; 199 } 200 201 /** 202 * The data type of the header such as <tt>string</tt>, <tt>integer</tt>, <tt>boolean</tt> 203 */ 204 public RestOperationResponseHeaderDefinition dataType(String type) { 205 setDataType(type); 206 return this; 207 } 208 209 /** 210 * The data format of the parameter such as <tt>binary</tt>, <tt>date</tt>, <tt>date-time</tt>, <tt>password</tt>. 211 * The format is usually derived from the dataType alone. However you can set this option for more fine grained control 212 * of the format in use. 213 */ 214 public RestOperationResponseHeaderDefinition dataFormat(String type) { 215 setDataFormat(type); 216 return this; 217 } 218 219 /** 220 * Allowed values of the header when its an enum type 221 */ 222 public RestOperationResponseHeaderDefinition allowableValues(List<String> allowableValues) { 223 setAllowableValues(allowableValues); 224 return this; 225 } 226 227 /** 228 * Allowed values of the parameter when its an enum type 229 */ 230 public RestOperationResponseHeaderDefinition allowableValues(String... allowableValues) { 231 setAllowableValues(Arrays.asList(allowableValues)); 232 return this; 233 } 234 235 /** 236 * Ends the configuration of this header 237 */ 238 public RestOperationResponseMsgDefinition endHeader() { 239 // name and type is mandatory 240 ObjectHelper.notEmpty(name, "name"); 241 ObjectHelper.notEmpty(dataType, "dataType"); 242 return response; 243 } 244 245}