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