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 java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.lang.annotation.*;
019
020import org.apache.juneau.httppart.*;
021import org.apache.juneau.oapi.*;
022
023/**
024 * REST request attribute annotation.
025 *
026 * <p>
027 * Identifies a POJO retrieved from the request attributes map.
028 *
029 * Annotation that can be applied to a parameter of a <ja>@RestMethod</ja>-annotated method to identify it as a value
030 * retrieved from the request attributes.
031 *
032 * <h5 class='section'>Example:</h5>
033 * <p class='bcode w800'>
034 *    <ja>@RestMethod</ja>(name=<jsf>GET</jsf>)
035 *    <jk>public void</jk> doGet(<ja>@Attr</ja>(<js>"ETag"</js>) UUID etag) {...}
036 * </p>
037 *
038 * <p>
039 * This is functionally equivalent to the following code...
040 * <p class='bcode w800'>
041 *    <ja>@RestMethod</ja>(name=<jsf>GET</jsf>)
042 *    <jk>public void</jk> doPostPerson(RestRequest req, RestResponse res) {
043 *       UUID etag = req.getAttributes().get(UUID.<jk>class</jk>, <js>"ETag"</js>);
044 *       ...
045 *    }
046 * </p>
047 */
048@Documented
049@Target({PARAMETER,FIELD,METHOD,TYPE})
050@Retention(RUNTIME)
051@Inherited
052public @interface Attr {
053
054   /**
055    * Specifies the {@link HttpPartParser} class used for parsing strings to values.
056    *
057    * <p>
058    * Overrides for this part the part parser defined on the REST resource which by default is {@link OpenApiParser}.
059    */
060   Class<? extends HttpPartParser> parser() default HttpPartParser.Null.class;
061
062   //=================================================================================================================
063   // Attributes common to all Swagger Parameter objects
064   //=================================================================================================================
065
066   /**
067    * Request attribute name.
068    *
069    * <p>
070    * The value should be either a valid attribute name, or <js>"*"</js> to represent multiple name/value pairs
071    *
072    * <p>
073    * A blank value (the default) has the following behavior:
074    * <ul class='spaced-list'>
075    *    <li>
076    *       If the data type is <c>NameValuePairs</c>, <c>Map</c>, or a bean,
077    *       then it's the equivalent to <js>"*"</js> which will cause the value to be serialized as name/value pairs.
078    *
079    *       <h5 class='figure'>Examples:</h5>
080    *       <p class='bcode w800'>
081    *    <ja>@RestMethod</ja>(path=<js>"/addPet"</js>)
082    *    <jk>public void</jk> addPet(<ja>@Attr</ja> ObjectMap allAttributes) {...}
083    *       </p>
084    *    </li>
085    * </ul>
086    */
087   String name() default "";
088
089   /**
090    * A synonym for {@link #name()}.
091    *
092    * <p>
093    * Allows you to use shortened notation if you're only specifying the name.
094    *
095    * <p>
096    * The following are completely equivalent ways of defining a header entry:
097    * <p class='bcode w800'>
098    *    <jk>public</jk> Order placeOrder(<ja>@Attr</ja>(name=<js>"api_key"</js>) String apiKey) {...}
099    * </p>
100    * <p class='bcode w800'>
101    *    <jk>public</jk> Order placeOrder(<ja>@Attr</ja>(<js>"api_key"</js>) String apiKey) {...}
102    * </p>
103    */
104   String value() default "";
105}