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.http.annotation;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021
022import java.lang.annotation.*;
023
024import org.apache.juneau.*;
025import org.apache.juneau.annotation.*;
026
027/**
028 * REST response status annotation.
029 *
030 * <p>
031 * Annotation used to denote an HTTP response status code.
032 *
033 * <p>
034 * Can be used in the following locations:
035 * <ul>
036 *    <li>Arguments of server-side <ja>@RestOp</ja>-annotated methods.
037 *    <li>Methods and return types of server-side and client-side <ja>@Response</ja>-annotated interfaces.
038 * </ul>
039 *
040 * <h5 class='topic'>Arguments of server-side <ja>@RestOp</ja>-annotated methods</h5>
041 *
042 * <p>
043 * On server-side REST, this annotation can be applied to method parameters to identify them as an HTTP response value.
044 *
045 * <h5 class='section'>Example:</h5>
046 * <p class='bjava'>
047 *    <ja>@RestPost</ja>
048 *    <jk>public void</jk> addPet(<ja>@Content</ja> Pet <jv>pet</jv>, <ja>@StatusCode</ja> Value&lt;Integer&gt; <jv>status</jv>) {
049 *       <jsm>addPet</jsm>(<jv>pet</jv>);
050 *       <jv>status</jv>.set(200);
051 *    }
052 * </p>
053 *
054 * <p>
055 * The parameter type must be {@link Value} with a parameterized type of {@link Integer}.
056 *
057 * <h5 class='topic'>Public methods of <ja>@Response</ja>-annotated types</h5>
058 *
059 * <p>
060 * On {@link Response @Response}-annotated classes, this method can be used to denote an HTTP status code on a response.
061 *
062 * <h5 class='section'>Example:</h5>
063 * <p class='bjava'>
064 *    <ja>@RestPost</ja>
065 *    <jk>public</jk> Success addPet(Pet <jv>pet</jv>) {
066 *       <jsm>addPet</jsm>(<jv>pet</jv>);
067 *       <jk>return new</jk> Success();
068 *    }
069 * </p>
070 *
071 * <p class='bjava'>
072 *    <ja>@Response</ja>
073 *    <jk>public class</jk> Success {
074 *
075 *       <ja>@StatusCode</ja>
076 *       <jk>public int</jk> getStatus() {
077 *          <jk>return</jk> 201;
078 *       }
079 *
080 *       <ja>@Override</ja>
081 *       <jk>public</jk> String toString() {
082 *          <jk>return</jk> <js>"Pet was successfully added"</js>;
083 *       }
084 *    }
085 * </p>
086 *
087 * <p>
088 * The method being annotated must be public and return a numeric value.
089 *
090 *
091 * <h5 class='section'>See Also:</h5><ul>
092 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a>
093 * </ul>
094 *
095 * <h5 class='topic'>Methods and return types of server-side and client-side @Response-annotated interfaces</h5>
096 *
097 * <h5 class='section'>See Also:</h5><ul>
098 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Response">@Response</a>
099 * </ul>
100 *
101 * <p>
102 * <h5 class='section'>See Also:</h5><ul>
103
104 * </ul>
105 */
106@Documented
107@Target({PARAMETER,METHOD,TYPE})
108@Retention(RUNTIME)
109@Inherited
110@Repeatable(StatusCodeAnnotation.Array.class)
111@ContextApply(StatusCodeAnnotation.Applier.class)
112public @interface StatusCode {
113
114    /**
115     * Optional description for the exposed API.
116     *
117     * @return The annotation value.
118     * @since 9.2.0
119     */
120    String[] description() default {};
121
122   /**
123    * Dynamically apply this annotation to the specified classes.
124    *
125    * <h5 class='section'>See Also:</h5><ul>
126    *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
127    * </ul>
128    *
129    * @return The annotation value.
130    */
131   String[] on() default {};
132
133   /**
134    * Dynamically apply this annotation to the specified classes.
135    *
136    * <p>
137    * Identical to {@link #on()} except allows you to specify class objects instead of a strings.
138    *
139    * <h5 class='section'>See Also:</h5><ul>
140    *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
141    * </ul>
142    *
143    * @return The annotation value.
144    */
145   Class<?>[] onClass() default {};
146
147   /**
148    * The HTTP response codes.
149    *
150    * The default value is <c>500</c> for exceptions and <c>200</c> for return types.
151    *
152    * @return The annotation value.
153    */
154   int[] value() default {};
155}