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.annotation.*;
025import org.apache.juneau.httppart.*;
026import org.apache.juneau.oapi.*;
027
028/**
029 * Request bean annotation.
030 *
031 * <p>
032 * Identifies an interface to use to interact with HTTP parts of an HTTP request through a bean.
033 *
034 * <p>
035 * Can be used in the following locations:
036 * <ul>
037 *    <li>Arguments and argument-types of server-side <ja>@RestOp</ja>-annotated methods.
038 *    <li>Arguments and argument-types of client-side <ja>@RemoteResource</ja>-annotated interfaces.
039 * </ul>
040 *
041 * <h5 class='topic'>Arguments and argument-types of server-side @RestOp-annotated methods</h5>
042 * <p>
043 * Annotation that can be applied to a parameter of a <ja>@RestOp</ja>-annotated method to identify it as an interface for retrieving HTTP parts through a bean interface.
044 *
045 * <h5 class='section'>Example:</h5>
046 * <p class='bjava'>
047 *    <ja>@RestGet</ja>(<js>"/mypath/{p1}/{p2}/*"</js>)
048 *    <jk>public void</jk> myMethod(<ja>@Request</ja> MyRequest <jv>requestBean</jv>) {...}
049 *
050 *    <jk>public interface</jk> MyRequest {
051 *
052 *       <ja>@Path</ja> <jc>// Path variable name inferred from getter.</jc>
053 *       String getP1();
054 *
055 *       <ja>@Path</ja>(<js>"p2"</js>)
056 *       String getX();
057 *
058 *       <ja>@Path</ja>(<js>"/*"</js>)
059 *       String getRemainder();
060 *
061 *       <ja>@Query</ja>
062 *       String getQ1();
063 *
064 *    <jc>// Schema-based query parameter:  Pipe-delimited lists of comma-delimited lists of integers.</jc>
065 *       <ja>@Query</ja>(
066 *          collectionFormat=<js>"pipes"</js>
067 *          items=<ja>@Items</ja>(
068 *             items=<ja>@SubItems</ja>(
069 *                collectionFormat=<js>"csv"</js>
070 *                type=<js>"integer"</js>
071 *             )
072 *          )
073 *       )
074 *       <jk>int</jk>[][] getQ3();
075 *
076 *       <ja>@Header</ja>(<js>"*"</js>)
077 *       Map&lt;String,Object&gt; getHeaders();
078 * </p>
079 * <p class='bjava'>
080 *    <jc>// Same as above but annotation defined on interface.</jc>
081 *    <ja>@RestGet</ja>(path=<js>"/mypath/{p1}/{p2}/*"</js>)
082 *    <jk>public void</jk> myMethod(MyRequest <jv>requestBean</jv>) {...}
083 *
084 * <ja>@Request</ja>
085 *    <jk>public interface</jk> MyRequest {...}
086 *
087 * <p>
088 * The return types of the getters must be the supported parameter types for the HTTP-part annotation used.
089 * <br>Schema-based serialization and parsing is allowed just as if used as individual parameter types.
090 *
091 *
092 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5>
093 * <p>
094 * Annotation applied to Java method arguments of interface proxies to denote a bean with remote resource annotations.
095 *
096 * <h5 class='section'>Example:</h5>
097 * <p class='bjava'>
098 *    <ja>@RemoteResource</ja>(path=<js>"/myproxy"</js>)
099 *    <jk>public interface</jk> MyProxy {
100 *
101 *       <ja>@RemoteGet</ja>(<js>"/mymethod/{p1}/{p2}"</js>)
102 *       String myProxyMethod(<ja>@Request</ja> MyRequest <jv>requestBean</jv>);
103 *    }
104 *
105 *    <jk>public class</jk> MyRequest {
106 *
107 *       <ja>@Path</ja> <jc>// Path variable name inferred from getter.</jc>
108 *       <jk>public</jk> String getP1() {...}
109 *
110 *       <ja>@Path</ja>(<js>"p2"</js>)
111 *       <jk>public</jk> String getX() {...}
112 *
113 *       <ja>@Path</ja>(<js>"/*"</js>)
114 *       <jk>public</jk> String getRemainder() {...}
115 *
116 *       <ja>@Query</ja>
117 *       <jk>public</jk> String getQ1() {...}
118 *
119 *    <jc>// Schema-based query parameter:  Pipe-delimited lists of comma-delimited lists of integers.</jc>
120 *       <ja>@Query</ja>(
121 *          schema=<ja>@Query</ja>(
122 *             collectionFormat=<js>"pipes"</js>
123 *             items=<ja>@Items</ja>(
124 *                items=<ja>@SubItems</ja>(
125 *                   collectionFormat=<js>"csv"</js>
126 *                   type=<js>"integer"</js>
127 *                )
128 *             )
129 *          )
130 *       )
131 *       <jk>public</jk> <jk>int</jk>[][] getQ3() {...}
132 *
133 *       <ja>@Header</ja>(<js>"*"</js>)
134 *       <jk>public</jk> Map&lt;String,Object&gt; getHeaders() {...}
135 *    }
136 * </p>
137 *
138 * <h5 class='section'>See Also:</h5><ul>
139 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Request">@Request</a>
140 * </ul>
141 * <p>
142 */
143@Documented
144@Target({ PARAMETER, TYPE, METHOD })
145@Retention(RUNTIME)
146@Inherited
147@Repeatable(RequestAnnotation.Array.class)
148@ContextApply(RequestAnnotation.Applier.class)
149public @interface Request {
150
151   /**
152    * Optional description for the exposed API.
153    *
154    * @return The annotation value.
155    * @since 9.2.0
156    */
157   String[] description() default {};
158
159   /**
160    * Dynamically apply this annotation to the specified classes.
161    *
162    * <h5 class='section'>See Also:</h5><ul>
163    *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
164    * </ul>
165    *
166    * @return The annotation value.
167    */
168   String[] on() default {};
169
170   /**
171    * Dynamically apply this annotation to the specified classes.
172    *
173    * <p>
174    * Identical to {@link #on()} except allows you to specify class objects instead of a strings.
175    *
176    * <h5 class='section'>See Also:</h5><ul>
177    *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
178    * </ul>
179    *
180    * @return The annotation value.
181    */
182   Class<?>[] onClass() default {};
183
184   /**
185    * Specifies the {@link HttpPartParser} class used for parsing strings to values.
186    *
187    * <p>
188    * Overrides for this part the part parser defined on the REST resource which by default is {@link OpenApiParser}.
189    *
190    * @return The annotation value.
191    */
192   Class<? extends HttpPartParser> parser() default HttpPartParser.Void.class;
193
194   /**
195    * Specifies the {@link HttpPartSerializer} class used for serializing values to strings.
196    *
197    * <p>
198    * Overrides for this part the part serializer defined on the REST client which by default is {@link OpenApiSerializer}.
199    *
200    * @return The annotation value.
201    */
202   Class<? extends HttpPartSerializer> serializer() default HttpPartSerializer.Void.class;
203}