| // *************************************************************************************************************************** |
| // * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * |
| // * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * |
| // * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * |
| // * with the License. You may obtain a copy of the License at * |
| // * * |
| // * http://www.apache.org/licenses/LICENSE-2.0 * |
| // * * |
| // * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * |
| // * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * |
| // * specific language governing permissions and limitations under the License. * |
| // *************************************************************************************************************************** |
| package org.apache.juneau.dto.swagger; |
| |
| import static org.apache.juneau.internal.StringUtils.*; |
| import static org.apache.juneau.internal.ObjectUtils.*; |
| |
| import java.util.*; |
| |
| import org.apache.juneau.annotation.*; |
| import org.apache.juneau.internal.*; |
| import org.apache.juneau.utils.*; |
| |
| /** |
| * Allows adding meta data to a single tag that is used by the {@doc SwaggerOperationObject Operation Object}. |
| * |
| * <p> |
| * It is not mandatory to have a Tag Object per tag used there. |
| * |
| * <h5 class='section'>Example:</h5> |
| * <p class='bcode w800'> |
| * <jc>// Construct using SwaggerBuilder.</jc> |
| * Tag x = <jsm>tag</jsm>() |
| * .name(<js>"pet"</js>) |
| * .description(<js>"Pets operations"</js>) |
| * |
| * <jc>// Serialize using JsonSerializer.</jc> |
| * String json = JsonSerializer.<jsf>DEFAULT</jsf>.toString(x); |
| * |
| * <jc>// Or just use toString() which does the same as above.</jc> |
| * String json = x.toString(); |
| * </p> |
| * <p class='bcode w800'> |
| * <jc>// Output</jc> |
| * { |
| * <js>"name"</js>: <js>"pet"</js>, |
| * <js>"description"</js>: <js>"Pets operations"</js> |
| * } |
| * </p> |
| * |
| * <ul class='seealso'> |
| * <li class='link'>{@doc juneau-dto.Swagger} |
| * </ul> |
| */ |
| @Bean(bpi="name,description,externalDocs,*") |
| public class Tag extends SwaggerElement { |
| |
| private String |
| name, |
| description; |
| private ExternalDocumentation externalDocs; |
| |
| /** |
| * Default constructor. |
| */ |
| public Tag() {} |
| |
| /** |
| * Copy constructor. |
| * |
| * @param copyFrom The object to copy. |
| */ |
| public Tag(Tag copyFrom) { |
| super(copyFrom); |
| |
| this.name = copyFrom.name; |
| this.description = copyFrom.description; |
| this.externalDocs = copyFrom.externalDocs == null ? null : copyFrom.externalDocs.copy(); |
| } |
| |
| /** |
| * Make a deep copy of this object. |
| * |
| * @return A deep copy of this object. |
| */ |
| public Tag copy() { |
| return new Tag(this); |
| } |
| |
| /** |
| * Bean property getter: <property>name</property>. |
| * |
| * <p> |
| * The name of the tag. |
| * |
| * @return The property value, or <jk>null</jk> if it is not set. |
| */ |
| public String getName() { |
| return name; |
| } |
| |
| /** |
| * Bean property setter: <property>name</property>. |
| * |
| * <p> |
| * The name of the tag. |
| * |
| * @param value |
| * The new value for this property. |
| * <br>Property value is required. |
| * @return This object (for method chaining). |
| */ |
| public Tag setName(String value) { |
| name = value; |
| return this; |
| } |
| |
| /** |
| * Same as {@link #setName(String)}. |
| * |
| * @param value |
| * The new value for this property. |
| * <br>Non-String values will be converted to String using <c>toString()</c>. |
| * <br>Can be <jk>null</jk> to unset the property. |
| * @return This object (for method chaining). |
| */ |
| public Tag name(Object value) { |
| return setName(stringify(value)); |
| } |
| |
| /** |
| * Bean property getter: <property>description</property>. |
| * |
| * <p> |
| * A short description for the tag. |
| * |
| * @return The property value, or <jk>null</jk> if it is not set. |
| */ |
| public String getDescription() { |
| return description; |
| } |
| |
| /** |
| * Bean property setter: <property>description</property>. |
| * |
| * <p> |
| * A short description for the tag. |
| * |
| * @param value |
| * The new value for this property. |
| * <br>{@doc GFM} can be used for rich text representation. |
| * <br>Can be <jk>null</jk> to unset the property. |
| * @return This object (for method chaining). |
| */ |
| public Tag setDescription(String value) { |
| description = value; |
| return this; |
| } |
| |
| /** |
| * Same as {@link #setDescription(String)}. |
| * |
| * @param value |
| * The new value for this property. |
| * <br>Non-String values will be converted to String using <c>toString()</c>. |
| * <br>Can be <jk>null</jk> to unset the property. |
| * @return This object (for method chaining). |
| */ |
| public Tag description(Object value) { |
| return setDescription(stringify(value)); |
| } |
| |
| /** |
| * Bean property getter: <property>externalDocs</property>. |
| * |
| * <p> |
| * Additional external documentation for this tag. |
| * |
| * @return The property value, or <jk>null</jk> if it is not set. |
| */ |
| public ExternalDocumentation getExternalDocs() { |
| return externalDocs; |
| } |
| |
| /** |
| * Bean property setter: <property>externalDocs</property>. |
| * |
| * <p> |
| * Additional external documentation for this tag. |
| * |
| * @param value |
| * The new value for this property. |
| * <br>Can be <jk>null</jk> to unset the property. |
| * @return This object (for method chaining). |
| */ |
| public Tag setExternalDocs(ExternalDocumentation value) { |
| externalDocs = value; |
| return this; |
| } |
| |
| /** |
| * Same as {@link #setExternalDocs(ExternalDocumentation)}. |
| * |
| * @param value |
| * The new value for this property. |
| * <br>Valid types: |
| * <ul> |
| * <li>{@link ExternalDocumentation} |
| * <li><c>String</c> - JSON object representation of {@link ExternalDocumentation} |
| * <p class='bcode w800'> |
| * <jc>// Example </jc> |
| * externalDocs(<js>"{description:'description',url:'url'}"</js>); |
| * </p> |
| * </ul> |
| * <br>Can be <jk>null</jk> to unset the property. |
| * @return This object (for method chaining). |
| */ |
| public Tag externalDocs(Object value) { |
| return setExternalDocs(toType(value, ExternalDocumentation.class)); |
| } |
| |
| @Override /* SwaggerElement */ |
| public <T> T get(String property, Class<T> type) { |
| if (property == null) |
| return null; |
| switch (property) { |
| case "name": return toType(getName(), type); |
| case "description": return toType(getDescription(), type); |
| case "externalDocs": return toType(getExternalDocs(), type); |
| default: return super.get(property, type); |
| } |
| } |
| |
| @Override /* SwaggerElement */ |
| public Tag set(String property, Object value) { |
| if (property == null) |
| return this; |
| switch (property) { |
| case "name": return name(value); |
| case "description": return description(value); |
| case "externalDocs": return externalDocs(value); |
| default: |
| super.set(property, value); |
| return this; |
| } |
| } |
| |
| @Override /* SwaggerElement */ |
| public Set<String> keySet() { |
| ASet<String> s = new ASet<String>() |
| .appendIf(name != null, "name") |
| .appendIf(description != null, "description") |
| .appendIf(externalDocs != null, "externalDocs"); |
| return new MultiSet<>(s, super.keySet()); |
| } |
| } |