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 @XmlElementWrapper(name = "allowableValues") 066 @XmlElement(name = "value") 067 private List<String> allowableValues; 068 069 public RestOperationResponseHeaderDefinition(RestOperationResponseMsgDefinition response) { 070 this(); 071 this.response = response; 072 } 073 074 public RestOperationResponseHeaderDefinition() { 075 this.collectionFormat = CollectionFormat.csv; 076 this.arrayType = "string"; 077 this.dataType = "string"; 078 } 079 080 /** 081 * Ends the configuration of this response message 082 */ 083 public RestOperationResponseMsgDefinition endResponseHeader() { 084 return response; 085 } 086 087 public String getName() { 088 return name; 089 } 090 091 public void setName(String name) { 092 this.name = name; 093 } 094 095 public String getDescription() { 096 return description; 097 } 098 099 public void setDescription(String description) { 100 this.description = description; 101 } 102 103 public CollectionFormat getCollectionFormat() { 104 return collectionFormat; 105 } 106 107 /** 108 * Sets the Swagger Parameter collection format. 109 */ 110 public void setCollectionFormat(CollectionFormat collectionFormat) { 111 this.collectionFormat = collectionFormat; 112 } 113 114 115 public String getArrayType() { 116 return arrayType; 117 } 118 119 /** 120 * Sets the Swagger Parameter array type. 121 * Required if data type is "array". Describes the type of items in the array. 122 */ 123 public void setArrayType(String arrayType) { 124 this.arrayType = arrayType; 125 } 126 127 public String getDataType() { 128 return dataType; 129 } 130 131 /** 132 * Sets the Swagger header data type. 133 */ 134 public void setDataType(String dataType) { 135 this.dataType = dataType; 136 } 137 138 public List<String> getAllowableValues() { 139 if (allowableValues != null) { 140 return allowableValues; 141 } 142 143 return new ArrayList<String>(); 144 } 145 146 /** 147 * Sets the Swagger Parameter list of allowable values. 148 */ 149 public void setAllowableValues(List<String> allowableValues) { 150 this.allowableValues = allowableValues; 151 } 152 153 /** 154 * Name of the parameter. 155 * <p> 156 * This option is mandatory. 157 */ 158 public RestOperationResponseHeaderDefinition name(String name) { 159 setName(name); 160 return this; 161 } 162 163 /** 164 * Description of the parameter. 165 */ 166 public RestOperationResponseHeaderDefinition description(String name) { 167 setDescription(name); 168 return this; 169 } 170 171 /** 172 * Sets the collection format. 173 */ 174 public RestOperationResponseHeaderDefinition collectionFormat(CollectionFormat collectionFormat) { 175 setCollectionFormat(collectionFormat); 176 return this; 177 } 178 179 /** 180 * The data type of the array data type 181 */ 182 public RestOperationResponseHeaderDefinition arrayType(String arrayType) { 183 setArrayType(arrayType); 184 return this; 185 } 186 187 /** 188 * The data type of the header such as <tt>string</tt>, <tt>integer</tt>, <tt>boolean</tt> 189 */ 190 public RestOperationResponseHeaderDefinition dataType(String type) { 191 setDataType(type); 192 return this; 193 } 194 195 /** 196 * Allowed values of the header when its an enum type 197 */ 198 public RestOperationResponseHeaderDefinition allowableValues(List<String> allowableValues) { 199 setAllowableValues(allowableValues); 200 return this; 201 } 202 203 /** 204 * Allowed values of the parameter when its an enum type 205 */ 206 public RestOperationResponseHeaderDefinition allowableValues(String... allowableValues) { 207 setAllowableValues(Arrays.asList(allowableValues)); 208 return this; 209 } 210 211 /** 212 * Ends the configuration of this header 213 */ 214 public RestOperationResponseMsgDefinition endHeader() { 215 // name and type is mandatory 216 ObjectHelper.notEmpty(name, "name"); 217 ObjectHelper.notEmpty(dataType, "dataType"); 218 return response; 219 } 220 221}