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.internal.*;
021
022import java.util.Set;
023
024/**
025 * information for Examples object.
026 *
027 * <h5 class='section'>Example:</h5>
028 * <p class='bcode'>
029 *    <jc>// Construct using SwaggerBuilder.</jc>
030 *    Contact x = <jsm>contact</jsm>(<js>"API Support"</js>, <js>"http://www.swagger.io/support"</js>, <js>"support@swagger.io"</js>);
031 *
032 *    <jc>// Serialize using JsonSerializer.</jc>
033 *    String json = JsonSerializer.<jsf>DEFAULT</jsf>.toString(x);
034 *
035 *    <jc>// Or just use toString() which does the same as above.</jc>
036 *    String json = x.toString();
037 * </p>
038 * <p class='bcode'>
039 *    <jc>// Output</jc>
040 *    {
041 *       <js>"name"</js>: <js>"API Support"</js>,
042 *       <js>"url"</js>: <js>"http://www.swagger.io/support"</js>,
043 *       <js>"email"</js>: <js>"support@swagger.io"</js>
044 *    }
045 * </p>
046 */
047@Bean(properties="summary,description,externalValue,value,*")
048@FluentSetters
049public class Example extends OpenApiElement {
050
051   private String summary;
052   private String description;
053   private String externalValue;
054   private Object value;
055
056   /**
057    * Default constructor.
058    */
059   public Example() {}
060
061   /**
062    * Copy constructor.
063    *
064    * @param copyFrom The object to copy.
065    */
066   public Example(Example copyFrom) {
067      super(copyFrom);
068
069      this.summary = copyFrom.summary;
070      this.description = copyFrom.description;
071      this.externalValue = copyFrom.externalValue;
072      this.value = copyFrom.value;
073   }
074
075   /**
076    * Make a deep copy of this object.
077    *
078    * @return A deep copy of this object.
079    */
080   public Example copy() {
081      return new Example(this);
082   }
083
084   /**
085    * Bean property getter:  <property>summary</property>.
086    *
087    * <p>
088    * The identifying name of the contact person/organization.
089    *
090    * @return The property value, or <jk>null</jk> if it is not set.
091    */
092   public String getSummary() {
093      return summary;
094   }
095
096   /**
097    * Bean property setter:  <property>summary</property>.
098    *
099    * <p>
100    * The identifying name of the contact person/organization.
101    *
102    * @param value
103    *    The new value for this property.
104    *    <br>Can be <jk>null</jk> to unset the property.
105    * @return This object
106    */
107   public Example setSummary(String value) {
108      summary = value;
109      return this;
110   }
111
112   /**
113    * Bean property getter:  <property>description</property>.
114    *
115    * <p>
116    * The URL pointing to the contact information.
117    *
118    * @return The property value, or <jk>null</jk> if it is not set.
119    */
120   public String getDescription() {
121      return description;
122   }
123
124   /**
125    * Bean property setter:  <property>description</property>.
126    * @param value
127    *    The new value for this property.
128    *    <br>Can be <jk>null</jk> to unset the property.
129    * @return This object
130    */
131   public Example setDescription(String value) {
132      description = value;
133      return this;
134   }
135
136   /**
137    * Bean property getter:  <property>externalValue</property>.
138    *
139    * <p>
140    * The email address of the contact person/organization.
141    *
142    * @return The property value, or <jk>null</jk> if it is not set.
143    */
144   public String getExternalValue() {
145      return externalValue;
146   }
147
148   /**
149    * Bean property setter:  <property>externalValue</property>.
150    *
151    * <p>
152    * The email address of the contact person/organization.
153    *
154    * @param value
155    *    The new value for this property.
156    *    <br>MUST be in the format of an email address.
157    *    <br>Can be <jk>null</jk> to unset the property.
158    * @return This object
159    */
160   public Example setExternalValue(String value) {
161      externalValue = value;
162      return this;
163   }
164
165   /**
166    * Bean property getter:  <property>default</property>.
167    *
168    * <p>
169    * Declares the value of the parameter that the server will use if none is provided, for example a <js>"count"</js>
170    * to control the number of results per page might default to 100 if not supplied by the client in the request.
171    *
172    * (Note: <js>"value"</js> has no meaning for required parameters.)
173    * Unlike JSON Schema this value MUST conform to the defined <code>type</code> for this parameter.
174    *
175    * @return The property value, or <jk>null</jk> if it is not set.
176    */
177   public Object getValue() {
178      return value;
179   }
180
181   /**
182    * Bean property setter:  <property>value</property>.
183    *
184    * <p>
185    * Declares the value of the parameter that the server will use if none is provided, for example a <js>"count"</js>
186    * to control the number of results per page might default to 100 if not supplied by the client in the request.
187    * (Note: <js>"default"</js> has no meaning for required parameters.)
188    * Unlike JSON Schema this value MUST conform to the defined <code>type</code> for this parameter.
189    *
190    * @param val The new value for this property.
191    * @return This object
192    */
193   public Example setValue(Object val) {
194      value = val;
195      return this;
196   }
197
198   // <FluentSetters>
199
200   // </FluentSetters>
201
202   @Override /* OpenApiElement */
203   public <T> T get(String property, Class<T> type) {
204      if (property == null)
205         return null;
206      switch (property) {
207         case "description": return toType(getDescription(), type);
208         case "externalValue": return toType(getExternalValue(), type);
209         case "summary": return toType(getSummary(), type);
210         case "value": return toType(getValue(), type);
211         default: return super.get(property, type);
212      }
213   }
214
215   @Override /* OpenApiElement */
216   public Example set(String property, Object value) {
217      if (property == null)
218         return this;
219      switch (property) {
220         case "description": return setDescription(stringify(value));
221         case "externalValue": return setExternalValue(stringify(value));
222         case "summary": return setSummary(stringify(value));
223         case "value": return setValue(value);
224         default:
225            super.set(property, value);
226            return this;
227      }
228   }
229
230   @Override /* OpenApiElement */
231   public Set<String> keySet() {
232      Set<String> s = setBuilder(String.class)
233         .addIf(description != null, "description")
234            .addIf(summary != null, "summary")
235            .addIf(externalValue != null, "externalValue")
236         .addIf(value != null, "value")
237         .build();
238      return new MultiSet<>(s, super.keySet());
239   }
240}