blob: 15344b7c3322ef20335f897d5629ccadfbd8ee3a [file] [log] [blame]
// ***************************************************************************************************************************
// * 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.ConverterUtils.*;
import java.net.*;
import java.net.URI;
import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.internal.*;
/**
* Allows referencing an external resource for extended documentation.
*
* <h5 class='section'>Example:</h5>
* <p class='bcode w800'>
* <jc>// Construct using SwaggerBuilder.</jc>
* ExternalDocumentation <jv>extDoc</jv> = <jsm>externalDocumentation</jsm>(<js>"https://swagger.io"</js>, <js>"Find more info here"</js>);
*
* <jc>// Serialize using JsonSerializer.</jc>
* String <jv>json</jv> = JsonSerializer.<jsf>DEFAULT</jsf>.toString(<jv>extDoc</jv>);
*
* <jc>// Or just use toString() which does the same as above.</jc>
* <jv>json</jv> = <jv>extDoc</jv>.toString();
* </p>
* <p class='bcode w800'>
* <jc>// Output</jc>
* {
* <js>"description"</js>: <js>"Find more info here"</js>,
* <js>"url"</js>: <js>"https://swagger.io"</js>
* }
* </p>
*
* <ul class='seealso'>
* <li class='link'>{@doc DtoSwagger}
* </ul>
*/
@Bean(properties="description,url,*")
public class ExternalDocumentation extends SwaggerElement {
private String description;
private URI url;
/**
* Default constructor.
*/
public ExternalDocumentation() {}
/**
* Copy constructor.
*
* @param copyFrom The object to copy.
*/
public ExternalDocumentation(ExternalDocumentation copyFrom) {
super(copyFrom);
this.description = copyFrom.description;
this.url = copyFrom.url;
}
/**
* Make a deep copy of this object.
*
* @return A deep copy of this object.
*/
public ExternalDocumentation copy() {
return new ExternalDocumentation(this);
}
//-----------------------------------------------------------------------------------------------------------------
// description
//-----------------------------------------------------------------------------------------------------------------
/**
* Bean property getter: <property>description</property>.
*
* <p>
* A short description of the target documentation.
*
* @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 of the target documentation.
*
* @param value
* The new value for this property.
* <br>{@doc ExtGFM} can be used for rich text representation.
* <br>Can be <jk>null</jk> to unset the property.
*/
public void setDescription(String value) {
description = value;
}
/**
* Bean property fluent getter: <property>description</property>.
*
* <p>
* A short description of the target documentation.
*
* @return The property value as an {@link Optional}. Never <jk>null</jk>.
*/
public Optional<String> description() {
return Optional.ofNullable(getDescription());
}
/**
* Bean property fluent setter: <property>description</property>.
*
* <p>
* A short description of the target documentation.
*
* @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 ExternalDocumentation description(String value) {
setDescription(value);
return this;
}
//-----------------------------------------------------------------------------------------------------------------
// url
//-----------------------------------------------------------------------------------------------------------------
/**
* Bean property getter: <property>url</property>.
*
* <p>
* The URL for the target documentation.
*
* @return The property value, or <jk>null</jk> if it is not set.
*/
public URI getUrl() {
return url;
}
/**
* Bean property setter: <property>url</property>.
*
* <p>
* The URL for the target documentation.
*
* @param value
* The new value for this property.
* <br>Property value is required.
* <br>URIs defined by {@link UriResolver} can be used for values.
*/
public void setUrl(URI value) {
url = value;
}
/**
* Bean property fluent getter: <property>url</property>.
*
* <p>
* The URL for the target documentation.
*
* @return The property value as an {@link Optional}. Never <jk>null</jk>.
*/
public Optional<URI> url() {
return Optional.ofNullable(getUrl());
}
/**
* Bean property fluent setter: <property>url</property>.
*
* <p>
* The URL for the target documentation.
*
* @param value
* The new value for this property.
* <br>URIs defined by {@link UriResolver} can be used for values.
* <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
public ExternalDocumentation url(URI value) {
setUrl(value);
return this;
}
/**
* Bean property fluent setter: <property>url</property>.
*
* <p>
* The URL for the target documentation.
*
* @param value
* The new value for this property.
* <br>URIs defined by {@link UriResolver} can be used for values.
* <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
public ExternalDocumentation url(URL value) {
setUrl(StringUtils.toURI(value));
return this;
}
/**
* Bean property fluent setter: <property>url</property>.
*
* <p>
* The URL for the target documentation.
*
* @param value
* The new value for this property.
* <br>URIs defined by {@link UriResolver} can be used for values.
* <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
public ExternalDocumentation url(String value) {
setUrl(StringUtils.toURI(value));
return this;
}
@Override /* SwaggerElement */
public <T> T get(String property, Class<T> type) {
if (property == null)
return null;
switch (property) {
case "description": return toType(getDescription(), type);
case "url": return toType(getUrl(), type);
default: return super.get(property, type);
}
}
@Override /* SwaggerElement */
public ExternalDocumentation set(String property, Object value) {
if (property == null)
return this;
switch (property) {
case "description": return description(stringify(value));
case "url": return url(StringUtils.toURI(value));
default:
super.set(property, value);
return this;
}
}
@Override /* SwaggerElement */
public Set<String> keySet() {
ASet<String> s = ASet.<String>of()
.appendIf(description != null, "description")
.appendIf(url != null, "url");
return new MultiSet<>(s, super.keySet());
}
}