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