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