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