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.http.annotation;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.lang.annotation.*;
019
020import org.apache.juneau.annotation.*;
021import org.apache.juneau.httppart.*;
022import org.apache.juneau.oapi.*;
023
024/**
025 * REST response annotation.
026 *
027 * <p>
028 * Identifies an interface to use to interact with HTTP parts of an HTTP response through a bean.
029 *
030 * <p>
031 * Can be used in the following locations:
032 *  <ul>
033 *    <li>Exception classes thrown from server-side <ja>@RestOp</ja>-annotated methods.
034 *    <li>Return type classes of server-side <ja>@RestOp</ja>-annotated methods.
035 *    <li>Arguments and argument-types of server-side <ja>@RestOp</ja>-annotated methods.
036 *    <li>Return type classes of server-side <ja>@RemoteOp</ja>-annotated methods.
037 *    <li>Client-side <ja>@RemoteOp</ja>-annotated methods.
038 *    <li>Return type interfaces of client-side <ja>@RemoteOp</ja>-annotated methods.
039 * </ul>
040 *
041 * <h5 class='section'>See Also:</h5><ul>
042 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrc.Response">@Response</a>
043 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.Swagger">Swagger</a>
044 *    <li class='extlink'><a class="doclink" href="https://swagger.io/specification/v2#responseObject">Swagger Response Object</a>
045 * </ul>
046 */
047@Documented
048@Target({PARAMETER,TYPE,METHOD})
049@Retention(RUNTIME)
050@Inherited
051@Repeatable(ResponseAnnotation.Array.class)
052@ContextApply(ResponseAnnotation.Applier.class)
053public @interface Response {
054
055   /**
056    * Serialized examples of the body of a response.
057    *
058    * <p>
059    * This is a <a class="doclink" href="../../../../../index.html#jd.Swagger">Swagger</a> object whose keys are media types and values are string representations of that value.
060    *
061    * <p class='bjava'>
062    *    <jc>// A JSON representation of a PetCreate object.</jc>
063    *    <ja>@Response</ja>(
064    *       examples={
065    *          <js>"'application/json':'{name:\\'Doggie\\',species:\\'Dog\\'}',"</js>,
066    *          <js>"'text/uon':'(name:Doggie,species=Dog)'"</js>
067    *       }
068    *    )
069    * </p>
070    *
071    * <h5 class='section'>Used for:</h5>
072    * <ul class='spaced-list'>
073    *    <li>
074    *       Server-side generated Swagger documentation.
075    * </ul>
076    *
077    * <h5 class='section'>Notes:</h5><ul>
078    *    <li class='note'>
079    *       The format is a <a class="doclink" href="../../../../../index.html#jd.Swagger">Swagger</a> object with string keys (media type) and string values (example for that media type) .
080    *    <li class='note'>
081    *       The leading/trailing <c>{ }</c> characters are optional.
082    *    <li class='note'>
083    *       Multiple lines are concatenated with newlines so that you can format the value to be readable:
084    *    <li class='note'>
085    *       Supports <a class="doclink" href="../../../../../index.html#jrs.SvlVariables">SVL Variables</a> (e.g. <js>"$L{my.localized.variable}"</js>) for the swagger generator.
086    *    <li class='note'>
087    *       Resolution of variables is delayed until request time and occurs before parsing.
088    *       <br>This allows you to, for example, pull in a JSON construct from a properties file based on the locale of the HTTP request.
089    * </ul>
090    *
091    * @return The annotation value.
092    */
093   String[] examples() default {};
094
095   /**
096    * <mk>headers</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#responseObject">Swagger Response Object</a>.
097    *
098    * <h5 class='section'>Used for:</h5>
099    * <ul class='spaced-list'>
100    *    <li>
101    *       Server-side generated Swagger documentation.
102    * </ul>
103    *
104    * @return The annotation value.
105    */
106   Header[] headers() default {};
107
108   /**
109    * Dynamically apply this annotation to the specified classes.
110    *
111    * <h5 class='section'>See Also:</h5><ul>
112    *    <li class='link'><a class="doclink" href="../../../../../index.html#jm.DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
113    * </ul>
114    *
115    * @return The annotation value.
116    */
117   String[] on() default {};
118
119   /**
120    * Dynamically apply this annotation to the specified classes.
121    *
122    * <p>
123    * Identical to {@link #on()} except allows you to specify class objects instead of a strings.
124    *
125    * <h5 class='section'>See Also:</h5><ul>
126    *    <li class='link'><a class="doclink" href="../../../../../index.html#jm.DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
127    * </ul>
128    *
129    * @return The annotation value.
130    */
131   Class<?>[] onClass() default {};
132
133   /**
134    * Specifies the {@link HttpPartParser} class used for parsing strings to values.
135    *
136    * <p>
137    * Overrides for this part the part parser defined on the REST resource which by default is {@link OpenApiParser}.
138    *
139    * @return The annotation value.
140    */
141   Class<? extends HttpPartParser> parser() default HttpPartParser.Void.class;
142
143   /**
144    * <mk>schema</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#responseObject">Swagger Response Object</a>.
145    *
146    * <h5 class='section'>Used for:</h5>
147    * <ul class='spaced-list'>
148    *    <li>
149    *       Server-side schema-based serializing and serializing validation.
150    *    <li>
151    *       Server-side generated Swagger documentation.
152    * </ul>
153    *
154    * @return The annotation value.
155    */
156   Schema schema() default @Schema;
157
158   /**
159    * Specifies the {@link HttpPartSerializer} class used for serializing values to strings.
160    *
161    * <p>
162    * Overrides for this part the part serializer defined on the REST resource which by default is {@link OpenApiSerializer}.
163    *
164    * @return The annotation value.
165    */
166   Class<? extends HttpPartSerializer> serializer() default HttpPartSerializer.Void.class;
167}