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.oapi.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.oapi.*; 026 027/** 028 * Annotation that can be applied to classes, fields, and methods to tweak how they are handled by {@link OpenApiSerializer} and {@link OpenApiParser}. 029 * 030 * <p> 031 * Can be used in the following locations: 032 * <ul> 033 * <li>Marshalled classes/methods/fields. 034 * <li><ja>@Rest</ja>-annotated classes and <ja>@RestOp</ja>-annotated methods when an {@link #on()} value is specified. 035 * </ul> 036 * 037 * <h5 class='section'>See Also:</h5><ul> 038 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/OpenApiBasics">OpenApi Basics</a> 039 040 * </ul> 041 */ 042@Documented 043@Target({TYPE,FIELD,METHOD}) 044@Retention(RUNTIME) 045@Inherited 046@Repeatable(OpenApiAnnotation.Array.class) 047@ContextApply(OpenApiAnnotation.Apply.class) 048public @interface OpenApi { 049 050 /** 051 * Optional description for the exposed API. 052 * 053 * @return The annotation value. 054 * @since 9.2.0 055 */ 056 String[] description() default {}; 057 058 /** 059 * Dynamically apply this annotation to the specified classes/methods/fields. 060 * 061 * <p> 062 * Used in conjunction with {@link org.apache.juneau.BeanContext.Builder#applyAnnotations(Class...)} to dynamically apply an annotation to an existing class/method/field. 063 * It is ignored when the annotation is applied directly to classes/methods/fields. 064 * 065 * <h5 class='section'>Valid patterns:</h5> 066 * <ul class='spaced-list'> 067 * <li>Classes: 068 * <ul> 069 * <li>Fully qualified: 070 * <ul> 071 * <li><js>"com.foo.MyClass"</js> 072 * </ul> 073 * <li>Fully qualified inner class: 074 * <ul> 075 * <li><js>"com.foo.MyClass$Inner1$Inner2"</js> 076 * </ul> 077 * <li>Simple: 078 * <ul> 079 * <li><js>"MyClass"</js> 080 * </ul> 081 * <li>Simple inner: 082 * <ul> 083 * <li><js>"MyClass$Inner1$Inner2"</js> 084 * <li><js>"Inner1$Inner2"</js> 085 * <li><js>"Inner2"</js> 086 * </ul> 087 * </ul> 088 * <li>Methods: 089 * <ul> 090 * <li>Fully qualified with args: 091 * <ul> 092 * <li><js>"com.foo.MyClass.myMethod(String,int)"</js> 093 * <li><js>"com.foo.MyClass.myMethod(java.lang.String,int)"</js> 094 * <li><js>"com.foo.MyClass.myMethod()"</js> 095 * </ul> 096 * <li>Fully qualified: 097 * <ul> 098 * <li><js>"com.foo.MyClass.myMethod"</js> 099 * </ul> 100 * <li>Simple with args: 101 * <ul> 102 * <li><js>"MyClass.myMethod(String,int)"</js> 103 * <li><js>"MyClass.myMethod(java.lang.String,int)"</js> 104 * <li><js>"MyClass.myMethod()"</js> 105 * </ul> 106 * <li>Simple: 107 * <ul> 108 * <li><js>"MyClass.myMethod"</js> 109 * </ul> 110 * <li>Simple inner class: 111 * <ul> 112 * <li><js>"MyClass$Inner1$Inner2.myMethod"</js> 113 * <li><js>"Inner1$Inner2.myMethod"</js> 114 * <li><js>"Inner2.myMethod"</js> 115 * </ul> 116 * </ul> 117 * <li>Fields: 118 * <ul> 119 * <li>Fully qualified: 120 * <ul> 121 * <li><js>"com.foo.MyClass.myField"</js> 122 * </ul> 123 * <li>Simple: 124 * <ul> 125 * <li><js>"MyClass.myField"</js> 126 * </ul> 127 * <li>Simple inner class: 128 * <ul> 129 * <li><js>"MyClass$Inner1$Inner2.myField"</js> 130 * <li><js>"Inner1$Inner2.myField"</js> 131 * <li><js>"Inner2.myField"</js> 132 * </ul> 133 * </ul> 134 * <li>A comma-delimited list of anything on this list. 135 * </ul> 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 String[] on() default {}; 144 145 /** 146 * Dynamically apply this annotation to the specified classes. 147 * 148 * <p> 149 * Identical to {@link #on()} except allows you to specify class objects instead of a strings. 150 * 151 * <h5 class='section'>See Also:</h5><ul> 152 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 153 * </ul> 154 * 155 * @return The annotation value. 156 */ 157 Class<?>[] onClass() default {}; 158}