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.swagger; 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 java.util.*; 020 021import org.apache.juneau.annotation.*; 022import org.apache.juneau.internal.*; 023 024/** 025 * The object provides metadata about the API. 026 * 027 * <p> 028 * The metadata can be used by the clients if needed, and can be presented 029 * in the Swagger-UI for convenience. 030 * 031 * <h5 class='section'>Example:</h5> 032 * <p class='bjava'> 033 * <jc>// Construct using SwaggerBuilder.</jc> 034 * Info <jv>info</jv> = <jsm>info</jsm>(<js>"Swagger Sample App"</js>, <js>"1.0.1"</js>) 035 * .description(<js>"This is a sample server Petstore server."</js>) 036 * .termsOfService(<js>"http://swagger.io/terms/"</js>) 037 * .contact( 038 * <jsm>contact</jsm>(<js>"API Support"</js>, <js>"http://www.swagger.io/support"</js>, <js>"support@swagger.io"</js>) 039 * ) 040 * .license( 041 * <jsm>license</jsm>(<js>"Apache 2.0"</js>, <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js>) 042 * ); 043 * 044 * <jc>// Serialize using JsonSerializer.</jc> 045 * String <jv>json</jv> = JsonSerializer.<jsf>DEFAULT</jsf>.toString(<jv>info</jv>); 046 * 047 * <jc>// Or just use toString() which does the same as above.</jc> 048 * <jv>json</jv> = <jv>info</jv>.toString(); 049 * </p> 050 * <p class='bjson'> 051 * <jc>// Output</jc> 052 * { 053 * <js>"title"</js>: <js>"Swagger Sample App"</js>, 054 * <js>"description"</js>: <js>"This is a sample server Petstore server."</js>, 055 * <js>"termsOfService"</js>: <js>"http://swagger.io/terms/"</js>, 056 * <js>"contact"</js>: { 057 * <js>"name"</js>: <js>"API Support"</js>, 058 * <js>"url"</js>: <js>"http://www.swagger.io/support"</js>, 059 * <js>"email"</js>: <js>"support@swagger.io"</js> 060 * }, 061 * <js>"license"</js>: { 062 * <js>"name"</js>: <js>"Apache 2.0"</js>, 063 * <js>"url"</js>: <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js> 064 * }, 065 * <js>"version"</js>: <js>"1.0.1"</js> 066 * } 067 * </p> 068 * 069 * <h5 class='section'>See Also:</h5><ul> 070 * <li class='link'><a class="doclink" href="../../../../../index.html#jrs.Swagger">Overview > juneau-rest-server > Swagger</a> 071 * </ul> 072 */ 073@Bean(properties="siteName,title,description,version,contact,license,termsOfService,*") 074@FluentSetters 075public class Info extends SwaggerElement { 076 077 private String 078 siteName, 079 title, 080 description, 081 termsOfService, 082 version; 083 private Contact contact; 084 private License license; 085 086 /** 087 * Default constructor. 088 */ 089 public Info() {} 090 091 /** 092 * Copy constructor. 093 * 094 * @param copyFrom The object to copy. 095 */ 096 public Info(Info copyFrom) { 097 super(copyFrom); 098 099 this.contact = copyFrom.contact == null ? null : copyFrom.contact.copy(); 100 this.description = copyFrom.description; 101 this.license = copyFrom.license == null ? null : copyFrom.license.copy(); 102 this.siteName = copyFrom.siteName; 103 this.termsOfService = copyFrom.termsOfService; 104 this.title = copyFrom.title; 105 this.version = copyFrom.version; 106 } 107 108 /** 109 * Make a deep copy of this object. 110 * 111 * @return A deep copy of this object. 112 */ 113 public Info copy() { 114 return new Info(this); 115 } 116 117 //----------------------------------------------------------------------------------------------------------------- 118 // Properties 119 //----------------------------------------------------------------------------------------------------------------- 120 121 /** 122 * Bean property getter: <property>contact</property>. 123 * 124 * <p> 125 * The contact information for the exposed API. 126 * 127 * @return The property value, or <jk>null</jk> if it is not set. 128 */ 129 public Contact getContact() { 130 return contact; 131 } 132 133 /** 134 * Bean property setter: <property>contact</property>. 135 * 136 * <p> 137 * The contact information for the exposed API. 138 * 139 * @param value 140 * The new value for this property. 141 * <br>Can be <jk>null</jk> to unset the property. 142 * @return This object. 143 */ 144 public Info setContact(Contact value) { 145 contact = value; 146 return this; 147 } 148 149 /** 150 * Bean property getter: <property>description</property>. 151 * 152 * <p> 153 * A short description of the application. 154 * 155 * @return The property value, or <jk>null</jk> if it is not set. 156 */ 157 public String getDescription() { 158 return description; 159 } 160 161 /** 162 * Bean property setter: <property>description</property>. 163 * 164 * <p> 165 * A short description of the application. 166 * 167 * @param value 168 * The new value for this property. 169 * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation. 170 * <br>Can be <jk>null</jk> to unset the property. 171 * @return This object. 172 */ 173 public Info setDescription(String value) { 174 description = value; 175 return this; 176 } 177 178 /** 179 * Bean property getter: <property>license</property>. 180 * 181 * <p> 182 * The license information for the exposed API. 183 * 184 * @return The property value, or <jk>null</jk> if it is not set. 185 */ 186 public License getLicense() { 187 return license; 188 } 189 190 /** 191 * Bean property setter: <property>license</property>. 192 * 193 * <p> 194 * The license information for the exposed API. 195 * 196 * @param value 197 * The new value for this property. 198 * <br>Can be <jk>null</jk> to unset the property. 199 * @return This object. 200 */ 201 public Info setLicense(License value) { 202 license = value; 203 return this; 204 } 205 206 /** 207 * Bean property getter: <property>siteName</property>. 208 * 209 * <p> 210 * The site name of the application. 211 * 212 * @return The property value, or <jk>null</jk> if it is not set. 213 */ 214 public String getSiteName() { 215 return siteName; 216 } 217 218 /** 219 * Bean property setter: <property>siteName</property>. 220 * 221 * <p> 222 * The site name of the application. 223 * 224 * @param value 225 * The new value for this property. 226 * @return This object. 227 */ 228 public Info setSiteName(String value) { 229 siteName = value; 230 return this; 231 } 232 233 /** 234 * Bean property getter: <property>termsOfService</property>. 235 * 236 * <p> 237 * The Terms of Service for the API. 238 * 239 * @return The property value, or <jk>null</jk> if it is not set. 240 */ 241 public String getTermsOfService() { 242 return termsOfService; 243 } 244 245 /** 246 * Bean property setter: <property>termsOfService</property>. 247 * 248 * <p> 249 * The Terms of Service for the API. 250 * 251 * @param value 252 * The new value for this property. 253 * <br>Can be <jk>null</jk> to unset the property. 254 * @return This object. 255 */ 256 public Info setTermsOfService(String value) { 257 termsOfService = value; 258 return this; 259 } 260 261 /** 262 * Bean property getter: <property>title</property>. 263 * 264 * <p> 265 * The title of the application. 266 * 267 * @return The property value, or <jk>null</jk> if it is not set. 268 */ 269 public String getTitle() { 270 return title; 271 } 272 273 /** 274 * Bean property setter: <property>title</property>. 275 * 276 * <p> 277 * The title of the application. 278 * 279 * @param value 280 * The new value for this property. 281 * @return This object. 282 */ 283 public Info setTitle(String value) { 284 title = value; 285 return this; 286 } 287 288 /** 289 * Bean property getter: <property>version</property>. 290 * 291 * <p> 292 * The version of the application API (not to be confused with the specification version). 293 * 294 * @return The property value, or <jk>null</jk> if it is not set. 295 */ 296 public String getVersion() { 297 return version; 298 } 299 300 /** 301 * Bean property setter: <property>version</property>. 302 * 303 * <p> 304 * The version of the application API (not to be confused with the specification version). 305 * 306 * @param value 307 * The new value for this property. 308 * <br>Property value is required. 309 * @return This object. 310 */ 311 public Info setVersion(String value) { 312 version = value; 313 return this; 314 } 315 316 // <FluentSetters> 317 318 // </FluentSetters> 319 320 @Override /* SwaggerElement */ 321 public <T> T get(String property, Class<T> type) { 322 if (property == null) 323 return null; 324 switch (property) { 325 case "contact": return toType(getContact(), type); 326 case "description": return toType(getDescription(), type); 327 case "license": return toType(getLicense(), type); 328 case "siteName": return toType(getSiteName(), type); 329 case "termsOfService": return toType(getTermsOfService(), type); 330 case "title": return toType(getTitle(), type); 331 case "version": return toType(getVersion(), type); 332 default: return super.get(property, type); 333 } 334 } 335 336 @Override /* SwaggerElement */ 337 public Info set(String property, Object value) { 338 if (property == null) 339 return this; 340 switch (property) { 341 case "contact": return setContact(toType(value, Contact.class)); 342 case "description": return setDescription(stringify(value)); 343 case "license": return setLicense(toType(value, License.class)); 344 case "siteName": return setSiteName(stringify(value)); 345 case "termsOfService": return setTermsOfService(stringify(value)); 346 case "title": return setTitle(stringify(value)); 347 case "version": return setVersion(stringify(value)); 348 default: 349 super.set(property, value); 350 return this; 351 } 352 } 353 354 @Override /* SwaggerElement */ 355 public Set<String> keySet() { 356 Set<String> s = setBuilder(String.class) 357 .addIf(contact != null, "contact") 358 .addIf(description != null, "description") 359 .addIf(license != null, "license") 360 .addIf(siteName != null, "siteName") 361 .addIf(termsOfService != null, "termsOfService") 362 .addIf(title != null, "title") 363 .addIf(version != null, "version") 364 .build(); 365 return new MultiSet<>(s, super.keySet()); 366 } 367}