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