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