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.juneau.bean.openapi3; 018 019import static org.apache.juneau.common.utils.StringUtils.*; 020import static org.apache.juneau.common.utils.Utils.*; 021import static org.apache.juneau.internal.CollectionUtils.*; 022import static org.apache.juneau.internal.ConverterUtils.*; 023 024import java.net.*; 025import java.util.*; 026 027import org.apache.juneau.*; 028import org.apache.juneau.common.utils.*; 029import org.apache.juneau.internal.*; 030 031/** 032 * Contact information for the exposed API. 033 * 034 * <p> 035 * The Contact Object provides contact information for the exposed API. This information can be used by clients 036 * to get in touch with the API maintainers for support, questions, or other inquiries. 037 * 038 * <h5 class='section'>OpenAPI Specification:</h5> 039 * <p> 040 * The Contact Object is composed of the following fields: 041 * <ul class='spaced-list'> 042 * <li><c>name</c> (string) - The identifying name of the contact person/organization 043 * <li><c>url</c> (string) - The URL pointing to the contact information 044 * <li><c>email</c> (string) - The email address of the contact person/organization 045 * </ul> 046 * 047 * <h5 class='section'>Example:</h5> 048 * <p class='bcode'> 049 * <jc>// Construct using SwaggerBuilder.</jc> 050 * Contact <jv>x</jv> = <jsm>contact</jsm>(<js>"API Support"</js>, <js>"http://www.swagger.io/support"</js>, <js>"support@swagger.io"</js>); 051 * 052 * <jc>// Serialize using JsonSerializer.</jc> 053 * String <jv>json</jv> = Json.<jsm>from</jsm>(<jv>x</jv>); 054 * 055 * <jc>// Or just use toString() which does the same as above.</jc> 056 * String <jv>json</jv> = <jv>x</jv>.toString(); 057 * </p> 058 * <p class='bcode'> 059 * <jc>// Output</jc> 060 * { 061 * <js>"name"</js>: <js>"API Support"</js>, 062 * <js>"url"</js>: <js>"http://www.swagger.io/support"</js>, 063 * <js>"email"</js>: <js>"support@swagger.io"</js> 064 * } 065 * </p> 066 * 067 * <h5 class='section'>See Also:</h5><ul> 068 * <li class='link'><a class="doclink" href="https://spec.openapis.org/oas/v3.0.0#contact-object">OpenAPI Specification > Contact Object</a> 069 * <li class='link'><a class="doclink" href="https://swagger.io/docs/specification/api-general-info/">OpenAPI API General Info</a> 070 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanOpenApi3">juneau-bean-openapi-v3</a> 071 * </ul> 072 */ 073public class Contact extends OpenApiElement { 074 075 private String name; 076 private URI url; 077 private String email; 078 079 /** 080 * Default constructor. 081 */ 082 public Contact() {} 083 084 /** 085 * Copy constructor. 086 * 087 * @param copyFrom The object to copy. 088 */ 089 public Contact(Contact copyFrom) { 090 super(copyFrom); 091 092 this.name = copyFrom.name; 093 this.url = copyFrom.url; 094 this.email = copyFrom.email; 095 } 096 097 /** 098 * Make a deep copy of this object. 099 * 100 * @return A deep copy of this object. 101 */ 102 public Contact copy() { 103 return new Contact(this); 104 } 105 106 /** 107 * Bean property getter: <property>name</property>. 108 * 109 * <p> 110 * The identifying name of the contact person/organization. 111 * 112 * @return The property value, or <jk>null</jk> if it is not set. 113 */ 114 public String getName() { 115 return name; 116 } 117 118 /** 119 * Bean property setter: <property>name</property>. 120 * 121 * <p> 122 * The identifying name of the contact person/organization. 123 * 124 * @param value 125 * The new value for this property. 126 * <br>Can be <jk>null</jk> to unset the property. 127 * @return This object 128 */ 129 public Contact setName(String value) { 130 name = value; 131 return this; 132 } 133 134 /** 135 * Bean property getter: <property>url</property>. 136 * 137 * <p> 138 * The URL pointing to the contact information. 139 * 140 * @return The property value, or <jk>null</jk> if it is not set. 141 */ 142 public URI getUrl() { 143 return url; 144 } 145 146 /** 147 * Bean property setter: <property>url</property>. 148 * 149 * <p> 150 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 151 * <br>Strings must be valid URIs. 152 * 153 * <p> 154 * URIs defined by {@link UriResolver} can be used for values. 155 * 156 * @param value 157 * The new value for this property. 158 * <br>Can be <jk>null</jk> to unset the property. 159 * @return This object 160 */ 161 public Contact setUrl(URI value) { 162 url = value; 163 return this; 164 } 165 166 /** 167 * Bean property getter: <property>email</property>. 168 * 169 * <p> 170 * The email address of the contact person/organization. 171 * 172 * @return The property value, or <jk>null</jk> if it is not set. 173 */ 174 public String getEmail() { 175 return email; 176 } 177 178 /** 179 * Bean property setter: <property>email</property>. 180 * 181 * <p> 182 * The email address of the contact person/organization. 183 * 184 * @param value 185 * The new value for this property. 186 * <br>MUST be in the format of an email address. 187 * <br>Can be <jk>null</jk> to unset the property. 188 * @return This object 189 */ 190 public Contact setEmail(String value) { 191 email = value; 192 return this; 193 } 194 195 @Override /* Overridden from OpenApiElement */ 196 public <T> T get(String property, Class<T> type) { 197 assertArgNotNull("property", property); 198 return switch (property) { 199 case "name" -> toType(getName(), type); 200 case "url" -> toType(getUrl(), type); 201 case "email" -> toType(getEmail(), type); 202 default -> super.get(property, type); 203 }; 204 } 205 206 @Override /* Overridden from OpenApiElement */ 207 public Contact set(String property, Object value) { 208 assertArgNotNull("property", property); 209 return switch (property) { 210 case "email" -> setEmail(Utils.s(value)); 211 case "name" -> setName(Utils.s(value)); 212 case "url" -> setUrl(toURI(value)); 213 default -> { 214 super.set(property, value); 215 yield this; 216 } 217 }; 218 } 219 220 @Override /* Overridden from OpenApiElement */ 221 public Set<String> keySet() { 222 var s = setBuilder(String.class) 223 .addIf(email != null, "email") 224 .addIf(name != null, "name") 225 .addIf(url != null, "url") 226 .build(); 227 return new MultiSet<>(s, super.keySet()); 228 } 229 230 @Override /* Overridden from OpenApiElement */ 231 public Contact strict() { 232 super.strict(); 233 return this; 234 } 235 236 @Override /* Overridden from OpenApiElement */ 237 public Contact strict(Object value) { 238 super.strict(value); 239 return this; 240 } 241}