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