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