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;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021
022import java.lang.annotation.*;
023
024import org.apache.juneau.commons.*;
025
026/**
027 * REST request form-data annotation.
028 *
029 * <p>
030 *    Identifies a POJO to be used as a form-data entry on an HTTP request.
031 *
032 * <p>
033 * Can be used in the following locations:
034 * <ul>
035 *    <li>Arguments and argument-types of server-side <ja>@RestOp</ja>-annotated methods.
036 *    <li>Arguments and argument-types of client-side <ja>@RemoteResource</ja>-annotated interfaces.
037 *    <li>Methods and return types of server-side and client-side <ja>@Request</ja>-annotated interfaces.
038 * </ul>
039 *
040 * <h5 class='topic'>Arguments and argument-types of server-side @RestOp-annotated methods</h5>
041 * <p>
042 * Annotation that can be applied to a parameter of a <ja>@RestOp</ja>-annotated method to identify it as a URL query parameter.
043 *
044 * <p>
045 * Unlike {@link FormData @FormData}, using this annotation does not result in the servlet reading the contents of
046 * URL-encoded form posts.
047 * Therefore, this annotation can be used in conjunction with the {@link Content @Content} annotation or
048 * <c>RestRequest.getContent()</c> method for <c>application/x-www-form-urlencoded POST</c> calls.
049 *
050 * <h5 class='section'>Example:</h5>
051 * <p class='bjava'>
052 *    <ja>@RestGet</ja>
053 *    <jk>public void</jk> doGet(
054 *          <ja>@Query</ja>(<js>"p1"</js>) <jk>int</jk> <jv>p1</jv>,
055 *          <ja>@Query</ja>(<js>"p2"</js>) String <jv>p2</jv>,
056 *          <ja>@Query</ja>(<js>"p3"</js>) UUID <jv>p3</jv>
057 *       ) {...}
058 * </p>
059 *
060 * <p>
061 * This is functionally equivalent to the following code...
062 * <p class='bjava'>
063 *    <ja>@RestGet</ja>
064 *    <jk>public void</jk> doGet(RestRequest <jv>req</jv>, RestResponse <jv>res</jv>) {
065 *       <jk>int</jk> <jv>p1</jv> = <jv>req</jv>.getQueryParam(<js>"p1"</js>).asInteger().orElse(0);
066 *       String <jv>p2</jv> = <jv>req</jv>.getQueryParam(<js>"p2"</js>).asString().orElse(<jk>null</jk>);
067 *       UUID <jv>p3</jv> = <jv>req</jv>.getQueryParam(<js>"p3"</js>).as(UUID.<jk>class</jk>).orElse(<jk>null</jk>);
068 *       ...
069 *    }
070 * </p>
071 *
072 * <h5 class='section'>See Also:</h5><ul>
073 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a>
074 *    <li class='extlink'><a class='doclink' href='https://swagger.io/specification/v2#parameterObject'>Swagger Parameter Object</a>
075 * </ul>
076 *
077 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5>
078 * <p>
079 * <h5 class='section'>See Also:</h5><ul>
080 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Query">@Query</a>
081 * </ul>
082 *
083 * <h5 class='topic'>Methods and return types of server-side and client-side @Request-annotated interfaces</h5>
084 * <p>
085 * <h5 class='section'>See Also:</h5><ul>
086 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Request">@Request</a>
087 * </ul>
088 * <p>
089 */
090@Documented
091@Target({ PARAMETER, METHOD, TYPE, FIELD })
092@Retention(RUNTIME)
093@Inherited
094public @interface Query {
095
096   /**
097    * Default value for this parameter.
098    *
099    * @return The annotation value.
100    */
101   String def() default "";
102
103   /**
104    * Optional description for the exposed API.
105    *
106    * @return The annotation value.
107    * @since 9.2.0
108    */
109   String[] description() default {};
110
111   /**
112    * Short, concise summary of the exposed API.
113    *
114    * <p>
115    * Intended as a brief, single-line description suitable for AI/LLM consumption, compact documentation,
116    * or any context where brevity matters. See {@link Schema#summary()}
117    * for the canonical definition.
118    *
119    * @return The annotation value.
120    * @since 10.0.0
121    */
122   String summary() default "";
123
124   /**
125    * URL query parameter name.
126    *
127    * Required. The name of the parameter. Parameter names are case sensitive.
128    *
129    * <p>
130    * The value should be either a valid query parameter name, or <js>"*"</js> to represent multiple name/value pairs
131    *
132    * <p>
133    * A blank value (the default) has the following behavior:
134    * <ul class='spaced-list'>
135    *    <li>
136    *       If the data type is <c>NameValuePairs</c>, <c>Map</c>, or a bean,
137    *       then it's the equivalent to <js>"*"</js> which will cause the value to be serialized as name/value pairs.
138    *
139    *       <h5 class='figure'>Examples:</h5>
140    *       <p class='bjava'>
141    *    <jc>// When used on a REST method</jc>
142    *    <ja>@RestPost</ja>
143    *    <jk>public void</jk> addPet(<ja>@Query</ja> JsonMap <jv>allQueryParameters</jv>) {...}
144    *       </p>
145    *       <p class='bjava'>
146    *    <jc>// When used on a remote method parameter</jc>
147    *    <ja>@RemoteResource</ja>(path=<js>"/myproxy"</js>)
148    *    <jk>public interface</jk> MyProxy {
149    *
150    *       <jc>// Equivalent to @Query("*")</jc>
151    *       <ja>@RemoteGet</ja>(<js>"/mymethod"</js>)
152    *       String myProxyMethod1(<ja>@Query</ja> Map&lt;String,Object&gt; <jv>allQueryParameters</jv>);
153    *    }
154    *       </p>
155    *       <p class='bjava'>
156    *    <jc>// When used on a request bean method</jc>
157    *    <jk>public interface</jk> MyRequest {
158    *
159    *       <jc>// Equivalent to @Query("*")</jc>
160    *       <ja>@Query</ja>
161    *       Map&lt;String,Object&gt; getFoo();
162    *    }
163    *       </p>
164    *    </li>
165    *    <li>
166    *       If used on a request bean method, uses the bean property name.
167    *
168    *       <h5 class='figure'>Example:</h5>
169    *       <p class='bjava'>
170    *    <jk>public interface</jk> MyRequest {
171    *
172    *       <jc>// Equivalent to @Query("foo")</jc>
173    *       <ja>@Query</ja>
174    *       String getFoo();
175    *    }
176    *       </p>
177    *    </li>
178    * </ul>
179    * <h5 class='section'>Notes:</h5><ul>
180    *    <li class='note'>
181    *       The format is plain-text.
182    * </ul>
183    *
184    * @return The annotation value.
185    */
186   String name() default "";
187
188   /**
189    * <mk>schema</mk> field of the <a class='doclink' href='https://swagger.io/specification/v2#parameterObject'>Swagger Parameter Object</a>.
190    *
191    * <p>
192    * The {@link Schema @Schema} annotation can also be used standalone on the parameter or type.
193    * Values specified on this field override values specified on the type, and values specified on child types override values
194    * specified on parent types.
195    *
196    * <p>
197    * The schema defining the type used for parameter.
198    *
199    * <h5 class='section'>Used for:</h5>
200    * <ul class='spaced-list'>
201    *    <li>
202    *       Server-side schema-based parsing and parsing validation.
203    *    <li>
204    *       Server-side generated Swagger documentation.
205    *    <li>
206    *       Client-side schema-based serializing and serializing validation.
207    * </ul>
208    *
209    * @return The annotation value.
210    */
211   Schema schema() default @Schema;
212
213   /**
214    * A synonym for {@link #name()}.
215    *
216    * <p>
217    * Allows you to use shortened notation if you're only specifying the name.
218    *
219    * <p>
220    * The following are completely equivalent ways of defining the existence of a query entry:
221    * <p class='bjava'>
222    *    <jk>public</jk> Order placeOrder(<ja>@Query</ja>(name=<js>"petId"</js>) <jk>long</jk> <jv>petId</jv>) {...}
223    * </p>
224    * <p class='bjava'>
225    *    <jk>public</jk> Order placeOrder(<ja>@Query</ja>(<js>"petId"</js>) <jk>long</jk> <jv>petId</jv>) {...}
226    * </p>
227    *
228    * @return The annotation value.
229    */
230   String value() default "";
231}