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 * REST request path annotation. 030 * 031 * <p> 032 * Identifies a POJO to be used as a path entry on an HTTP request. 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 * <li>Methods and return types of server-side and client-side <ja>@Request</ja>-annotated interfaces. 040 * </ul> 041 * 042 * <h5 class='topic'>Arguments and argument-types of server-side @RestOp-annotated methods</h5> 043 * <p> 044 * Annotation that can be applied to a parameter of a <ja>@RestOp</ja>-annotated method to identify it as a variable 045 * in a URL path pattern. 046 * 047 * <h5 class='section'>Example:</h5> 048 * <p class='bjava'> 049 * <ja>@RestGet</ja>(<js>"/myurl/{foo}/{bar}/{baz}/*"</js>) 050 * <jk>public void</jk> doGet( 051 * <ja>@Path</ja>(<js>"foo"</js>) String <jv>foo</jv>, 052 * <ja>@Path</ja>(<js>"bar"</js>) <jk>int</jk> <jv>bar</jv>, 053 * <ja>@Path</ja>(<js>"baz"</js>) UUID <jv>baz</jv>, 054 * <ja>@Path</ja>(<js>"/*"</js>) String <jv>remainder</jv>, 055 * ) {...} 056 * </p> 057 * 058 * <p> 059 * The special name <js>"/*"</js> is used to retrieve the path remainder after the path match (i.e. the part that matches <js>"/*"</js>). 060 * 061 * <h5 class='section'>See Also:</h5><ul> 062 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> 063 * <li class='extlink'><a class='doclink' href='https://swagger.io/specification/v2#parameterObject'>Swagger Parameter Object</a> 064 * </ul> 065 * 066 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5> 067 * <p> 068 * Annotation applied to Java method arguments of interface proxies to denote that they are path variables on the request. 069 * 070 * <h5 class='section'>See Also:</h5><ul> 071 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Path">@Path</a> 072 * </ul> 073 * 074 * <h5 class='topic'>Methods and return types of server-side and client-side @Request-annotated interfaces</h5> 075 * <p> 076 * <h5 class='section'>See Also:</h5><ul> 077 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Request">@Request</a> 078 * </ul> 079 * 080 * <h5 class='section'>See Also:</h5><ul> 081 082 * </ul> 083 */ 084@Documented 085@Target({PARAMETER,METHOD,TYPE,FIELD}) 086@Retention(RUNTIME) 087@Inherited 088@Repeatable(PathAnnotation.Array.class) 089@ContextApply(PathAnnotation.Applier.class) 090public @interface Path { 091 092 /** 093 * Default value for this parameter. 094 * 095 * @return The annotation value. 096 */ 097 String def() default ""; 098 099 /** 100 * Optional description for the exposed API. 101 * 102 * @return The annotation value. 103 * @since 9.2.0 104 */ 105 String[] description() default {}; 106 107 /** 108 * URL path variable name. 109 * 110 * <p> 111 * The path remainder after the path match can be referenced using the name <js>"/*"</js>. 112 * <br>The non-URL-decoded path remainder after the path match can be referenced using the name <js>"/**"</js>. 113 * 114 * <p> 115 * The value should be either a valid path parameter name, or <js>"*"</js> to represent multiple name/value pairs 116 * 117 * <p> 118 * A blank value (the default) has the following behavior: 119 * <ul class='spaced-list'> 120 * <li> 121 * If the data type is <c>NameValuePairs</c>, <c>Map</c>, or a bean, 122 * then it's the equivalent to <js>"*"</js> which will cause the value to be treated as name/value pairs. 123 * 124 * <h5 class='figure'>Examples:</h5> 125 * <p class='bjava'> 126 * <jc>// When used on a REST method</jc> 127 * <ja>@RestPost</ja> 128 * <jk>public void</jk> addPet(<ja>@Path</ja> JsonMap <jv>allPathParameters</jv>) {...} 129 * </p> 130 * <p class='bjava'> 131 * <jc>// When used on a remote method parameter</jc> 132 * <ja>@RemoteResource</ja>(path=<js>"/myproxy"</js>) 133 * <jk>public interface</jk> MyProxy { 134 * 135 * <jc>// Equivalent to @Path("*")</jc> 136 * <ja>@RemoteGet</ja>(<js>"/mymethod/{foo}/{bar}"</js>) 137 * String myProxyMethod1(<ja>@Path</ja> Map<String,Object> <jv>allPathParameters</jv>); 138 * } 139 * </p> 140 * <p class='bjava'> 141 * <jc>// When used on a request bean method</jc> 142 * <jk>public interface</jk> MyRequest { 143 * 144 * <jc>// Equivalent to @Path("*")</jc> 145 * <ja>@Path</ja> 146 * Map<String,Object> getPathVars(); 147 * } 148 * </p> 149 * </li> 150 * <li> 151 * If used on a request bean method, uses the bean property name. 152 * 153 * <h5 class='figure'>Example:</h5> 154 * <p class='bjava'> 155 * <jk>public interface</jk> MyRequest { 156 * 157 * <jc>// Equivalent to @Path("foo")</jc> 158 * <ja>@Path</ja> 159 * String getFoo(); 160 * } 161 * </ul> 162 * 163 * <p> 164 * The name field MUST correspond to the associated <a class="doclink" href="https://swagger.io/specification/v2#pathsPath">path</a> segment from the path field in the <a class="doclink" href="https://swagger.io/specification/v2#pathsObject">Paths Object</a>. 165 * See <a class="doclink" href="https://swagger.io/specification/v2#pathTemplating">Path Templating</a> for further information. 166 * 167 * <h5 class='section'>Notes:</h5><ul> 168 * <li class='note'> 169 * The format is plain-text. 170 * </ul> 171 * 172 * @return The annotation value. 173 */ 174 String name() default ""; 175 176 /** 177 * Dynamically apply this annotation to the specified classes. 178 * 179 * <h5 class='section'>See Also:</h5><ul> 180 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 181 * </ul> 182 * 183 * @return The annotation value. 184 */ 185 String[] on() default {}; 186 187 /** 188 * Dynamically apply this annotation to the specified classes. 189 * 190 * <p> 191 * Identical to {@link #on()} except allows you to specify class objects instead of a strings. 192 * 193 * <h5 class='section'>See Also:</h5><ul> 194 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 195 * </ul> 196 * 197 * @return The annotation value. 198 */ 199 Class<?>[] onClass() default {}; 200 201 /** 202 * Specifies the {@link HttpPartParser} class used for parsing strings to values. 203 * 204 * <p> 205 * Overrides for this part the part parser defined on the REST resource which by default is {@link OpenApiParser}. 206 * 207 * @return The annotation value. 208 */ 209 Class<? extends HttpPartParser> parser() default HttpPartParser.Void.class; 210 211 /** 212 * <mk>schema</mk> field of the <a class='doclink' href='https://swagger.io/specification/v2#parameterObject'>Swagger Parameter Object</a>. 213 * 214 * <p> 215 * The schema defining the type used for parameter. 216 * 217 * <p> 218 * The {@link Schema @Schema} annotation can also be used standalone on the parameter or type. 219 * Values specified on this field override values specified on the type, and values specified on child types override values 220 * specified on parent types. 221 * 222 * <h5 class='section'>Used for:</h5> 223 * <ul class='spaced-list'> 224 * <li> 225 * Server-side schema-based parsing and parsing validation. 226 * <li> 227 * Server-side generated Swagger documentation. 228 * <li> 229 * Client-side schema-based serializing and serializing validation. 230 * </ul> 231 * 232 * @return The annotation value. 233 */ 234 Schema schema() default @Schema; 235 236 /** 237 * Specifies the {@link HttpPartSerializer} class used for serializing values to strings. 238 * 239 * <p> 240 * Overrides for this part the part serializer defined on the REST client which by default is {@link OpenApiSerializer}. 241 * 242 * @return The annotation value. 243 */ 244 Class<? extends HttpPartSerializer> serializer() default HttpPartSerializer.Void.class; 245 246 /** 247 * A synonym for {@link #name()}. 248 * 249 * <p> 250 * Allows you to use shortened notation if you're only specifying the name. 251 * 252 * <p> 253 * The following are completely equivalent ways of defining a path entry: 254 * <p class='bjava'> 255 * <ja>@RestGet</ja>(<js>"/pet/{petId}"</js>) 256 * <jk>public</jk> Pet getPet(<ja>@Path</ja>(name=<js>"petId"</js>) <jk>long</jk> <jv>petId</jv>) { ... } 257 * </p> 258 * <p class='bjava'> 259 * <ja>@RestGet</ja>(<js>"/pet/{petId}"</js>) 260 * <jk>public</jk> Pet getPet(<ja>@Path</ja>(<js>"petId"</js>) <jk>long</jk> <jv>petId</jv>) { ... } 261 * </p> 262 * 263 * @return The annotation value. 264 */ 265 String value() default ""; 266}