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