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