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.UriResolver;
020import org.apache.juneau.annotation.Bean;
021import org.apache.juneau.internal.*;
022
023import java.net.URI;
024import java.util.Set;
025
026/**
027 * Allows referencing an external resource for extended documentation.
028 */
029@Bean(properties="description,url,*")
030@FluentSetters
031public class ExternalDocumentation extends OpenApiElement {
032
033   private String description;
034   private URI url;
035
036   /**
037    * Default constructor.
038    */
039   public ExternalDocumentation() {}
040
041   /**
042    * Copy constructor.
043    *
044    * @param copyFrom The object to copy.
045    */
046   public ExternalDocumentation(ExternalDocumentation copyFrom) {
047      super(copyFrom);
048
049      this.description = copyFrom.description;
050      this.url = copyFrom.url;
051   }
052
053   /**
054    * Make a deep copy of this object.
055    *
056    * @return A deep copy of this object.
057    */
058   public ExternalDocumentation copy() {
059      return new ExternalDocumentation(this);
060   }
061
062   /**
063    * Bean property getter:  <property>description</property>.
064    *
065    * <p>
066    * A short description of the target documentation.
067    *
068    * @return The property value, or <jk>null</jk> if it is not set.
069    */
070   public String getDescription() {
071      return description;
072   }
073
074   /**
075    * Bean property setter:  <property>description</property>.
076    *
077    * <p>
078    * A short description of the target documentation.
079    *
080    * @param value
081    *    The new value for this property.
082    *    <br>Can be <jk>null</jk> to unset the property.
083    * @return This object
084    */
085   public ExternalDocumentation setDescription(String value) {
086      description = value;
087      return this;
088   }
089
090   /**
091    * Bean property getter:  <property>url</property>.
092    *
093    * <p>
094    * The URL for the target documentation.
095    *
096    * @return The property value, or <jk>null</jk> if it is not set.
097    */
098   public URI getUrl() {
099      return url;
100   }
101
102   /**
103    * Bean property setter:  <property>url</property>.
104    *
105    * <p>
106    * The URL for the target documentation.
107    *
108    * @param value
109    *    The new value for this property.
110    *    <br>Property value is required.
111    *    <br>URIs defined by {@link UriResolver} can be used for values.
112    * @return This object
113    */
114   public ExternalDocumentation setUrl(URI value) {
115      url = value;
116      return this;
117   }
118
119   // <FluentSetters>
120
121   // </FluentSetters>
122
123   @Override /* OpenApiElement */
124   public <T> T get(String property, Class<T> type) {
125      if (property == null)
126         return null;
127      switch (property) {
128         case "description": return toType(getDescription(), type);
129         case "url": return toType(getUrl(), type);
130         default: return super.get(property, type);
131      }
132   }
133
134   @Override /* OpenApiElement */
135   public ExternalDocumentation set(String property, Object value) {
136      if (property == null)
137         return this;
138      switch (property) {
139         case "description": return setDescription(stringify(value));
140         case "url": return setUrl(toURI(value));
141         default:
142            super.set(property, value);
143            return this;
144      }
145   }
146
147   @Override /* OpenApiElement */
148   public Set<String> keySet() {
149      Set<String> s = setBuilder(String.class)
150         .addIf(description != null, "description")
151         .addIf(url != null, "url")
152         .build();
153      return new MultiSet<>(s, super.keySet());
154   }
155}