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.Utils.*;
020import static org.apache.juneau.internal.CollectionUtils.*;
021import static org.apache.juneau.internal.ConverterUtils.*;
022
023import java.net.*;
024import java.util.*;
025
026import org.apache.juneau.*;
027import org.apache.juneau.common.utils.*;
028import org.apache.juneau.internal.*;
029
030/**
031 * License information for the exposed API.
032 *
033 * <p>
034 * The License Object provides license information for the exposed API in Swagger 2.0. This information helps clients 
035 * understand the terms under which the API can be used, including any restrictions or requirements.
036 *
037 * <h5 class='section'>Swagger Specification:</h5>
038 * <p>
039 * The License Object is composed of the following fields:
040 * <ul class='spaced-list'>
041 *    <li><c>name</c> (string, REQUIRED) - The license name used for the API
042 *    <li><c>url</c> (string) - A URL to the license used for the API
043 * </ul>
044 *
045 * <h5 class='section'>Example:</h5>
046 * <p class='bjava'>
047 *    <jc>// Construct using SwaggerBuilder.</jc>
048 *    License <jv>license</jv> = <jsm>license</jsm>(<js>"Apache 2.0"</js>, <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js>);
049 *
050 *    <jc>// Serialize using JsonSerializer.</jc>
051 *    String <jv>json</jv> = Json.<jsm>from</jsm>(<jv>license</jv>);
052 *
053 *    <jc>// Or just use toString() which does the same as above.</jc>
054 *    <jv>json</jv> = <jv>license</jv>.toString();
055 * </p>
056 * <p class='bjson'>
057 *    <jc>// Output</jc>
058 *    {
059 *       <js>"name"</js>: <js>"Apache 2.0"</js>,
060 *       <js>"url"</js>: <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</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/#license-object">Swagger 2.0 Specification &gt; License 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 */
070public class License extends SwaggerElement {
071
072   private String name;
073   private URI url;
074
075   /**
076    * Default constructor.
077    */
078   public License() {}
079
080   /**
081    * Copy constructor.
082    *
083    * @param copyFrom The object to copy.
084    */
085   public License(License copyFrom) {
086      super(copyFrom);
087
088      this.name = copyFrom.name;
089      this.url = copyFrom.url;
090   }
091
092   /**
093    * Make a deep copy of this object.
094    *
095    * @return A deep copy of this object.
096    */
097   public License copy() {
098      return new License(this);
099   }
100
101   //-----------------------------------------------------------------------------------------------------------------
102   // Properties
103   //-----------------------------------------------------------------------------------------------------------------
104
105   /**
106    * Bean property getter:  <property>name</property>.
107    *
108    * <p>
109    * The license name used for the API.
110    *
111    * @return The property value, or <jk>null</jk> if it is not set.
112    */
113   public String getName() {
114      return name;
115   }
116
117   /**
118    * Bean property setter:  <property>name</property>.
119    *
120    * <p>
121    * The license name used for the API.
122    *
123    * @param value
124    *    The new value for this property.
125    *    <br>Property value is required.
126    *    <br>Can be <jk>null</jk> to unset the property.
127    * @return This object.
128    */
129   public License setName(String value) {
130      name = value;
131      return this;
132   }
133
134   /**
135    * Bean property getter:  <property>url</property>.
136    *
137    * <p>
138    * A URL to the license used for the API.
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    * A URL to the license used for the API.
151    *
152    * @param value
153    *    The new value for this property.
154    *    <br>URIs defined by {@link UriResolver} can be used for values.
155    *    <br>Can be <jk>null</jk> to unset the property.
156    * @return This object.
157    */
158   public License setUrl(URI value) {
159      url = value;
160      return this;
161   }
162
163   @Override /* Overridden from SwaggerElement */
164   public <T> T get(String property, Class<T> type) {
165      assertArgNotNull("property", property);
166      return switch (property) {
167         case "name" -> toType(getName(), type);
168         case "url" -> toType(getUrl(), type);
169         default -> super.get(property, type);
170      };
171   }
172
173   @Override /* Overridden from SwaggerElement */
174   public License set(String property, Object value) {
175      assertArgNotNull("property", property);
176      return switch (property) {
177         case "name" -> setName(Utils.s(value));
178         case "url" -> setUrl(StringUtils.toURI(value));
179         default -> {
180            super.set(property, value);
181            yield this;
182         }
183      };
184   }
185
186   @Override /* Overridden from SwaggerElement */
187   public Set<String> keySet() {
188      var s = setBuilder(String.class)
189         .addIf(name != null, "name")
190         .addIf(url != null, "url")
191         .build();
192      return new MultiSet<>(s, super.keySet());
193   }
194
195   /**
196    * Sets strict mode on this bean.
197    *
198    * @return This object.
199    */
200   @Override
201   public License strict() {
202      super.strict();
203      return this;
204   }
205
206   /**
207    * Sets strict mode on this bean.
208    *
209    * @param value
210    *    The new value for this property.
211    *    <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
212    *    <br>Can be <jk>null</jk> (interpreted as <jk>false</jk>).
213    * @return This object.
214    */
215   @Override
216   public License strict(Object value) {
217      super.strict(value);
218      return this;
219   }
220
221}