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