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.rest.annotation;
014
015import static org.apache.juneau.internal.ArrayUtils.*;
016
017import java.lang.annotation.*;
018
019import org.apache.juneau.annotation.*;
020
021/**
022 * Utility classes and methods for the {@link OpSwagger @OpSwagger} annotation.
023 *
024 * <h5 class='section'>See Also:</h5><ul>
025 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.Swagger">Swagger</a>
026 * </ul>
027 */
028public class OpSwaggerAnnotation {
029
030   //-----------------------------------------------------------------------------------------------------------------
031   // Static
032   //-----------------------------------------------------------------------------------------------------------------
033
034   /** Default value */
035   public static final OpSwagger DEFAULT = create().build();
036
037   /**
038    * Instantiates a new builder for this class.
039    *
040    * @return A new builder object.
041    */
042   public static Builder create() {
043      return new Builder();
044   }
045
046   /**
047    * Returns <jk>true</jk> if the specified annotation contains all default values.
048    *
049    * @param a The annotation to check.
050    * @return <jk>true</jk> if the specified annotation contains all default values.
051    */
052   public static boolean empty(OpSwagger a) {
053      return a == null || DEFAULT.equals(a);
054   }
055
056   /**
057    * Returns <jk>false</jk> if the specified annotation contains all default values.
058    *
059    * @param a The annotation to check.
060    * @return <jk>false</jk> if the specified annotation contains all default values.
061    */
062   public static boolean notEmpty(OpSwagger a) {
063      return ! empty(a);
064   }
065
066   //-----------------------------------------------------------------------------------------------------------------
067   // Builder
068   //-----------------------------------------------------------------------------------------------------------------
069
070   /**
071    * Builder class.
072    *
073    * <h5 class='section'>See Also:</h5><ul>
074    *    <li class='jm'>{@link org.apache.juneau.BeanContext.Builder#annotations(Annotation...)}
075    * </ul>
076    */
077   public static class Builder extends AnnotationBuilder {
078
079      ExternalDocs externalDocs = ExternalDocsAnnotation.DEFAULT;
080      String deprecated="", operationId="";
081      String[] consumes={}, description={}, parameters={}, produces={}, responses={}, schemes={}, summary={}, tags={}, value={};
082
083      /**
084       * Constructor.
085       */
086      protected Builder() {
087         super(OpSwagger.class);
088      }
089
090      /**
091       * Instantiates a new {@link OpSwagger @OpSwagger} object initialized with this builder.
092       *
093       * @return A new {@link OpSwagger @OpSwagger} object.
094       */
095      public OpSwagger build() {
096         return new Impl(this);
097      }
098
099      /**
100       * Sets the {@link OpSwagger#consumes()} property on this annotation.
101       *
102       * @param value The new value for this property.
103       * @return This object.
104       */
105      public Builder consumes(String...value) {
106         this.consumes = value;
107         return this;
108      }
109
110      /**
111       * Sets the {@link OpSwagger#deprecated()} property on this annotation.
112       *
113       * @param value The new value for this property.
114       * @return This object.
115       */
116      public Builder deprecated(String value) {
117         this.deprecated = value;
118         return this;
119      }
120
121      /**
122       * Sets the {@link OpSwagger#description()} property on this annotation.
123       *
124       * @param value The new value for this property.
125       * @return This object.
126       */
127      public Builder description(String...value) {
128         this.description = value;
129         return this;
130      }
131
132      /**
133       * Sets the {@link OpSwagger#externalDocs()} property on this annotation.
134       *
135       * @param value The new value for this property.
136       * @return This object.
137       */
138      public Builder externalDocs(ExternalDocs value) {
139         this.externalDocs = value;
140         return this;
141      }
142
143      /**
144       * Sets the {@link OpSwagger#operationId()} property on this annotation.
145       *
146       * @param value The new value for this property.
147       * @return This object.
148       */
149      public Builder operationId(String value) {
150         this.operationId = value;
151         return this;
152      }
153
154      /**
155       * Sets the {@link OpSwagger#parameters()} property on this annotation.
156       *
157       * @param value The new value for this property.
158       * @return This object.
159       */
160      public Builder parameters(String...value) {
161         this.parameters = value;
162         return this;
163      }
164
165      /**
166       * Sets the {@link OpSwagger#produces()} property on this annotation.
167       *
168       * @param value The new value for this property.
169       * @return This object.
170       */
171      public Builder produces(String...value) {
172         this.produces = value;
173         return this;
174      }
175
176      /**
177       * Sets the {@link OpSwagger#responses()} property on this annotation.
178       *
179       * @param value The new value for this property.
180       * @return This object.
181       */
182      public Builder responses(String...value) {
183         this.responses = value;
184         return this;
185      }
186
187      /**
188       * Sets the {@link OpSwagger#schemes()} property on this annotation.
189       *
190       * @param value The new value for this property.
191       * @return This object.
192       */
193      public Builder schemes(String...value) {
194         this.schemes = value;
195         return this;
196      }
197
198      /**
199       * Sets the {@link OpSwagger#summary()} property on this annotation.
200       *
201       * @param value The new value for this property.
202       * @return This object.
203       */
204      public Builder summary(String...value) {
205         this.summary = value;
206         return this;
207      }
208
209      /**
210       * Sets the {@link OpSwagger#tags()} property on this annotation.
211       *
212       * @param value The new value for this property.
213       * @return This object.
214       */
215      public Builder tags(String...value) {
216         this.tags = value;
217         return this;
218      }
219
220      /**
221       * Sets the {@link OpSwagger#value()} property on this annotation.
222       *
223       * @param value The new value for this property.
224       * @return This object.
225       */
226      public Builder value(String...value) {
227         this.value = value;
228         return this;
229      }
230
231      // <FluentSetters>
232
233      // </FluentSetters>
234   }
235
236   //-----------------------------------------------------------------------------------------------------------------
237   // Implementation
238   //-----------------------------------------------------------------------------------------------------------------
239
240   private static class Impl extends AnnotationImpl implements OpSwagger {
241
242      private final ExternalDocs externalDocs;
243      private final String deprecated, operationId;
244      private final String[] consumes, description, parameters, produces, responses, schemes, summary, tags, value;
245
246      Impl(Builder b) {
247         super(b);
248         this.consumes = copyOf(b.consumes);
249         this.deprecated = b.deprecated;
250         this.description = copyOf(b.description);
251         this.externalDocs = b.externalDocs;
252         this.operationId = b.operationId;
253         this.parameters = copyOf(b.parameters);
254         this.produces = copyOf(b.produces);
255         this.responses = copyOf(b.responses);
256         this.schemes = copyOf(b.schemes);
257         this.summary = copyOf(b.summary);
258         this.tags = copyOf(b.tags);
259         this.value = copyOf(b.value);
260         postConstruct();
261      }
262
263      @Override /* OpSwagger */
264      public String[] consumes() {
265         return consumes;
266      }
267
268      @Override /* OpSwagger */
269      public String deprecated() {
270         return deprecated;
271      }
272
273      @Override /* OpSwagger */
274      public String[] description() {
275         return description;
276      }
277
278      @Override /* OpSwagger */
279      public ExternalDocs externalDocs() {
280         return externalDocs;
281      }
282
283      @Override /* OpSwagger */
284      public String operationId() {
285         return operationId;
286      }
287
288      @Override /* OpSwagger */
289      public String[] parameters() {
290         return parameters;
291      }
292
293      @Override /* OpSwagger */
294      public String[] produces() {
295         return produces;
296      }
297
298      @Override /* OpSwagger */
299      public String[] responses() {
300         return responses;
301      }
302
303      @Override /* OpSwagger */
304      public String[] schemes() {
305         return schemes;
306      }
307
308      @Override /* OpSwagger */
309      public String[] summary() {
310         return summary;
311      }
312
313      @Override /* OpSwagger */
314      public String[] tags() {
315         return tags;
316      }
317
318      @Override /* OpSwagger */
319      public String[] value() {
320         return value;
321      }
322   }
323}