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.swagger; 014 015import static org.apache.juneau.internal.BeanPropertyUtils.*; 016import java.net.*; 017import java.net.URI; 018 019import org.apache.juneau.*; 020import org.apache.juneau.annotation.*; 021 022/** 023 * License information for the exposed API. 024 * 025 * <h5 class='section'>Example:</h5> 026 * <p class='bcode'> 027 * <jc>// Construct using SwaggerBuilder.</jc> 028 * License x = <jsm>license</jsm>(<js>"Apache 2.0"</js>, <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js>); 029 * 030 * <jc>// Serialize using JsonSerializer.</jc> 031 * String json = JsonSerializer.<jsf>DEFAULT</jsf>.toString(x); 032 * 033 * <jc>// Or just use toString() which does the same as above.</jc> 034 * String json = x.toString(); 035 * </p> 036 * <p class='bcode'> 037 * <jc>// Output</jc> 038 * { 039 * <js>"name"</js>: <js>"Apache 2.0"</js>, 040 * <js>"url"</js>: <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js> 041 * } 042 * </p> 043 * 044 * <h5 class='section'>See Also:</h5> 045 * <ul class='doctree'> 046 * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a> 047 * </ul> 048 */ 049@Bean(properties="name,url,*") 050public class License extends SwaggerElement { 051 052 private String name; 053 private URI url; 054 055 /** 056 * Bean property getter: <property>name</property>. 057 * 058 * <p> 059 * The license name used for the API. 060 * 061 * @return The property value, or <jk>null</jk> if it is not set. 062 */ 063 public String getName() { 064 return name; 065 } 066 067 /** 068 * Bean property setter: <property>name</property>. 069 * 070 * <p> 071 * The license name used for the API. 072 * 073 * @param value 074 * The new value for this property. 075 * <br>Property value is required. 076 * @return This object (for method chaining). 077 */ 078 public License setName(String value) { 079 name = value; 080 return this; 081 } 082 083 /** 084 * Same as {@link #setName(String)}. 085 * 086 * @param value 087 * The new value for this property. 088 * <br>Non-String values will be converted to String using <code>toString()</code>. 089 * <br>Can be <jk>null</jk> to unset the property. 090 * @return This object (for method chaining). 091 */ 092 public License name(Object value) { 093 return setName(toStringVal(value)); 094 } 095 096 /** 097 * Bean property getter: <property>url</property>. 098 * 099 * <p> 100 * A URL to the license used for the API. 101 * 102 * @return The property value, or <jk>null</jk> if it is not set. 103 */ 104 public URI getUrl() { 105 return url; 106 } 107 108 /** 109 * Bean property setter: <property>url</property>. 110 * 111 * <p> 112 * A URL to the license used for the API. 113 * 114 * @param value 115 * The new value for this property. 116 * <br>URIs defined by {@link UriResolver} can be used for values. 117 * <br>Can be <jk>null</jk> to unset the property. 118 * @return This object (for method chaining). 119 */ 120 public License setUrl(URI value) { 121 url = value; 122 return this; 123 } 124 125 /** 126 * Same as {@link #setUrl(URI)}. 127 * 128 * @param value 129 * The new value for this property. 130 * <br>Non-URI values will be converted to URI using <code><jk>new</jk> URI(value.toString())</code>. 131 * <br>Valid types: 132 * <ul> 133 * <li>{@link URI} 134 * <li>{@link URL} 135 * <li>{@link String} 136 * <br>Converted to a URI using <code>URI.<jsm>create</jsm>(value.toString())</code> 137 * </ul> 138 * <br>Can be <jk>null</jk> to unset the property. 139 * @return This object (for method chaining). 140 */ 141 public License url(Object value) { 142 return setUrl(toURI(value)); 143 } 144 145 @Override /* SwaggerElement */ 146 public <T> T get(String property, Class<T> type) { 147 if (property == null) 148 return null; 149 switch (property) { 150 case "name": return toType(getName(), type); 151 case "url": return toType(getUrl(), type); 152 default: return super.get(property, type); 153 } 154 } 155 156 @Override /* SwaggerElement */ 157 public License set(String property, Object value) { 158 if (property == null) 159 return this; 160 switch (property) { 161 case "name": return name(value); 162 case "url": return url(value); 163 default: 164 super.set(property, value); 165 return this; 166 } 167 } 168}