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 body annotation.
028 *
029 * <p>
030 * Identifies a POJO to be used as the body of 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>@RemoteOp</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 *
042 * <p>
043 * On server-side REST, this annotation can be applied to method parameters or parameter classes to identify them as the body of an HTTP request.
044 *
045 * <h5 class='section'>Examples:</h5>
046 * <p class='bjava'>
047 *    <jc>// Used on parameter</jc>
048 *    <ja>@RestPost</ja>(<js>"/pets"</js>)
049 *    <jk>public void</jk> addPet(<ja>@Content</ja> Pet <jv>pet</jv>) {...}
050 * </p>
051 * <p class='bjava'>
052 *    <jc>// Used on class</jc>
053 *    <ja>@RestPost</ja>(<js>"/pets"</js>)
054 *    <jk>public void</jk> addPet(Pet <jv>pet</jv>) {...}
055 *
056 *    <ja>@Content</ja>
057 *    <jk>public class</jk> Pet {...}
058 * </p>
059 *
060 * <p>
061 * This is functionally equivalent to the following code...
062 * <p class='bjava'>
063 *    <ja>@RestPost</ja>(<js>"/pets"</js>)
064 *    <jk>public void</jk> addPet(RestRequest <jv>req</jv>) {
065 *       Pet <jv>pet</jv> = <jv>req</jv>.getContent().as(Pet.<jk>class</jk>);
066 *       ...
067 *    }
068 * </p>
069 *
070 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5>
071 *
072 * <h5 class='section'>See Also:</h5><ul>
073 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Content">@Content</a>
074 * </ul>
075 *
076 * <h5 class='topic'>Methods and return types of server-side and client-side @Request-annotated interfaces</h5>
077 *
078 * <h5 class='section'>See Also:</h5><ul>
079 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Request">@Request</a>
080 * </ul>
081 *
082 * <h5 class='section'>Notes:</h5><ul>
083 *    <li class='note'>
084 *       Annotation parameter values will be aggregated when used on POJO parent and child classes.
085 *       <br>Values on child classes override values on parent classes.
086 *    <li class='note'>
087 *       Annotation parameter values will be aggregated when used on both POJOs and REST methods.
088 *       <br>Values on methods override values on POJO classes.
089 *    <li class='warn'>
090 *       If using this annotation on a Spring bean, note that you are likely to encounter issues when using on parameterized
091 *       types such as <code>List&lt;MyBean&gt;</code>.  This is due to the fact that Spring uses CGLIB to recompile classes
092 *       at runtime, and CGLIB was written before generics were introduced into Java and is a virtually-unsupported library.
093 *       Therefore, parameterized types will often be stripped from class definitions and replaced with unparameterized types
094 *    (e.g. <code>List</code>).  Under these circumstances, you are likely to get <code>ClassCastExceptions</code>
095 *    when trying to access generalized <code>JsonMaps</code> as beans.  The best solution to this issue is to either
096 *    specify the parameter as a bean array (e.g. <code>MyBean[]</code>) or declare the method as final so that CGLIB
097 *    will not try to recompile it.
098 * </ul>
099 *
100 */
101@Documented
102@Target({ PARAMETER, METHOD, TYPE })
103@Retention(RUNTIME)
104@Inherited
105public @interface Content {
106
107   /**
108    * Default value for this parameter.
109    *
110    * <p>
111    * This value is only used when annotation is applied to a method (not a parameter).
112    * When applied to a remote interface method, it specifies the default content to use
113    * if not overridden by the client.
114    *
115    * @return The annotation value.
116    * @since 9.2.0
117    */
118   String def() default "";
119
120   /**
121    * Optional description for the exposed API.
122    *
123    * @return The annotation value.
124    * @since 9.2.0
125    */
126   String[] description() default {};
127
128   /**
129    * Short, concise summary of the exposed API.
130    *
131    * <p>
132    * Intended as a brief, single-line description suitable for AI/LLM consumption, compact documentation,
133    * or any context where brevity matters. See {@link Schema#summary()}
134    * for the canonical definition.
135    *
136    * @return The annotation value.
137    * @since 10.0.0
138    */
139   String summary() default "";
140
141   /**
142    * <mk>schema</mk> field of the <a class='doclink' href='https://swagger.io/specification/v2#parameterObject'>Swagger Parameter Object</a>.
143    *
144    * <p>
145    * The schema defining the type used for parameter.
146    *
147    * <p>
148    * This is a required attribute per the swagger definition.
149    * However, if not explicitly specified, the value will be auto-generated using {@link org.apache.juneau.marshall.json.JsonSchemaSerializer}.
150    *
151    * <p>
152    * The {@link Schema @Schema} annotation can also be used standalone on the parameter or type.
153    * Values specified on this field override values specified on the type, and values specified on child types override values
154    * specified on parent types.
155    *
156    * <h5 class='section'>Used for:</h5>
157    * <ul class='spaced-list'>
158    *    <li>
159    *       Server-side schema-based parsing and parsing validation.
160    *    <li>
161    *       Server-side generated Swagger documentation.
162    *    <li>
163    *       Client-side schema-based serializing and serializing validation.
164    * </ul>
165    *
166    * @return The annotation value.
167    */
168   Schema schema() default @Schema;
169}