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.commons.utils.Shorts.*;
020import static org.apache.juneau.commons.utils.StringUtils.*;
021import static org.apache.juneau.marshall.internal.ConverterUtils.*;
022
023import java.net.*;
024import java.util.*;
025
026import org.apache.juneau.commons.collections.*;
027
028/**
029 * Contact information for the exposed API.
030 *
031 * <p>
032 * The Contact Object provides contact information for the exposed API in Swagger 2.0. This information can be used
033 * by clients to get in touch with the API maintainers for support, questions, or other inquiries.
034 *
035 * <h5 class='section'>Swagger Specification:</h5>
036 * <p>
037 * The Contact Object is composed of the following fields:
038 * <ul class='spaced-list'>
039 *    <li><c>name</c> (string) - The identifying name of the contact person/organization
040 *    <li><c>url</c> (string) - The URL pointing to the contact information
041 *    <li><c>email</c> (string) - The email address of the contact person/organization
042 * </ul>
043 *
044 * <h5 class='section'>Example:</h5>
045 * <p class='bjava'>
046 *    <jc>// Construct using SwaggerBuilder.</jc>
047 *    Contact <jv>contact</jv> = <jsm>contact</jsm>(<js>"API Support"</js>, <js>"http://www.swagger.io/support"</js>, <js>"support@swagger.io"</js>);
048 *
049 *    <jc>// Serialize using JsonSerializer.</jc>
050 *    String <jv>json</jv> = Json.<jsm>from</jsm>(<jv>contact</jv>);
051 *
052 *    <jc>// Or just use toString() which does the same as above.</jc>
053 *    <jv>json</jv> = <jv>contact</jv>.toString();
054 * </p>
055 * <p class='bjson'>
056 *    <jc>// Output</jc>
057 *    {
058 *       <js>"name"</js>: <js>"API Support"</js>,
059 *       <js>"url"</js>: <js>"http://www.swagger.io/support"</js>,
060 *       <js>"email"</js>: <js>"support@swagger.io"</js>
061 *    }
062 * </p>
063 *
064 * <h5 class='section'>See Also:</h5><ul>
065 *    <li class='link'><a class="doclink" href="https://swagger.io/specification/v2/#contact-object">Swagger 2.0 Specification &gt; Contact Object</a>
066 *    <li class='link'><a class="doclink" href="https://swagger.io/docs/specification/2-0/api-general-info/">Swagger API General Info</a>
067 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a>
068 * </ul>
069 */
070@SuppressWarnings({
071   "java:S1192" // Duplicated literals (argument/property names) read more clearly inline than as constants
072})
073public class Contact extends SwaggerElement {
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.email = copyFrom.email;
093      this.name = copyFrom.name;
094      this.url = copyFrom.url;
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   @Override /* Overridden from SwaggerElement */
107   public <T> T get(String property, Class<T> type) {
108      reqnn("property", property);
109      return switch (property) {
110         case "email" -> toType(getEmail(), type);
111         case "name" -> toType(getName(), type);
112         case "url" -> toType(getUrl(), type);
113         default -> super.get(property, type);
114      };
115   }
116
117   /**
118    * Bean property getter:  <property>email</property>.
119    *
120    * <p>
121    * The email address of the contact person/organization.
122    *
123    * @return The property value, or <jk>null</jk> if it is not set.
124    */
125   public String getEmail() { return email; }
126
127   /**
128    * Bean property getter:  <property>name</property>.
129    *
130    * <p>
131    * The identifying name of the contact person/organization.
132    *
133    * @return The property value, or <jk>null</jk> if it is not set.
134    */
135   public String getName() { return name; }
136
137   /**
138    * Bean property getter:  <property>url</property>.
139    *
140    * <p>
141    * The URL pointing to the contact information.
142    *
143    * @return The property value, or <jk>null</jk> if it is not set.
144    */
145   public URI getUrl() { return url; }
146
147   @Override /* Overridden from SwaggerElement */
148   public Set<String> keySet() {
149      // @formatter:off
150      var s = stb(String.class)
151         .addIf(nn(email), "email")
152         .addIf(nn(name), "name")
153         .addIf(nn(url), "url")
154         .build();
155      // @formatter:on
156      return new MultiSet<>(s, super.keySet());
157   }
158
159   @Override /* Overridden from SwaggerElement */
160   public Contact set(String property, Object value) {
161      reqnn("property", property);
162      return switch (property) {
163         case "email" -> setEmail(s(value));
164         case "name" -> setName(s(value));
165         case "url" -> setUrl(toUri(value));
166         default -> {
167            super.set(property, value);
168            yield this;
169         }
170      };
171   }
172
173   /**
174    * Bean property setter:  <property>email</property>.
175    *
176    * <p>
177    * The email address of the contact person/organization.
178    *
179    * @param value
180    *    The new value for this property.
181    *    <br>MUST be in the format of an email address.
182    *    <br>Can be <jk>null</jk> to unset the property.
183    * @return This object.
184    */
185   public Contact setEmail(String value) {
186      email = value;
187      return this;
188   }
189
190   /**
191    * Bean property setter:  <property>name</property>.
192    *
193    * <p>
194    * The identifying name of the contact person/organization.
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 Contact setName(String value) {
202      name = value;
203      return this;
204   }
205
206   /**
207    * Bean property setter:  <property>url</property>.
208    *
209    * <p>
210    * The URL pointing to the contact information.
211    *
212    * @param value
213    *    The new value for this property.
214    *    <br>Can be <jk>null</jk> to unset the property.
215    * @return This object.
216    */
217   public Contact setUrl(URI value) {
218      url = value;
219      return this;
220   }
221
222   /**
223    * Sets strict mode on this bean.
224    *
225    * @return This object.
226    */
227   @Override
228   public Contact strict() {
229      super.strict();
230      return this;
231   }
232
233   /**
234    * Sets strict mode on this bean.
235    *
236    * @param value
237    *    The new value for this property.
238    *    <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
239    *    <br>Can be <jk>null</jk> (interpreted as <jk>false</jk>).
240    * @return This object.
241    */
242   @Override
243   public Contact strict(Object value) {
244      super.strict(value);
245      return this;
246   }
247}