![JAR search and dependency download from the Maven repository](/logo.png)
org.apache.juneau.dto.swagger.ExternalDocumentation Maven / Gradle / Ivy
// ***************************************************************************************************************************
// * 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.common.internal.StringUtils.*;
import static org.apache.juneau.internal.CollectionUtils.*;
import static org.apache.juneau.internal.ConverterUtils.*;
import java.net.*;
import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.common.internal.*;
import org.apache.juneau.internal.*;
/**
* Allows referencing an external resource for extended documentation.
*
* Example:
*
* // Construct using SwaggerBuilder.
* ExternalDocumentation extDoc = externalDocumentation ("https://swagger.io" , "Find more info here" );
*
* // Serialize using JsonSerializer.
* String json = JsonSerializer.DEFAULT .toString(extDoc );
*
* // Or just use toString() which does the same as above.
* json = extDoc .toString();
*
*
* // Output
* {
* "description" : "Find more info here" ,
* "url" : "https://swagger.io"
* }
*
*
* See Also:
*/
@Bean(properties="description,url,*")
@FluentSetters
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);
}
//-----------------------------------------------------------------------------------------------------------------
// Properties
//-----------------------------------------------------------------------------------------------------------------
/**
* Bean property getter: description .
*
*
* A short description of the target documentation.
*
* @return The property value, or null if it is not set.
*/
public String getDescription() {
return description;
}
/**
* Bean property setter: description .
*
*
* A short description of the target documentation.
*
* @param value
* The new value for this property.
*
GFM syntax can be used for rich text representation.
*
Can be null to unset the property.
* @return This object.
*/
public ExternalDocumentation setDescription(String value) {
description = value;
return this;
}
/**
* Bean property getter: url .
*
*
* The URL for the target documentation.
*
* @return The property value, or null if it is not set.
*/
public URI getUrl() {
return url;
}
/**
* Bean property setter: url .
*
*
* The URL for the target documentation.
*
* @param value
* The new value for this property.
*
Property value is required.
*
URIs defined by {@link UriResolver} can be used for values.
* @return This object.
*/
public ExternalDocumentation setUrl(URI value) {
url = value;
return this;
}
//
//
@Override /* SwaggerElement */
public T get(String property, Class 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 setDescription(stringify(value));
case "url": return setUrl(StringUtils.toURI(value));
default:
super.set(property, value);
return this;
}
}
@Override /* SwaggerElement */
public Set keySet() {
Set s = setBuilder(String.class)
.addIf(description != null, "description")
.addIf(url != null, "url")
.build();
return new MultiSet<>(s, super.keySet());
}
}