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.dto.openapi3; 014 015import static org.apache.juneau.common.internal.StringUtils.*; 016import static org.apache.juneau.internal.CollectionUtils.*; 017import static org.apache.juneau.internal.ConverterUtils.*; 018 019import org.apache.juneau.annotation.Bean; 020import org.apache.juneau.dto.swagger.ExternalDocumentation; 021import org.apache.juneau.internal.*; 022 023import java.util.Set; 024 025/** 026 * Allows adding meta data to a single tag that is used by the operation object. 027 * 028 * <p> 029 * It is not mandatory to have a Tag Object per tag used there. 030 * 031 * <h5 class='section'>Example:</h5> 032 * <p class='bcode'> 033 * <jc>// Construct using SwaggerBuilder.</jc> 034 * Tag x = <jsm>tag</jsm>() 035 * .name(<js>"pet"</js>) 036 * .description(<js>"Pets operations"</js>) 037 * 038 * <jc>// Serialize using JsonSerializer.</jc> 039 * String json = JsonSerializer.<jsf>DEFAULT</jsf>.toString(x); 040 * 041 * <jc>// Or just use toString() which does the same as above.</jc> 042 * String json = x.toString(); 043 * </p> 044 * <p class='bcode'> 045 * <jc>// Output</jc> 046 * { 047 * <js>"name"</js>: <js>"pet"</js>, 048 * <js>"description"</js>: <js>"Pets operations"</js> 049 * } 050 * </p> 051 */ 052@Bean(properties="name,description,externalDocs,*") 053@FluentSetters 054public class Tag extends OpenApiElement { 055 056 private String 057 name, 058 description; 059 private ExternalDocumentation externalDocs; 060 061 /** 062 * Default constructor. 063 */ 064 public Tag() {} 065 066 /** 067 * Copy constructor. 068 * 069 * @param copyFrom The object to copy. 070 */ 071 public Tag(Tag copyFrom) { 072 super(copyFrom); 073 074 this.name = copyFrom.name; 075 this.description = copyFrom.description; 076 this.externalDocs = copyFrom.externalDocs == null ? null : copyFrom.externalDocs.copy(); 077 } 078 079 /** 080 * Make a deep copy of this object. 081 * 082 * @return A deep copy of this object. 083 */ 084 public Tag copy() { 085 return new Tag(this); 086 } 087 088 /** 089 * Bean property getter: <property>name</property>. 090 * 091 * <p> 092 * The name of the tag. 093 * 094 * @return The property value, or <jk>null</jk> if it is not set. 095 */ 096 public String getName() { 097 return name; 098 } 099 100 /** 101 * Bean property setter: <property>name</property>. 102 * 103 * <p> 104 * The name of the tag. 105 * 106 * @param value 107 * The new value for this property. 108 * <br>Property value is required. 109 * @return This object 110 */ 111 public Tag setName(String value) { 112 name = value; 113 return this; 114 } 115 116 /** 117 * Bean property getter: <property>description</property>. 118 * 119 * <p> 120 * A short description for the tag. 121 * 122 * @return The property value, or <jk>null</jk> if it is not set. 123 */ 124 public String getDescription() { 125 return description; 126 } 127 128 /** 129 * Bean property setter: <property>description</property>. 130 * 131 * <p> 132 * A short description for the tag. 133 * 134 * @param value 135 * The new value for this property. 136 * <br>Can be <jk>null</jk> to unset the property. 137 * @return This object 138 */ 139 public Tag setDescription(String value) { 140 description = value; 141 return this; 142 } 143 144 /** 145 * Bean property getter: <property>externalDocs</property>. 146 * 147 * <p> 148 * Additional external documentation for this tag. 149 * 150 * @return The property value, or <jk>null</jk> if it is not set. 151 */ 152 public ExternalDocumentation getExternalDocs() { 153 return externalDocs; 154 } 155 156 /** 157 * Bean property setter: <property>externalDocs</property>. 158 * 159 * <p> 160 * Additional external documentation for this tag. 161 * 162 * @param value 163 * The new value for this property. 164 * <br>Can be <jk>null</jk> to unset the property. 165 * @return This object 166 */ 167 public Tag setExternalDocs(ExternalDocumentation value) { 168 externalDocs = value; 169 return this; 170 } 171 172 // <FluentSetters> 173 174 // </FluentSetters> 175 176 @Override /* OpenApiElement */ 177 public <T> T get(String property, Class<T> type) { 178 if (property == null) 179 return null; 180 switch (property) { 181 case "name": return toType(getName(), type); 182 case "description": return toType(getDescription(), type); 183 case "externalDocs": return toType(getExternalDocs(), type); 184 default: return super.get(property, type); 185 } 186 } 187 188 @Override /* OpenApiElement */ 189 public Tag set(String property, Object value) { 190 if (property == null) 191 return this; 192 switch (property) { 193 case "name": return setName(stringify(value)); 194 case "description": return setDescription(stringify(value)); 195 case "externalDocs": return setExternalDocs(toType(value, ExternalDocumentation.class)); 196 default: 197 super.set(property, value); 198 return this; 199 } 200 } 201 202 @Override /* OpenApiElement */ 203 public Set<String> keySet() { 204 Set<String> s = setBuilder(String.class) 205 .addIf(name != null, "name") 206 .addIf(description != null, "description") 207 .addIf(externalDocs != null, "externalDocs") 208 .build(); 209 return new MultiSet<>(s, super.keySet()); 210 } 211}