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.commons.utils.CollectionUtils.*; 020 021import java.lang.annotation.*; 022 023import org.apache.juneau.annotation.*; 024import org.apache.juneau.commons.annotation.*; 025import org.apache.juneau.http.annotation.*; 026 027/** 028 * Utility classes and methods for the {@link Swagger @Swagger} annotation. 029 * 030 * <h5 class='section'>See Also:</h5><ul> 031 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> 032 * </ul> 033 */ 034public class SwaggerAnnotation { 035 /** 036 * Builder class. 037 * 038 * <h5 class='section'>See Also:</h5><ul> 039 * <li class='jm'>{@link org.apache.juneau.BeanContext.Builder#annotations(Annotation...)} 040 * </ul> 041 */ 042 public static class Builder extends AnnotationObject.Builder { 043 044 private String[] description = {}; 045 private Contact contact = ContactAnnotation.DEFAULT; 046 private ExternalDocs externalDocs = ExternalDocsAnnotation.DEFAULT; 047 private License license = LicenseAnnotation.DEFAULT; 048 private String version = ""; 049 private String[] termsOfService = {}, title = {}, value = {}; 050 private Tag[] tags = {}; 051 052 /** 053 * Constructor. 054 */ 055 protected Builder() { 056 super(Swagger.class); 057 } 058 059 /** 060 * Instantiates a new {@link Swagger @Swagger} object initialized with this builder. 061 * 062 * @return A new {@link Swagger @Swagger} object. 063 */ 064 public Swagger build() { 065 return new Object(this); 066 } 067 068 /** 069 * Sets the description property on this annotation. 070 * 071 * @param value The new value for this property. 072 * @return This object. 073 */ 074 public Builder description(String...value) { 075 description = value; 076 return this; 077 } 078 079 /** 080 * Sets the {@link Swagger#contact()} property on this annotation. 081 * 082 * @param value The new value for this property. 083 * @return This object. 084 */ 085 public Builder contact(Contact value) { 086 contact = value; 087 return this; 088 } 089 090 /** 091 * Sets the {@link Swagger#externalDocs()} property on this annotation. 092 * 093 * @param value The new value for this property. 094 * @return This object. 095 */ 096 public Builder externalDocs(ExternalDocs value) { 097 externalDocs = value; 098 return this; 099 } 100 101 /** 102 * Sets the {@link Swagger#license()} property on this annotation. 103 * 104 * @param value The new value for this property. 105 * @return This object. 106 */ 107 public Builder license(License value) { 108 license = value; 109 return this; 110 } 111 112 /** 113 * Sets the {@link Swagger#tags()} property on this annotation. 114 * 115 * @param value The new value for this property. 116 * @return This object. 117 */ 118 public Builder tags(Tag...value) { 119 tags = value; 120 return this; 121 } 122 123 /** 124 * Sets the {@link Swagger#termsOfService()} property on this annotation. 125 * 126 * @param value The new value for this property. 127 * @return This object. 128 */ 129 public Builder termsOfService(String...value) { 130 termsOfService = value; 131 return this; 132 } 133 134 /** 135 * Sets the {@link Swagger#title()} property on this annotation. 136 * 137 * @param value The new value for this property. 138 * @return This object. 139 */ 140 public Builder title(String...value) { 141 title = value; 142 return this; 143 } 144 145 /** 146 * Sets the {@link Swagger#value()} property on this annotation. 147 * 148 * @param value The new value for this property. 149 * @return This object. 150 */ 151 public Builder value(String...value) { 152 this.value = value; 153 return this; 154 } 155 156 /** 157 * Sets the {@link Swagger#version()} property on this annotation. 158 * 159 * @param value The new value for this property. 160 * @return This object. 161 */ 162 public Builder version(String value) { 163 version = value; 164 return this; 165 } 166 167 } 168 169 private static class Object extends AnnotationObject implements Swagger { 170 171 private final String[] description; 172 private final Contact contact; 173 private final ExternalDocs externalDocs; 174 private final License license; 175 private final String version; 176 private final String[] termsOfService, title, value; 177 private final Tag[] tags; 178 179 Object(SwaggerAnnotation.Builder b) { 180 super(b); 181 description = copyOf(b.description); 182 contact = b.contact; 183 externalDocs = b.externalDocs; 184 license = b.license; 185 tags = copyOf(b.tags); 186 termsOfService = copyOf(b.termsOfService); 187 title = copyOf(b.title); 188 value = copyOf(b.value); 189 version = b.version; 190 } 191 192 @Override /* Overridden from Swagger */ 193 public Contact contact() { 194 return contact; 195 } 196 197 @Override /* Overridden from Swagger */ 198 public ExternalDocs externalDocs() { 199 return externalDocs; 200 } 201 202 @Override /* Overridden from Swagger */ 203 public License license() { 204 return license; 205 } 206 207 @Override /* Overridden from Swagger */ 208 public Tag[] tags() { 209 return tags; 210 } 211 212 @Override /* Overridden from Swagger */ 213 public String[] termsOfService() { 214 return termsOfService; 215 } 216 217 @Override /* Overridden from Swagger */ 218 public String[] title() { 219 return title; 220 } 221 222 @Override /* Overridden from Swagger */ 223 public String[] value() { 224 return value; 225 } 226 227 @Override /* Overridden from Swagger */ 228 public String version() { 229 return version; 230 } 231 232 @Override /* Overridden from annotation */ 233 public String[] description() { 234 return description; 235 } 236 } 237 238 /** Default value */ 239 public static final Swagger DEFAULT = create().build(); 240 241 /** 242 * Instantiates a new builder for this class. 243 * 244 * @return A new builder object. 245 */ 246 public static Builder create() { 247 return new Builder(); 248 } 249 250 /** 251 * Returns <jk>true</jk> if the specified annotation contains all default values. 252 * 253 * @param a The annotation to check. 254 * @return <jk>true</jk> if the specified annotation contains all default values. 255 */ 256 public static boolean empty(Swagger a) { 257 return a == null || DEFAULT.equals(a); 258 } 259}