001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.dto.openapi3; 014 015import static org.apache.juneau.common.internal.StringUtils.*; 016import static org.apache.juneau.internal.CollectionUtils.*; 017import static org.apache.juneau.internal.ConverterUtils.*; 018 019import org.apache.juneau.annotation.Bean; 020import org.apache.juneau.internal.*; 021 022import java.util.LinkedHashMap; 023import java.util.Map; 024import java.util.Set; 025 026/** 027 * information for Link object. 028 * 029 * <h5 class='section'>Example:</h5> 030 * <p class='bcode'> 031 * <jc>// Construct using SwaggerBuilder.</jc> 032 * Contact x = <jsm>contact</jsm>(<js>"API Support"</js>, <js>"http://www.swagger.io/support"</js>, <js>"support@swagger.io"</js>); 033 * 034 * <jc>// Serialize using JsonSerializer.</jc> 035 * String json = JsonSerializer.<jsf>DEFAULT</jsf>.toString(x); 036 * 037 * <jc>// Or just use toString() which does the same as above.</jc> 038 * String json = x.toString(); 039 * </p> 040 * <p class='bcode'> 041 * <jc>// Output</jc> 042 * { 043 * <js>"name"</js>: <js>"API Support"</js>, 044 * <js>"url"</js>: <js>"http://www.swagger.io/support"</js>, 045 * <js>"email"</js>: <js>"support@swagger.io"</js> 046 * } 047 * </p> 048 */ 049@Bean(properties="operationRef,operationId,description,requestBody,server,parameters,*") 050@FluentSetters 051public class Link extends OpenApiElement { 052 053 private String operationRef; 054 private String operationId; 055 private String description; 056 private Object requestBody; 057 private Server server; 058 private Map<String,Object> parameters; 059 060 061 /** 062 * Default constructor. 063 */ 064 public Link() {} 065 066 /** 067 * Copy constructor. 068 * 069 * @param copyFrom The object to copy. 070 */ 071 public Link(Link copyFrom) { 072 super(copyFrom); 073 074 this.operationRef = copyFrom.operationRef; 075 this.description = copyFrom.description; 076 this.operationId = copyFrom.operationId; 077 this.requestBody = copyFrom.requestBody; 078 this.server = copyFrom.server == null ? null : copyFrom.server.copy(); 079 080 if (copyFrom.parameters == null) 081 this.parameters = null; 082 else 083 this.parameters = new LinkedHashMap<>(copyFrom.parameters); 084 } 085 086 /** 087 * Make a deep copy of this object. 088 * 089 * @return A deep copy of this object. 090 */ 091 public Link copy() { 092 return new Link(this); 093 } 094 095 /** 096 * Bean property getter: <property>operationRef</property>. 097 * 098 * <p> 099 * The identifying name of the contact person/organization. 100 * 101 * @return The property value, or <jk>null</jk> if it is not set. 102 */ 103 public String getOperationRef() { 104 return operationRef; 105 } 106 107 /** 108 * Bean property setter: <property>operationRef</property>. 109 * 110 * <p> 111 * The identifying name of the contact person/organization. 112 * 113 * @param value 114 * The new value for this property. 115 * <br>Can be <jk>null</jk> to unset the property. 116 * @return This object 117 */ 118 public Link setOperationRef(String value) { 119 operationRef = value; 120 return this; 121 } 122 123 /** 124 * Bean property getter: <property>description</property>. 125 * 126 * <p> 127 * The URL pointing to the contact information. 128 * 129 * @return The property value, or <jk>null</jk> if it is not set. 130 */ 131 public String getDescription() { 132 return description; 133 } 134 135 /** 136 * Bean property setter: <property>description</property>. 137 * @param value 138 * The new value for this property. 139 * <br>Can be <jk>null</jk> to unset the property. 140 * @return This object 141 */ 142 public Link setDescription(String value) { 143 description = value; 144 return this; 145 } 146 147 /** 148 * Bean property getter: <property>externalValue</property>. 149 * 150 * <p> 151 * The email address of the contact person/organization. 152 * 153 * @return The property value, or <jk>null</jk> if it is not set. 154 */ 155 public String getOperationId() { 156 return operationId; 157 } 158 159 /** 160 * Bean property setter: <property>externalValue</property>. 161 * 162 * <p> 163 * The email address of the contact person/organization. 164 * 165 * @param value 166 * The new value for this property. 167 * <br>MUST be in the format of an email address. 168 * <br>Can be <jk>null</jk> to unset the property. 169 * @return This object 170 */ 171 public Link setOperationId(String value) { 172 operationId = value; 173 return this; 174 } 175 176 /** 177 * Bean property getter: <property>default</property>. 178 * 179 * <p> 180 * Declares the value of the parameter that the server will use if none is provided, for example a <js>"count"</js> 181 * to control the number of results per page might default to 100 if not supplied by the client in the request. 182 * 183 * (Note: <js>"value"</js> has no meaning for required parameters.) 184 * Unlike JSON Schema this value MUST conform to the defined <code>type</code> for this parameter. 185 * 186 * @return The property value, or <jk>null</jk> if it is not set. 187 */ 188 public Object getRequestBody() { 189 return requestBody; 190 } 191 192 /** 193 * Bean property setter: <property>value</property>. 194 * 195 * <p> 196 * Declares the value of the parameter that the server will use if none is provided, for example a <js>"count"</js> 197 * to control the number of results per page might default to 100 if not supplied by the client in the request. 198 * (Note: <js>"default"</js> has no meaning for required parameters.) 199 * Unlike JSON Schema this value MUST conform to the defined <code>type</code> for this parameter. 200 * 201 * @param val The new value for this property. 202 * @return This object 203 */ 204 public Link setRequestBody(Object val) { 205 requestBody = val; 206 return this; 207 } 208 209 /** 210 * Bean property getter: <property>additionalProperties</property>. 211 * 212 * @return The property value, or <jk>null</jk> if it is not set. 213 */ 214 public Server getServer() { 215 return server; 216 } 217 218 /** 219 * Bean property setter: <property>additionalProperties</property>. 220 * 221 * @param value 222 * The new value for this property. 223 * <br>Can be <jk>null</jk> to unset the property. 224 * @return This object 225 */ 226 public Link setServer(Server value) { 227 server = value; 228 return this; 229 } 230 231 /** 232 * Bean property getter: <property>examples</property>. 233 * 234 * <p> 235 * An example of the response message. 236 * 237 * @return The property value, or <jk>null</jk> if it is not set. 238 */ 239 public Map<String,Object> getParameters() { 240 return parameters; 241 } 242 243 /** 244 * Bean property setter: <property>examples</property>. 245 * 246 * <p> 247 * An example of the response message. 248 * 249 * @param value 250 * The new value for this property. 251 * <br>Keys must be MIME-type strings. 252 * <br>Can be <jk>null</jk> to unset the property. 253 * @return This object 254 */ 255 public Link setParameters(Map<String,Object> value) { 256 parameters = copyOf(value); 257 return this; 258 } 259 260 /** 261 * Adds a single value to the <property>examples</property> property. 262 * 263 * @param mimeType The mime-type string. 264 * @param parameter The example. 265 * @return This object 266 */ 267 public Link addParameter(String mimeType, Object parameter) { 268 parameters = mapBuilder(parameters).sparse().add(mimeType, parameters).build(); 269 return this; 270 } 271 272 // <FluentSetters> 273 274 // </FluentSetters> 275 276 @Override /* OpenApiElement */ 277 public <T> T get(String property, Class<T> type) { 278 if (property == null) 279 return null; 280 switch (property) { 281 case "description": return toType(getDescription(), type); 282 case "operationRef": return toType(getOperationRef(), type); 283 case "operationId": return toType(getOperationId(), type); 284 case "requestBody": return toType(getRequestBody(), type); 285 case "parameters": return toType(getParameters(), type); 286 case "server": return toType(getServer(), type); 287 default: return super.get(property, type); 288 } 289 } 290 291 @Override /* OpenApiElement */ 292 public Link set(String property, Object value) { 293 if (property == null) 294 return this; 295 switch (property) { 296 case "description": return setDescription(stringify(value)); 297 case "operationId": return setOperationId(stringify(value)); 298 case "operationRef": return setOperationRef(stringify(value)); 299 case "requestBody": return setRequestBody(value); 300 case "server": return setServer(toType(value, Server.class)); 301 case "parameters": return setParameters(mapBuilder(String.class,Object.class).sparse().addAny(value).build()); 302 default: 303 super.set(property, value); 304 return this; 305 } 306 } 307 308 @Override /* OpenApiElement */ 309 public Set<String> keySet() { 310 Set<String> s = setBuilder(String.class) 311 .addIf(description != null, "description") 312 .addIf(operationId != null, "operationId") 313 .addIf(operationRef != null, "operationRef") 314 .addIf(requestBody != null, "requestBody") 315 .addIf(parameters != null, "parameters") 316 .addIf(server != null, "server") 317 .build(); 318 return new MultiSet<>(s, super.keySet()); 319 } 320}