You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2018/01/18 19:00:57 UTC
[01/10] juneau git commit: JUNEAU-78
Repository: juneau
Updated Branches:
refs/heads/master 6f4b27ea2 -> 8df34f56d
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Xml.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Xml.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Xml.java
index c856b01..650b714 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Xml.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Xml.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import org.apache.juneau.annotation.*;
/**
@@ -21,29 +22,42 @@ import org.apache.juneau.annotation.*;
* When using arrays, XML element names are not inferred (for singular/plural forms) and the name property should be
* used to add that information.
*
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * Xml x = <jsm>xml</jsm>()
+ * .name(<js>"foo"</js>)
+ * .namespace(<js>"http://foo"</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'>
+ * <jc>// Output</jc>
+ * {
+ * <js>"name"</js>: <js>"foo"</js>,
+ * <js>"namespace"</js>: <js>"http://foo"</js>
+ * }
+ * </p>
+ *
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="name,namespace,prefix,attribute,wrapped")
+@Bean(properties="name,namespace,prefix,attribute,wrapped,*")
public class Xml extends SwaggerElement {
- private String name;
- private String namespace;
- private String prefix;
- private Boolean attribute;
- private Boolean wrapped;
+ private String
+ name,
+ namespace,
+ prefix;
+ private Boolean
+ attribute,
+ wrapped;
/**
* Bean property getter: <property>name</property>.
@@ -54,11 +68,11 @@ public class Xml extends SwaggerElement {
* <p>
* When defined within the Items Object (<code>items</code>), it will affect the name of the individual XML elements
* within the list.
- * When defined alongside <code>type</code> being array (outside the <code>items</code>), it will affect the
+ * <br>When defined alongside <code>type</code> being array (outside the <code>items</code>), it will affect the
* wrapping element and only if wrapped is <jk>true</jk>.
- * If wrapped is <jk>false</jk>, it will be ignored.
+ * <br>If wrapped is <jk>false</jk>, it will be ignored.
*
- * @return The value of the <property>name</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getName() {
return name;
@@ -73,26 +87,31 @@ public class Xml extends SwaggerElement {
* <p>
* When defined within the Items Object (<code>items</code>), it will affect the name of the individual XML elements
* within the list.
- * When defined alongside <code>type</code> being array (outside the <code>items</code>), it will affect the
+ * <br>When defined alongside <code>type</code> being array (outside the <code>items</code>), it will affect the
* wrapping element and only if wrapped is <jk>true</jk>.
- * If wrapped is <jk>false</jk>, it will be ignored.
+ * <br>If wrapped is <jk>false</jk>, it will be ignored.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @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 Xml setName(String name) {
- this.name = name;
+ public Xml setName(String value) {
+ name = value;
return this;
}
/**
- * Synonym for {@link #setName(String)}.
+ * Same as {@link #setName(String)}.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Xml name(String name) {
- return setName(name);
+ public Xml name(Object value) {
+ return setName(toStringVal(value));
}
/**
@@ -101,7 +120,7 @@ public class Xml extends SwaggerElement {
* <p>
* The URL of the namespace definition. Value SHOULD be in the form of a URL.
*
- * @return The value of the <property>namespace</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getNamespace() {
return namespace;
@@ -113,22 +132,27 @@ public class Xml extends SwaggerElement {
* <p>
* The URL of the namespace definition. Value SHOULD be in the form of a URL.
*
- * @param namespace The new value for the <property>namespace</property> property on this bean.
+ * @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 Xml setNamespace(String namespace) {
- this.namespace = namespace;
+ public Xml setNamespace(String value) {
+ namespace = value;
return this;
}
/**
- * Synonym for {@link #setNamespace(String)}.
+ * Same as {@link #setNamespace(String)}.
*
- * @param namespace The new value for the <property>namespace</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Xml namespace(String namespace) {
- return setNamespace(namespace);
+ public Xml namespace(Object value) {
+ return setNamespace(toStringVal(value));
}
/**
@@ -137,7 +161,7 @@ public class Xml extends SwaggerElement {
* <p>
* The prefix to be used for the name.
*
- * @return The value of the <property>prefix</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getPrefix() {
return prefix;
@@ -149,22 +173,27 @@ public class Xml extends SwaggerElement {
* <p>
* The prefix to be used for the name.
*
- * @param prefix The new value for the <property>prefix</property> property on this bean.
+ * @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 Xml setPrefix(String prefix) {
- this.prefix = prefix;
+ public Xml setPrefix(String value) {
+ prefix = value;
return this;
}
/**
- * Synonym for {@link #setPrefix(String)}.
+ * Same as {@link #setPrefix(String)}.
*
- * @param prefix The new value for the <property>prefix</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Xml prefix(String prefix) {
- return setPrefix(prefix);
+ public Xml prefix(Object value) {
+ return setPrefix(toStringVal(value));
}
/**
@@ -173,10 +202,7 @@ public class Xml extends SwaggerElement {
* <p>
* Declares whether the property definition translates to an attribute instead of an element.
*
- * <p>
- * Default value is <jk>false</jk>.
- *
- * @return The value of the <property>attribute</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getAttribute() {
return attribute;
@@ -188,25 +214,29 @@ public class Xml extends SwaggerElement {
* <p>
* Declares whether the property definition translates to an attribute instead of an element.
*
- * <p>
- * Default value is <jk>false</jk>.
- *
- * @param attribute The new value for the <property>attribute</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Default value is <jk>false</jk>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Xml setAttribute(Boolean attribute) {
- this.attribute = attribute;
+ public Xml setAttribute(Boolean value) {
+ attribute = value;
return this;
}
/**
- * Synonym for {@link #setAttribute(Boolean)}.
+ * Same as {@link #setAttribute(Boolean)}.
*
- * @param attribute The new value for the <property>attribute</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Default value is <jk>false</jk>.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Xml attribute(Boolean attribute) {
- return setAttribute(attribute);
+ public Xml attribute(Object value) {
+ return setAttribute(toBoolean(value));
}
/**
@@ -219,11 +249,10 @@ public class Xml extends SwaggerElement {
* Signifies whether the array is wrapped (for example,
* <code><books><book/><book/><books></code>) or unwrapped
* (<code><book/><book/></code>).
- * Default value is <jk>false</jk>.
- * The definition takes effect only when defined alongside <code>type</code> being <code>array</code>
+ * <br<The definition takes effect only when defined alongside <code>type</code> being <code>array</code>
* (outside the <code>items</code>).
*
- * @return The value of the <property>wrapped</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getWrapped() {
return wrapped;
@@ -239,25 +268,59 @@ public class Xml extends SwaggerElement {
* Signifies whether the array is wrapped (for example,
* <code><books><book/><book/><books></code>) or unwrapped
* (<code><book/><book/></code>).
- * Default value is <jk>false</jk>.
- * The definition takes effect only when defined alongside <code>type</code> being <code>array</code>
+ * <br<The definition takes effect only when defined alongside <code>type</code> being <code>array</code>
* (outside the <code>items</code>).
*
- * @param wrapped The new value for the <property>wrapped</property> property on this bean.
+ * @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 Xml setWrapped(Boolean wrapped) {
- this.wrapped = wrapped;
+ public Xml setWrapped(Boolean value) {
+ this.wrapped = value;
return this;
}
/**
- * Synonym for {@link #setWrapped(Boolean)}.
+ * Same as {@link #setWrapped(Boolean)}.
*
- * @param wrapped The new value for the <property>wrapped</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Xml wrapped(Boolean wrapped) {
- return setWrapped(wrapped);
+ public Xml wrapped(Object value) {
+ return setWrapped(toBoolean(value));
+ }
+
+ @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 "namespace": return toType(getNamespace(), type);
+ case "prefix": return toType(getPrefix(), type);
+ case "attribute": return toType(getAttribute(), type);
+ case "wrapped": return toType(getWrapped(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public Xml set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "name": return name(value);
+ case "namespace": return namespace(value);
+ case "prefix": return prefix(value);
+ case "attribute": return attribute(value);
+ case "wrapped": return wrapped(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/package.html
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/package.html b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/package.html
index 8966843..75ecbaa 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/package.html
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/package.html
@@ -54,161 +54,5 @@
}
}
</script>
-<a id='TOC'></a><h5 class='toc'>Table of Contents</h5>
-<ol class='toc'>
- <li><p><a class='doclink' href='#Overview'>Overview</a></p>
- <ol>
- <li><p><a class='doclink' href='#Serialize'>Generating Swagger Docs</a></p>
- <li><p><a class='doclink' href='#Parse'>Parsing Swagger Docs</a></p>
- </ol>
-</ol>
-
-
-<!-- ======================================================================================================== -->
-<a id="Overview"></a>
-<h2 class='topic' onclick='toggle(this)'>1 - Overview</h2>
-<div class='topic'>
- <p>
- Juneau supports generation and consumption of Swagger 2.0 documents and fragments through the use of DTOs
- (Data Transfer Objects).
- <br>It uses existing support for serializing and parsing POJOs to and from JSON to define these objects.
- </p>
-
- <!-- ======================================================================================================== -->
- <a id="Serialize"></a>
- <h3 class='topic' onclick='toggle(this)'>1.1 - Generating Swagger Docs</h3>
- <div class='topic'>
- <p>
- The following is an example Swagger document from the <a href="http://petstore.swagger.io/">Swagger website</a>.
- </p>
- <p class='bcode'>
- {
- <jf>"swagger"</jf>: <js>"2.0"</js>,
- <jf>"info"</jf>: {
- <jf>"title"</jf>: <js>"Swagger Petstore"</js>,
- <jf>"description"</jf>: <js>"This is a sample server Petstore server."</js>,
- <jf>"version"</jf>: <js>"1.0.0"</js>,
- <jf>"termsOfService"</jf>: <js>"http://swagger.io/terms/"</js>,
- <jf>"contact"</jf>: {
- <jf>"email"</jf>: <js>"apiteam@swagger.io"</js>
- },
- <jf>"license"</jf>: {
- <jf>"name"</jf>: <js>"Apache 2.0"</js>,
- <jf>"url"</jf>: <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js>
- }
- },
- <jf>"host"</jf>: <js>"petstore.swagger.io"</js>,
- <jf>"basePath"</jf>: <js>"/v2"</js>,
- <jf>"tags"</jf>: [
- {
- <jf>"name"</jf>: <js>"pet"</js>,
- <jf>"description"</jf>: <js>"Everything about your Pets"</js>,
- <jf>"externalDocs"</jf>: {
- <jf>"description"</jf>: <js>"Find out more"</js>,
- <jf>"url"</jf>: <js>"http://swagger.io"</js>
- }
- }
- ],
- <jf>"schemes"</jf>: [
- <js>"http"</js>
- ],
- <jf>"paths"</jf>: {
- <jf>"/pet"</jf>: {
- <jf>"post"</jf>: {
- <jf>"tags"</jf>: [
- <js>"pet"</js>
- ],
- <jf>"summary"</jf>: <js>"Add a new pet to the store"</js>,
- <jf>"description"</jf>: <js>""</js>,
- <jf>"operationId"</jf>: <js>"addPet"</js>,
- <jf>"consumes"</jf>: [
- <js>"application/json"</js>,
- <js>"text/xml"</js>
- ],
- <jf>"produces"</jf>: [
- <js>"application/json"</js>,
- <js>"text/xml"</js>
- ],
- <jf>"parameters"</jf>: [
- {
- <jf>"in"</jf>: <js>"body"</js>,
- <jf>"name"</jf>: <js>"body"</js>,
- <jf>"description"</jf>: <js>"Pet object that needs to be added to the store"</js>,
- <jf>"required"</jf>: <jk>true</jk>
- }
- ],
- <jf>"responses"</jf>: {
- <jf>"405"</jf>: {
- <jf>"description"</jf>: <js>"Invalid input"</js>
- }
- }
- }
- }
- },
- }
- </p>
- <p>
- This document can be generated by the following Java code:
- </p>
- <p class='bcode'>
- <jk>static import</jk> org.apache.juneau.dto.swagger.SwaggerBuilder.*;
-
- Swagger swagger = <jsm>swagger</jsm>()
- .swagger(<js>"2.0"</js>)
- .info(
- <jsm>info</jsm>(<js>"Swagger Petstore"</js>, <js>"1.0.0"</js>)
- .description(<js>"This is a sample server Petstore server."</js>)
- .termsOfService(<js>"http://swagger.io/terms/"</js>)
- .contact(
- <jsm>contact</jsm>().email(<js>"apiteam@swagger.io"</js>)
- )
- .license(
- <jsm>license</jsm>(<js>"Apache 2.0"</js>)
- .url(<js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js>)
- )
- )
- .host(<js>"petstore.swagger.io"</js>)
- .basePath(<js>"/v2"</js>)
- .tags(
- <jsm>tag</jsm>(<js>"pet"</js>).description(<js>"Everything about your Pets"</js>)
- .externalDocs(
- <jsm>externalDocumentation</jsm>(<js>"http://swagger.io"</js>, <js>"http://swagger.io"</js>)
- )
- )
- .schemes(<js>"http"</js>)
- .path(<js>"/pet"</js>, <js>"post"</js>,
- <jsm>operation</jsm>()
- .tags(<js>"pet"</js>)
- .summary(<js>"Add a new pet to the store"</js>)
- .description(<js>""</js>)
- .operationId(<js>"addPet"</js>)
- .consumes(MediaType.<jsf>JSON</jsf>, MediaType.<jsf>XML</jsf>)
- .produces(MediaType.<jsf>JSON</jsf>, MediaType.<jsf>XML</jsf>)
- .parameters(
- <jsm>parameterInfo</jsm>(<js>"body"</js>, <js>"body"</js>)
- .description(<js>"Pet object that needs to be added to the store"</js>)
- .required(<jk>true</jk>)
- )
- .response(405, <jsm>responseInfo</jsm>(<js>"Invalid input"</js>))
- );
-
- String swaggerJson = JsonSerializer.<jsf>DEFAULT_READABLE</jsf>.serialize(swagger);
- </p>
- </div>
-
- <!-- ======================================================================================================== -->
- <a id="Parse"></a>
- <h3 class='topic' onclick='toggle(this)'>1.2 - Parsing Swagger Docs</h3>
- <div class='topic'>
- <p>
- Swagger docs can be parsed back into Swagger beans using the following code:
- </p>
- <p class='bcode'>
- Swagger swagger = JsonParser.<jsf>DEFAULT</jsf>.parse(swaggerJson, Swagger.<jk>class</jk>);
- </p>
- </div>
-
-</div>
-
</body>
</html>
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/BeanPropertyUtils.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/BeanPropertyUtils.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/BeanPropertyUtils.java
new file mode 100644
index 0000000..8a01323
--- /dev/null
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/BeanPropertyUtils.java
@@ -0,0 +1,257 @@
+// ***************************************************************************************************************************
+// * 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.internal;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
+
+/**
+ * Utility methods when working with setting of bean properties.
+ */
+public final class BeanPropertyUtils {
+
+ /**
+ * Converts a value to a String.
+ *
+ * @param o The value to convert.
+ * @return The converted value, or <jk>null</jk> if the input was null.
+ */
+ public static String toStringVal(Object o) {
+ return StringUtils.toString(o);
+ }
+
+ /**
+ * Converts a value to a Boolean.
+ *
+ * @param o The value to convert.
+ * @return The converted value, or <jk>null</jk> if the input was null.
+ */
+ public static Boolean toBoolean(Object o) {
+ return ObjectUtils.toBoolean(o);
+ }
+
+ /**
+ * Converts a value to a Number.
+ *
+ * @param o The value to convert.
+ * @return The converted value, or <jk>null</jk> if the input was null.
+ */
+ public static Number toNumber(Object o) {
+ return ObjectUtils.toNumber(o);
+ }
+
+ /**
+ * Converts a value to an Integer.
+ *
+ * @param o The value to convert.
+ * @return The converted value, or <jk>null</jk> if the input was null.
+ */
+ public static Integer toInteger(Object o) {
+ return ObjectUtils.toInteger(o);
+ }
+
+ /**
+ * Converts a value to a URI.
+ *
+ * @param o The value to convert.
+ * @return The converted value, or <jk>null</jk> if the input was null.
+ */
+ public static java.net.URI toURI(Object o) {
+ return StringUtils.toURI(o);
+ }
+
+ /**
+ * Adds a set of values to an existing list.
+ *
+ * @param appendTo
+ * The list to append to.
+ * <br>If <jk>null</jk>, a new {@link ArrayList} will be created.
+ * @param values The values to add.
+ * @param type The data type of the elements.
+ * @param args The generic type arguments of the data type.
+ * @return The converted value, or <jk>null</jk> if the input was null.
+ */
+ public static <T> List<T> addToList(List<T> appendTo, Object[] values, Class<T> type, Type...args) {
+ if (values == null)
+ return appendTo;
+ try {
+ List<T> l = appendTo == null ? new ArrayList<T>() : appendTo;
+ for (Object o : values) {
+ if (o != null) {
+ if (isObjectList(o)) {
+ for (Object o2 : new ObjectList(o.toString()))
+ l.add(toType(o2, type, args));
+ } else if (o instanceof Collection) {
+ for (Object o2 : (Collection<?>)o)
+ l.add(toType(o2, type, args));
+ } else if (o.getClass().isArray()) {
+ for (int i = 0; i < Array.getLength(o); i++)
+ l.add(toType(Array.get(o, i), type, args));
+ } else {
+ l.add(toType(o, type, args));
+ }
+ }
+ }
+ return l;
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Adds a set of values to an existing map.
+ *
+ * @param appendTo
+ * The map to append to.
+ * <br>If <jk>null</jk>, a new {@link LinkedHashMap} will be created.
+ * @param values The values to add.
+ * @param keyType The data type of the keys.
+ * @param valueType The data type of the values.
+ * @param valueTypeArgs The generic type arguments of the data type of the values.
+ * @return The converted value, or <jk>null</jk> if the input was null.
+ */
+ @SuppressWarnings("unchecked")
+ public static <K,V> Map<K,V> addToMap(Map<K,V> appendTo, Object[] values, Class<K> keyType, Class<V> valueType, Type...valueTypeArgs) {
+ if (values == null)
+ return appendTo;
+ try {
+ Map<K,V> m = appendTo == null ? new LinkedHashMap<K,V>() : appendTo;
+ for (Object o : values) {
+ if (o != null) {
+ if (isObjectMap(o)) {
+ for (Map.Entry<String,Object> e : new ObjectMap(o.toString()).entrySet())
+ m.put(toType(e.getKey(), keyType), toType(e.getValue(), valueType, valueTypeArgs));
+ } else if (o instanceof Map) {
+ for (Map.Entry<Object,Object> e : ((Map<Object,Object>)o).entrySet())
+ m.put(toType(e.getKey(), keyType), toType(e.getValue(), valueType, valueTypeArgs));
+ } else {
+ throw new FormattedRuntimeException("Invalid object type {0} passed to addToMap()", o.getClass().getName());
+ }
+ }
+ }
+ return m;
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static boolean isObjectList(Object o) {
+ if (o instanceof CharSequence) {
+ String s = o.toString();
+ return (s.startsWith("[") && s.endsWith("]") && BeanContext.DEFAULT != null);
+ }
+ return false;
+ }
+
+ private static boolean isObjectMap(Object o) {
+ if (o instanceof CharSequence) {
+ String s = o.toString();
+ return (s.startsWith("{") && s.endsWith("}") && BeanContext.DEFAULT != null);
+ }
+ return false;
+ }
+
+ /**
+ * Converts an object to the specified type.
+ *
+ * @param o The object to convert.
+ * @param type The type to covert to.
+ * @param args The type arguments for types of map or collection.
+ * @return The converted object.
+ */
+ public static <T> T toType(Object o, Class<T> type, Type...args) {
+ return ObjectUtils.toType(o, type, args);
+ }
+
+ /**
+ * Creates a new list from the specified collection.
+ *
+ * @param val The value to copy from.
+ * @return A new {@link ArrayList}, or <jk>null</jk> if the input was null.
+ */
+ public static <T> List<T> newList(Collection<T> val) {
+ if (val == null)
+ return null;
+ return new ArrayList<>(val);
+ }
+
+ /**
+ * Copies the specified values into an existing list.
+ *
+ * @param l
+ * The list to add to.
+ * <br>If <jk>null</jk>, a new {@link ArrayList} will be created.
+ * @param val The values to add.
+ * @return The list with values copied into it.
+ */
+ public static <T> List<T> addToList(List<T> l, Collection<T> val) {
+ if (val != null) {
+ if (l == null)
+ l = new ArrayList<>(val);
+ else
+ l.addAll(val);
+ }
+ return l;
+ }
+
+ /**
+ * Creates a new map from the specified map.
+ *
+ * @param val The value to copy from.
+ * @return A new {@link LinkedHashMap}, or <jk>null</jk> if the input was null.
+ */
+ public static <K,V> Map<K,V> newMap(Map<K,V> val) {
+ if (val == null)
+ return null;
+ return new LinkedHashMap<>(val);
+ }
+
+ /**
+ * Copies the specified values into an existing map.
+ *
+ * @param m
+ * The map to add to.
+ * <br>If <jk>null</jk>, a new {@link LinkedHashMap} will be created.
+ * @param val The values to add.
+ * @return The list with values copied into it.
+ */
+ public static <K,V> Map<K,V> addToMap(Map<K,V> m, Map<K,V> val) {
+ if (val != null) {
+ if (m == null)
+ m = new LinkedHashMap<>(val);
+ else
+ m.putAll(val);
+ }
+ return m;
+ }
+
+ /**
+ * Adds a single entry into an existing map.
+ *
+ * @param m
+ * The map to add to.
+ * <br>If <jk>null</jk>, a new {@link LinkedHashMap} will be created.
+ * @param key The entry key.
+ * @param value The entry value.
+ * @return The list with values copied into it.
+ */
+ public static <K,V> Map<K,V> addToMap(Map<K,V> m, K key, V value) {
+ if (m == null)
+ m = new LinkedHashMap<>();
+ m.put(key, value);
+ return m;
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
index d188cfb..19dd747 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
@@ -16,6 +16,7 @@ import java.lang.reflect.*;
import java.util.*;
import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
import org.apache.juneau.transform.*;
/**
@@ -162,10 +163,25 @@ public final class ObjectUtils {
* @throws InvalidDataConversionException If the specified value cannot be converted to the specified type.
* @return The converted value.
*/
- public static <T> T convertToType(Object value, Class<T> type) {
+ public static <T> T toType(Object value, Class<T> type) {
return session.convertToType(value, type);
}
+
+ /**
+ * Converts the specified object to the specified type.
+ *
+ * @param <T> The class type to convert the value to.
+ * @param value The value to convert.
+ * @param type The class type to convert the value to.
+ * @param args The type arguments.
+ * @throws InvalidDataConversionException If the specified value cannot be converted to the specified type.
+ * @return The converted value.
+ */
+ public static <T> T toType(Object value, Class<T> type, Type...args) {
+ return session.convertToType(value, type, args);
+ }
+
/**
* Converts the specified object to the specified type.
*
@@ -178,7 +194,7 @@ public final class ObjectUtils {
* @throws InvalidDataConversionException If the specified value cannot be converted to the specified type.
* @return The converted value.
*/
- public static <T> T convertToMemberType(Object outer, Object value, Class<T> type) {
+ public static <T> T toMemberType(Object outer, Object value, Class<T> type) {
return session.convertToMemberType(outer, value, type);
}
@@ -243,4 +259,42 @@ public final class ObjectUtils {
return tt;
return null;
}
+
+ /**
+ * Converts an object to a Boolean.
+ *
+ * @param o The object to convert.
+ * @return The converted object.
+ */
+ public static Boolean toBoolean(Object o) {
+ return toType(o, Boolean.class);
+ }
+
+ /**
+ * Converts an object to an Integer.
+ *
+ * @param o The object to convert.
+ * @return The converted object.
+ */
+ public static Integer toInteger(Object o) {
+ return toType(o, Integer.class);
+ }
+
+ /**
+ * Converts an object to a Number.
+ *
+ * @param o The object to convert.
+ * @return The converted object.
+ */
+ public static Number toNumber(Object o) {
+ if (o == null)
+ return null;
+ if (o instanceof Number)
+ return (Number)o;
+ try {
+ return StringUtils.parseNumber(o.toString(), null);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
index d4ed252..e5b2b45 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/StringUtils.java
@@ -121,12 +121,13 @@ public final class StringUtils {
* <li> BigInteger
* <li> BigDecimal
* </ul>
- * If <jk>null</jk>, uses the best guess.
- * @return The parsed number.
+ * If <jk>null</jk> or <code>Number</code>, uses the best guess.
+ * @return The parsed number, or <jk>null</jk> if the string was null.
* @throws ParseException
*/
public static Number parseNumber(String s, Class<? extends Number> type) throws ParseException {
-
+ if (s == null)
+ return null;
if (s.isEmpty())
s = "0";
if (type == null)
[10/10] juneau git commit: JUNEAU-78
Posted by ja...@apache.org.
JUNEAU-78
Support for missing $ref field.
Project: http://git-wip-us.apache.org/repos/asf/juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/juneau/commit/8df34f56
Tree: http://git-wip-us.apache.org/repos/asf/juneau/tree/8df34f56
Diff: http://git-wip-us.apache.org/repos/asf/juneau/diff/8df34f56
Branch: refs/heads/master
Commit: 8df34f56dc3b0f5e67318ad050f8e288a58d6c00
Parents: 6f4b27e
Author: JamesBognar <ja...@apache.org>
Authored: Thu Jan 18 14:00:53 2018 -0500
Committer: JamesBognar <ja...@apache.org>
Committed: Thu Jan 18 14:00:53 2018 -0500
----------------------------------------------------------------------
.../apache/juneau/dto/swagger/ContactTest.java | 123 ++
.../dto/swagger/ExternalDocumentationTest.java | 101 ++
.../juneau/dto/swagger/HeaderInfoTest.java | 607 ++++++++++
.../org/apache/juneau/dto/swagger/InfoTest.java | 200 ++++
.../apache/juneau/dto/swagger/ItemsTest.java | 582 ++++++++++
.../apache/juneau/dto/swagger/LicenseTest.java | 109 ++
.../juneau/dto/swagger/OperationTest.java | 675 +++++++++++
.../juneau/dto/swagger/ParameterInfoTest.java | 729 ++++++++++++
.../juneau/dto/swagger/ResponseInfoTest.java | 265 +++++
.../juneau/dto/swagger/SchemaInfoTest.java | 1011 ++++++++++++++++
.../juneau/dto/swagger/SecuritySchemeTest.java | 284 +++++
.../juneau/dto/swagger/SwaggerBuilderTest.java | 322 ++++++
.../apache/juneau/dto/swagger/SwaggerTest.java | 910 +++++++++++++++
.../org/apache/juneau/dto/swagger/TagTest.java | 133 +++
.../org/apache/juneau/dto/swagger/XmlTest.java | 186 +++
.../apache/juneau/dto/html5/HtmlElement.java | 2 +-
.../juneau/dto/html5/HtmlElementContainer.java | 2 +-
.../juneau/dto/html5/HtmlElementMixed.java | 2 +-
.../org/apache/juneau/dto/swagger/Contact.java | 126 +-
.../dto/swagger/ExternalDocumentation.java | 123 +-
.../apache/juneau/dto/swagger/HeaderInfo.java | 829 +++++++------
.../org/apache/juneau/dto/swagger/Info.java | 233 ++--
.../org/apache/juneau/dto/swagger/Items.java | 828 ++++++++-----
.../org/apache/juneau/dto/swagger/License.java | 119 +-
.../apache/juneau/dto/swagger/Operation.java | 883 ++++++++------
.../juneau/dto/swagger/ParameterInfo.java | 1094 +++++++++++-------
.../apache/juneau/dto/swagger/ResponseInfo.java | 267 +++--
.../apache/juneau/dto/swagger/SchemaInfo.java | 996 ++++++++++------
.../juneau/dto/swagger/SecurityScheme.java | 352 +++---
.../org/apache/juneau/dto/swagger/Swagger.java | 1005 +++++++++-------
.../juneau/dto/swagger/SwaggerBuilder.java | 163 ++-
.../juneau/dto/swagger/SwaggerElement.java | 105 +-
.../java/org/apache/juneau/dto/swagger/Tag.java | 147 ++-
.../java/org/apache/juneau/dto/swagger/Xml.java | 205 ++--
.../org/apache/juneau/dto/swagger/package.html | 156 ---
.../juneau/internal/BeanPropertyUtils.java | 257 ++++
.../org/apache/juneau/internal/ObjectUtils.java | 58 +-
.../org/apache/juneau/internal/StringUtils.java | 7 +-
38 files changed, 11205 insertions(+), 2991 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ContactTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ContactTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ContactTest.java
new file mode 100644
index 0000000..90be313
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ContactTest.java
@@ -0,0 +1,123 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+
+import static org.junit.Assert.*;
+
+import java.net.*;
+
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+/**
+ * Testcase for {@link Contact}.
+ */
+public class ContactTest {
+
+ /**
+ * Test method for {@link Contact#name(java.lang.Object)}.
+ */
+ @Test
+ public void testName() {
+ Contact t = new Contact();
+
+ t.name("foo");
+ assertEquals("foo", t.getName());
+
+ t.name(new StringBuilder("foo"));
+ assertEquals("foo", t.getName());
+ assertType(String.class, t.getName());
+
+ t.name(null);
+ assertNull(t.getName());
+ }
+
+ /**
+ * Test method for {@link Contact#url(java.lang.Object)}.
+ */
+ @Test
+ public void testUrl() {
+ Contact t = new Contact();
+
+ t.url("foo");
+ assertEquals("foo", t.getUrl().toString());
+
+ t.url(new StringBuilder("foo"));
+ assertEquals("foo", t.getUrl().toString());
+ assertType(URI.class, t.getUrl());
+
+ t.url(null);
+ assertNull(t.getUrl());
+ }
+
+ /**
+ * Test method for {@link Contact#email(java.lang.Object)}.
+ */
+ @Test
+ public void testEmail() {
+ Contact t = new Contact();
+
+ t.email("foo");
+ assertEquals("foo", t.getEmail());
+
+ t.email(new StringBuilder("foo"));
+ assertEquals("foo", t.getEmail());
+ assertType(String.class, t.getEmail());
+
+ t.email(null);
+ assertNull(t.getEmail());
+ }
+
+ /**
+ * Test method for {@link Contact#set(String, Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ Contact t = new Contact();
+
+ t
+ .set("name", "foo")
+ .set("url", "bar")
+ .set("email", "baz")
+ .set("$ref", "qux");
+
+ assertObjectEquals("{name:'foo',url:'bar',email:'baz','$ref':'qux'}", t);
+
+ t
+ .set("name", new StringBuilder("foo"))
+ .set("url", new StringBuilder("bar"))
+ .set("email", new StringBuilder("baz"))
+ .set("$ref", new StringBuilder("qux"));
+
+ assertObjectEquals("{name:'foo',url:'bar',email:'baz','$ref':'qux'}", t);
+
+ assertEquals("foo", t.get("name", String.class));
+ assertEquals("bar", t.get("url", URI.class).toString());
+ assertEquals("baz", t.get("email", String.class));
+ assertEquals("qux", t.get("$ref", String.class));
+
+ assertType(String.class, t.get("name", String.class));
+ assertType(URI.class, t.get("url", URI.class));
+ assertType(String.class, t.get("email", String.class));
+ assertType(String.class, t.get("$ref", String.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ assertObjectEquals("{name:'foo',url:'bar',email:'baz','$ref':'qux'}", JsonParser.DEFAULT.parse("{name:'foo',url:'bar',email:'baz','$ref':'qux'}", Contact.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ExternalDocumentationTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ExternalDocumentationTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ExternalDocumentationTest.java
new file mode 100644
index 0000000..d92cc4d
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ExternalDocumentationTest.java
@@ -0,0 +1,101 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.net.*;
+
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+/**
+ * Testcase for {@link ExternalDocumentation}.
+ */
+public class ExternalDocumentationTest {
+
+ /**
+ * Test method for {@link ExternalDocumentation#description(java.lang.Object)}.
+ */
+ @Test
+ public void testDescription() {
+ ExternalDocumentation t = new ExternalDocumentation();
+
+ t.description("foo");
+ assertEquals("foo", t.getDescription());
+
+ t.description(new StringBuilder("foo"));
+ assertEquals("foo", t.getDescription());
+ assertType(String.class, t.getDescription());
+
+ t.description(null);
+ assertNull(t.getDescription());
+ }
+
+ /**
+ * Test method for {@link ExternalDocumentation#url(java.lang.Object)}.
+ */
+ @Test
+ public void testUrl() {
+ ExternalDocumentation t = new ExternalDocumentation();
+
+ t.url("foo");
+ assertEquals("foo", t.getUrl().toString());
+
+ t.url(new StringBuilder("foo"));
+ assertEquals("foo", t.getUrl().toString());
+ assertType(URI.class, t.getUrl());
+
+ t.url(null);
+ assertNull(t.getUrl());
+ }
+
+ /**
+ * Test method for {@link ExternalDocumentation#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ ExternalDocumentation t = new ExternalDocumentation();
+
+ t
+ .set("description", "foo")
+ .set("url", "bar")
+ .set("$ref", "baz");
+
+ assertObjectEquals("{description:'foo',url:'bar','$ref':'baz'}", t);
+
+ t
+ .set("description", new StringBuilder("foo"))
+ .set("url", new StringBuilder("bar"))
+ .set("$ref", new StringBuilder("baz"));
+
+ assertObjectEquals("{description:'foo',url:'bar','$ref':'baz'}", t);
+
+ assertEquals("foo", t.get("description", String.class));
+ assertEquals("bar", t.get("url", URI.class).toString());
+ assertEquals("baz", t.get("$ref", String.class));
+
+ assertType(String.class, t.get("description", String.class));
+ assertType(URI.class, t.get("url", URI.class));
+ assertType(String.class, t.get("$ref", String.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ assertObjectEquals("{description:'foo',url:'bar','$ref':'baz'}", JsonParser.DEFAULT.parse("{description:'foo',url:'bar','$ref':'baz'}", ExternalDocumentation.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/HeaderInfoTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/HeaderInfoTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/HeaderInfoTest.java
new file mode 100644
index 0000000..4eece6b
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/HeaderInfoTest.java
@@ -0,0 +1,607 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.*;
+
+import org.apache.juneau.json.*;
+import org.apache.juneau.utils.*;
+
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+
+import org.junit.*;
+
+/**
+ * Testcase for {@link HeaderInfo}.
+ */
+public class HeaderInfoTest {
+
+ /**
+ * Test method for {@link HeaderInfo#description(java.lang.Object)}.
+ */
+ @Test
+ public void testDescription() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.description("foo");
+ assertEquals("foo", t.getDescription());
+
+ t.description(new StringBuilder("foo"));
+ assertEquals("foo", t.getDescription());
+ assertType(String.class, t.getDescription());
+
+ t.description(null);
+ assertNull(t.getDescription());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#type(java.lang.Object)}.
+ */
+ @Test
+ public void testType() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.type("foo");
+ assertEquals("foo", t.getType());
+
+ t.type(new StringBuilder("foo"));
+ assertEquals("foo", t.getType());
+ assertType(String.class, t.getType());
+
+ t.type(null);
+ assertNull(t.getType());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#format(java.lang.Object)}.
+ */
+ @Test
+ public void testFormat() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.format("foo");
+ assertEquals("foo", t.getFormat());
+
+ t.format(new StringBuilder("foo"));
+ assertEquals("foo", t.getFormat());
+ assertType(String.class, t.getFormat());
+
+ t.format(null);
+ assertNull(t.getFormat());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#items(java.lang.Object)}.
+ */
+ @Test
+ public void testItems() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.items(items("foo"));
+ assertObjectEquals("{type:'foo'}", t.getItems());
+
+ t.items("{type:'foo'}");
+ assertObjectEquals("{type:'foo'}", t.getItems());
+ assertType(Items.class, t.getItems());
+
+ t.items(null);
+ assertNull(t.getItems());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#collectionFormat(java.lang.Object)}.
+ */
+ @Test
+ public void testCollectionFormat() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.collectionFormat("foo");
+ assertEquals("foo", t.getCollectionFormat());
+
+ t.collectionFormat(new StringBuilder("foo"));
+ assertEquals("foo", t.getCollectionFormat());
+ assertType(String.class, t.getCollectionFormat());
+
+ t.collectionFormat(null);
+ assertNull(t.getCollectionFormat());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#_default(java.lang.Object)}.
+ */
+ @Test
+ public void test_default() {
+ HeaderInfo t = new HeaderInfo();
+
+ t._default("foo");
+ assertEquals("foo", t.getDefault());
+
+ t._default(new StringBuilder("foo"));
+ assertEquals("foo", t.getDefault().toString());
+ assertType(StringBuilder.class, t.getDefault());
+
+ t._default(null);
+ assertNull(t.getDefault());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#maximum(java.lang.Object)}.
+ */
+ @Test
+ public void testMaximum() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.maximum(123);
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(123f);
+ assertEquals(123f, t.getMaximum());
+ assertType(Float.class, t.getMaximum());
+
+ t.maximum("123");
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(new StringBuilder("123"));
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(null);
+ assertNull(t.getMaximum());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#exclusiveMaximum(java.lang.Object)}.
+ */
+ @Test
+ public void testExclusiveMaximum() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.exclusiveMaximum(true);
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum("true");
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum(new StringBuilder("true"));
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum(null);
+ assertNull(t.getExclusiveMaximum());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#minimum(java.lang.Object)}.
+ */
+ @Test
+ public void testMinimum() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.minimum(123);
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(123f);
+ assertEquals(123f, t.getMinimum());
+ assertType(Float.class, t.getMinimum());
+
+ t.minimum("123");
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(new StringBuilder("123"));
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(null);
+ assertNull(t.getMinimum());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#exclusiveMinimum(java.lang.Object)}.
+ */
+ @Test
+ public void testExclusiveMinimum() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.exclusiveMinimum(true);
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum("true");
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum(new StringBuilder("true"));
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum(null);
+ assertNull(t.getExclusiveMinimum());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#maxLength(java.lang.Object)}.
+ */
+ @Test
+ public void testMaxLength() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.maxLength(123);
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(123f);
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength("123");
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(new StringBuilder("123"));
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(null);
+ assertNull(t.getMaxLength());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#minLength(java.lang.Object)}.
+ */
+ @Test
+ public void testMinLength() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.minLength(123);
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(123f);
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength("123");
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(new StringBuilder("123"));
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(null);
+ assertNull(t.getMinLength());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#pattern(java.lang.Object)}.
+ */
+ @Test
+ public void testPattern() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.pattern("foo");
+ assertEquals("foo", t.getPattern());
+
+ t.pattern(new StringBuilder("foo"));
+ assertEquals("foo", t.getPattern());
+ assertType(String.class, t.getPattern());
+
+ t.pattern(null);
+ assertNull(t.getPattern());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#maxItems(java.lang.Object)}.
+ */
+ @Test
+ public void testMaxItems() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.maxItems(123);
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(123f);
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems("123");
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(new StringBuilder("123"));
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(null);
+ assertNull(t.getMaxItems());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#minItems(java.lang.Object)}.
+ */
+ @Test
+ public void testMinItems() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.minItems(123);
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(123f);
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems("123");
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(new StringBuilder("123"));
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(null);
+ assertNull(t.getMinItems());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#uniqueItems(java.lang.Object)}.
+ */
+ @Test
+ public void testUniqueItems() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.uniqueItems(true);
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems("true");
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems(new StringBuilder("true"));
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems(null);
+ assertNull(t.getUniqueItems());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#setEnum(java.util.Collection)}.
+ */
+ @Test
+ public void testSetEnum() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.setEnum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(new ASet<Object>());
+ assertObjectEquals("[]", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(null);
+ assertNull(t.getEnum());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#addEnum(java.util.Collection)}.
+ */
+ @Test
+ public void testAddEnum() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.addEnum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.addEnum(new ASet<Object>().appendAll("baz"));
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.addEnum(null);
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#_enum(java.lang.Object[])}.
+ */
+ @Test
+ public void test_enum() {
+ HeaderInfo t = new HeaderInfo();
+
+ t._enum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t._enum(new ASet<Object>().appendAll("baz"));
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t._enum((Object[])null);
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(null);
+ t._enum("foo")._enum(new StringBuilder("bar"))._enum("['baz','qux']")._enum((Object)new String[]{"quux"});
+ assertObjectEquals("['foo','bar','baz','qux','quux']", t.getEnum());
+ assertType(List.class, t.getEnum());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#multipleOf(java.lang.Object)}.
+ */
+ @Test
+ public void testMultipleOf() {
+ HeaderInfo t = new HeaderInfo();
+
+ t.multipleOf(123);
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(123f);
+ assertEquals(123f, t.getMultipleOf());
+ assertType(Float.class, t.getMultipleOf());
+
+ t.multipleOf("123");
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(new StringBuilder("123"));
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(null);
+ assertNull(t.getMultipleOf());
+ }
+
+ /**
+ * Test method for {@link HeaderInfo#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ HeaderInfo t = new HeaderInfo();
+
+ t
+ .set("default", "a")
+ .set("enum", new ASet<String>().append("b"))
+ .set("collectionFormat", "c")
+ .set("description", "d")
+ .set("exclusiveMaximum", true)
+ .set("exclusiveMinimum", true)
+ .set("format", "g")
+ .set("items", items("h"))
+ .set("maximum", 123f)
+ .set("maxItems", 123)
+ .set("maxLength", 123)
+ .set("minimum", 123f)
+ .set("minItems", 123)
+ .set("minLength", 123)
+ .set("multipleOf", 123f)
+ .set("pattern", "i")
+ .set("type", "j")
+ .set("uniqueItems", true)
+ .set("$ref", "ref");
+
+ assertObjectEquals("{description:'d',type:'j',format:'g',items:{type:'h'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}", t);
+
+ t
+ .set("default", "a")
+ .set("enum", "['b']")
+ .set("collectionFormat", "c")
+ .set("description", "d")
+ .set("exclusiveMaximum", "true")
+ .set("exclusiveMinimum", "true")
+ .set("format", "g")
+ .set("items", "{type:'h'}")
+ .set("maximum", "123f")
+ .set("maxItems", "123")
+ .set("maxLength", "123")
+ .set("minimum", "123f")
+ .set("minItems", "123")
+ .set("minLength", "123")
+ .set("multipleOf", "123f")
+ .set("pattern", "i")
+ .set("type", "j")
+ .set("uniqueItems", "true")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{description:'d',type:'j',format:'g',items:{type:'h'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}", t);
+
+ t
+ .set("default", new StringBuilder("a"))
+ .set("enum", new StringBuilder("['b']"))
+ .set("collectionFormat", new StringBuilder("c"))
+ .set("description", new StringBuilder("d"))
+ .set("exclusiveMaximum", new StringBuilder("true"))
+ .set("exclusiveMinimum", new StringBuilder("true"))
+ .set("format", new StringBuilder("g"))
+ .set("items", new StringBuilder("{type:'h'}"))
+ .set("maximum", new StringBuilder("123f"))
+ .set("maxItems", new StringBuilder("123"))
+ .set("maxLength", new StringBuilder("123"))
+ .set("minimum", new StringBuilder("123f"))
+ .set("minItems", new StringBuilder("123"))
+ .set("minLength", new StringBuilder("123"))
+ .set("multipleOf", new StringBuilder("123f"))
+ .set("pattern", new StringBuilder("i"))
+ .set("type", new StringBuilder("j"))
+ .set("uniqueItems", new StringBuilder("true"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{description:'d',type:'j',format:'g',items:{type:'h'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}", t);
+
+ assertEquals("a", t.get("default", String.class));
+ assertEquals("['b']", t.get("enum", String.class));
+ assertEquals("c", t.get("collectionFormat", String.class));
+ assertEquals("d", t.get("description", String.class));
+ assertEquals("true", t.get("exclusiveMaximum", String.class));
+ assertEquals("true", t.get("exclusiveMinimum", String.class));
+ assertEquals("g", t.get("format", String.class));
+ assertEquals("{type:'h'}", t.get("items", String.class));
+ assertEquals("123.0", t.get("maximum", String.class));
+ assertEquals("123", t.get("maxItems", String.class));
+ assertEquals("123", t.get("maxLength", String.class));
+ assertEquals("123.0", t.get("minimum", String.class));
+ assertEquals("123", t.get("minItems", String.class));
+ assertEquals("123", t.get("minLength", String.class));
+ assertEquals("123.0", t.get("multipleOf", String.class));
+ assertEquals("i", t.get("pattern", String.class));
+ assertEquals("j", t.get("type", String.class));
+ assertEquals("true", t.get("uniqueItems", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(StringBuilder.class, t.get("default", Object.class));
+ assertType(List.class, t.get("enum", Object.class));
+ assertType(String.class, t.get("collectionFormat", Object.class));
+ assertType(String.class, t.get("description", Object.class));
+ assertType(Boolean.class, t.get("exclusiveMaximum", Object.class));
+ assertType(Boolean.class, t.get("exclusiveMinimum", Object.class));
+ assertType(String.class, t.get("format", Object.class));
+ assertType(Items.class, t.get("items", Object.class));
+ assertType(Float.class, t.get("maximum", Object.class));
+ assertType(Integer.class, t.get("maxItems", Object.class));
+ assertType(Integer.class, t.get("maxLength", Object.class));
+ assertType(Float.class, t.get("minimum", Object.class));
+ assertType(Integer.class, t.get("minItems", Object.class));
+ assertType(Integer.class, t.get("minLength", Object.class));
+ assertType(Float.class, t.get("multipleOf", Object.class));
+ assertType(String.class, t.get("pattern", Object.class));
+ assertType(String.class, t.get("type", Object.class));
+ assertType(Boolean.class, t.get("uniqueItems", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ JsonSerializer.DEFAULT_LAX.println(t);
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{description:'d',type:'j',format:'g',items:{type:'h'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, HeaderInfo.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/InfoTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/InfoTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/InfoTest.java
new file mode 100644
index 0000000..ce7d48c
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/InfoTest.java
@@ -0,0 +1,200 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+/**
+ * Testcase for {@link Info}.
+ */
+public class InfoTest {
+
+ /**
+ * Test method for {@link Info#title(java.lang.Object)}.
+ */
+ @Test
+ public void testTitle() {
+ Info t = new Info();
+
+ t.title("foo");
+ assertEquals("foo", t.getTitle());
+
+ t.title(new StringBuilder("foo"));
+ assertEquals("foo", t.getTitle());
+ assertType(String.class, t.getTitle());
+
+ t.title(null);
+ assertNull(t.getTitle());
+ }
+
+ /**
+ * Test method for {@link Info#description(java.lang.Object)}.
+ */
+ @Test
+ public void testDescription() {
+ Info t = new Info();
+
+ t.description("foo");
+ assertEquals("foo", t.getDescription());
+
+ t.description(new StringBuilder("foo"));
+ assertEquals("foo", t.getDescription());
+ assertType(String.class, t.getDescription());
+
+ t.description(null);
+ assertNull(t.getDescription());
+ }
+
+ /**
+ * Test method for {@link Info#termsOfService(java.lang.Object)}.
+ */
+ @Test
+ public void testTermsOfService() {
+ Info t = new Info();
+
+ t.termsOfService("foo");
+ assertEquals("foo", t.getTermsOfService());
+
+ t.termsOfService(new StringBuilder("foo"));
+ assertEquals("foo", t.getTermsOfService());
+ assertType(String.class, t.getTermsOfService());
+
+ t.termsOfService(null);
+ assertNull(t.getTermsOfService());
+ }
+
+ /**
+ * Test method for {@link Info#contact(java.lang.Object)}.
+ */
+ @Test
+ public void testContact() {
+ Info t = new Info();
+
+ t.contact(contact("foo"));
+ assertObjectEquals("{name:'foo'}", t.getContact());
+
+ t.contact("{name:'foo'}");
+ assertObjectEquals("{name:'foo'}", t.getContact());
+ assertType(Contact.class, t.getContact());
+
+ t.contact(null);
+ assertNull(t.getContact());
+ }
+
+ /**
+ * Test method for {@link Info#license(java.lang.Object)}.
+ */
+ @Test
+ public void testLicense() {
+ Info t = new Info();
+
+ t.license(license("foo"));
+ assertObjectEquals("{name:'foo'}", t.getLicense());
+
+ t.license("{name:'foo'}");
+ assertObjectEquals("{name:'foo'}", t.getLicense());
+ assertType(License.class, t.getLicense());
+
+ t.license(null);
+ assertNull(t.getLicense());
+ }
+
+ /**
+ * Test method for {@link Info#version(java.lang.Object)}.
+ */
+ @Test
+ public void testVersion() {
+ Info t = new Info();
+
+ t.version("foo");
+ assertEquals("foo", t.getVersion());
+
+ t.version(new StringBuilder("foo"));
+ assertEquals("foo", t.getVersion());
+ assertType(String.class, t.getVersion());
+
+ t.version(null);
+ assertNull(t.getVersion());
+ }
+
+ /**
+ * Test method for {@link Info#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ Info t = new Info();
+
+ t
+ .set("contact", contact("a"))
+ .set("description", "b")
+ .set("license", license("c"))
+ .set("termsOfService", "d")
+ .set("title", "e")
+ .set("version", "f")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{title:'e',description:'b',termsOfService:'d',contact:{name:'a'},license:{name:'c'},version:'f','$ref':'ref'}", t);
+
+ t
+ .set("contact", "{name:'a'}")
+ .set("description", "b")
+ .set("license", "{name:'c'}")
+ .set("termsOfService", "d")
+ .set("title", "e")
+ .set("version", "f")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{title:'e',description:'b',termsOfService:'d',contact:{name:'a'},license:{name:'c'},version:'f','$ref':'ref'}", t);
+
+ t
+ .set("contact", new StringBuilder("{name:'a'}"))
+ .set("description", new StringBuilder("b"))
+ .set("license", new StringBuilder("{name:'c'}"))
+ .set("termsOfService", new StringBuilder("d"))
+ .set("title", new StringBuilder("e"))
+ .set("version", new StringBuilder("f"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{title:'e',description:'b',termsOfService:'d',contact:{name:'a'},license:{name:'c'},version:'f','$ref':'ref'}", t);
+
+ assertEquals("{name:'a'}", t.get("contact", String.class));
+ assertEquals("b", t.get("description", String.class));
+ assertEquals("{name:'c'}", t.get("license", String.class));
+ assertEquals("d", t.get("termsOfService", String.class));
+ assertEquals("e", t.get("title", String.class));
+ assertEquals("f", t.get("version", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(Contact.class, t.get("contact", Object.class));
+ assertType(String.class, t.get("description", Object.class));
+ assertType(License.class, t.get("license", Object.class));
+ assertType(String.class, t.get("termsOfService", Object.class));
+ assertType(String.class, t.get("title", Object.class));
+ assertType(String.class, t.get("version", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{title:'e',description:'b',termsOfService:'d',contact:{name:'a'},license:{name:'c'},version:'f','$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, Info.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ItemsTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ItemsTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ItemsTest.java
new file mode 100644
index 0000000..06f313a
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ItemsTest.java
@@ -0,0 +1,582 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.*;
+
+import org.apache.juneau.json.*;
+import org.apache.juneau.utils.*;
+import org.junit.*;
+
+/**
+ * Testcase for {@link Items}.
+ */
+public class ItemsTest {
+
+ /**
+ * Test method for {@link Items#type(java.lang.Object)}.
+ */
+ @Test
+ public void testType() {
+ Items t = new Items();
+
+ t.type("foo");
+ assertEquals("foo", t.getType());
+
+ t.type(new StringBuilder("foo"));
+ assertEquals("foo", t.getType());
+ assertType(String.class, t.getType());
+
+ t.type(null);
+ assertNull(t.getType());
+ }
+
+ /**
+ * Test method for {@link Items#format(java.lang.Object)}.
+ */
+ @Test
+ public void testFormat() {
+ Items t = new Items();
+
+ t.format("foo");
+ assertEquals("foo", t.getFormat());
+
+ t.format(new StringBuilder("foo"));
+ assertEquals("foo", t.getFormat());
+ assertType(String.class, t.getFormat());
+
+ t.format(null);
+ assertNull(t.getFormat());
+ }
+
+ /**
+ * Test method for {@link Items#items(java.lang.Object)}.
+ */
+ @Test
+ public void testItems() {
+ Items t = new Items();
+
+ t.items(items("foo"));
+ assertObjectEquals("{type:'foo'}", t.getItems());
+
+ t.items("{type:'foo'}");
+ assertObjectEquals("{type:'foo'}", t.getItems());
+ assertType(Items.class, t.getItems());
+
+ t.items(null);
+ assertNull(t.getItems());
+ }
+
+ /**
+ * Test method for {@link Items#collectionFormat(java.lang.Object)}.
+ */
+ @Test
+ public void testCollectionFormat() {
+ Items t = new Items();
+
+ t.collectionFormat("foo");
+ assertEquals("foo", t.getCollectionFormat());
+
+ t.collectionFormat(new StringBuilder("foo"));
+ assertEquals("foo", t.getCollectionFormat());
+ assertType(String.class, t.getCollectionFormat());
+
+ t.collectionFormat(null);
+ assertNull(t.getCollectionFormat());
+ }
+
+ /**
+ * Test method for {@link Items#_default(java.lang.Object)}.
+ */
+ @Test
+ public void test_default() {
+ Items t = new Items();
+
+ t._default("foo");
+ assertEquals("foo", t.getDefault());
+
+ t._default(new StringBuilder("foo"));
+ assertEquals("foo", t.getDefault().toString());
+ assertType(StringBuilder.class, t.getDefault());
+
+ t._default(null);
+ assertNull(t.getDefault());
+ }
+
+ /**
+ * Test method for {@link Items#maximum(java.lang.Object)}.
+ */
+ @Test
+ public void testMaximum() {
+ Items t = new Items();
+
+ t.maximum(123);
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(123f);
+ assertEquals(123f, t.getMaximum());
+ assertType(Float.class, t.getMaximum());
+
+ t.maximum("123");
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(new StringBuilder("123"));
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(null);
+ assertNull(t.getMaximum());
+ }
+
+ /**
+ * Test method for {@link Items#exclusiveMaximum(java.lang.Object)}.
+ */
+ @Test
+ public void testExclusiveMaximum() {
+ Items t = new Items();
+
+ t.exclusiveMaximum(true);
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum("true");
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum(new StringBuilder("true"));
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum(null);
+ assertNull(t.getExclusiveMaximum());
+ }
+
+ /**
+ * Test method for {@link Items#minimum(java.lang.Object)}.
+ */
+ @Test
+ public void testMinimum() {
+ Items t = new Items();
+
+ t.minimum(123);
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(123f);
+ assertEquals(123f, t.getMinimum());
+ assertType(Float.class, t.getMinimum());
+
+ t.minimum("123");
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(new StringBuilder("123"));
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(null);
+ assertNull(t.getMinimum());
+ }
+
+ /**
+ * Test method for {@link Items#exclusiveMinimum(java.lang.Object)}.
+ */
+ @Test
+ public void testExclusiveMinimum() {
+ Items t = new Items();
+
+ t.exclusiveMinimum(true);
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum("true");
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum(new StringBuilder("true"));
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum(null);
+ assertNull(t.getExclusiveMinimum());
+ }
+
+ /**
+ * Test method for {@link Items#maxLength(java.lang.Object)}.
+ */
+ @Test
+ public void testMaxLength() {
+ Items t = new Items();
+
+ t.maxLength(123);
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(123f);
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength("123");
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(new StringBuilder("123"));
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(null);
+ assertNull(t.getMaxLength());
+ }
+
+ /**
+ * Test method for {@link Items#minLength(java.lang.Object)}.
+ */
+ @Test
+ public void testMinLength() {
+ Items t = new Items();
+
+ t.minLength(123);
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(123f);
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength("123");
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(new StringBuilder("123"));
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(null);
+ assertNull(t.getMinLength());
+ }
+
+ /**
+ * Test method for {@link Items#pattern(java.lang.Object)}.
+ */
+ @Test
+ public void testPattern() {
+ Items t = new Items();
+
+ t.pattern("foo");
+ assertEquals("foo", t.getPattern());
+
+ t.pattern(new StringBuilder("foo"));
+ assertEquals("foo", t.getPattern());
+ assertType(String.class, t.getPattern());
+
+ t.pattern(null);
+ assertNull(t.getPattern());
+ }
+
+ /**
+ * Test method for {@link Items#maxItems(java.lang.Object)}.
+ */
+ @Test
+ public void testMaxItems() {
+ Items t = new Items();
+
+ t.maxItems(123);
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(123f);
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems("123");
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(new StringBuilder("123"));
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(null);
+ assertNull(t.getMaxItems());
+ }
+
+ /**
+ * Test method for {@link Items#minItems(java.lang.Object)}.
+ */
+ @Test
+ public void testMinItems() {
+ Items t = new Items();
+
+ t.minItems(123);
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(123f);
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems("123");
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(new StringBuilder("123"));
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(null);
+ assertNull(t.getMinItems());
+ }
+
+ /**
+ * Test method for {@link Items#uniqueItems(java.lang.Object)}.
+ */
+ @Test
+ public void testUniqueItems() {
+ Items t = new Items();
+
+ t.uniqueItems(true);
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems("true");
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems(new StringBuilder("true"));
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems(null);
+ assertNull(t.getUniqueItems());
+ }
+
+ /**
+ * Test method for {@link Items#setEnum(java.util.Collection)}.
+ */
+ @Test
+ public void testSetEnum() {
+ Items t = new Items();
+
+ t.setEnum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(new ASet<Object>());
+ assertObjectEquals("[]", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(null);
+ assertNull(t.getEnum());
+ }
+
+ /**
+ * Test method for {@link Items#addEnum(java.util.Collection)}.
+ */
+ @Test
+ public void testAddEnum() {
+ Items t = new Items();
+
+ t.addEnum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.addEnum(new ASet<Object>().appendAll("baz"));
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.addEnum(null);
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+ }
+
+ /**
+ * Test method for {@link Items#_enum(java.lang.Object[])}.
+ */
+ @Test
+ public void test_enum() {
+ Items t = new Items();
+
+ t._enum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t._enum(new ASet<Object>().appendAll("baz"));
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t._enum((Object[])null);
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(null);
+ t._enum("foo")._enum(new StringBuilder("bar"))._enum("['baz','qux']")._enum((Object)new String[]{"quux"});
+ assertObjectEquals("['foo','bar','baz','qux','quux']", t.getEnum());
+ assertType(List.class, t.getEnum());
+ }
+
+ /**
+ * Test method for {@link Items#multipleOf(java.lang.Object)}.
+ */
+ @Test
+ public void testMultipleOf() {
+ Items t = new Items();
+
+ t.multipleOf(123);
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(123f);
+ assertEquals(123f, t.getMultipleOf());
+ assertType(Float.class, t.getMultipleOf());
+
+ t.multipleOf("123");
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(new StringBuilder("123"));
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(null);
+ assertNull(t.getMultipleOf());
+ }
+
+ /**
+ * Test method for {@link Items#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ Items t = new Items();
+
+ t
+ .set("default", "a")
+ .set("enum", new ASet<String>().append("b"))
+ .set("collectionFormat", "c")
+ .set("exclusiveMaximum", true)
+ .set("exclusiveMinimum", true)
+ .set("format", "g")
+ .set("items", items("h"))
+ .set("maximum", 123f)
+ .set("maxItems", 123)
+ .set("maxLength", 123)
+ .set("minimum", 123f)
+ .set("minItems", 123)
+ .set("minLength", 123)
+ .set("multipleOf", 123f)
+ .set("pattern", "i")
+ .set("type", "j")
+ .set("uniqueItems", true)
+ .set("$ref", "ref");
+
+ assertObjectEquals("{type:'j',format:'g',items:{type:'h'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}", t);
+
+ t
+ .set("default", "a")
+ .set("enum", "['b']")
+ .set("collectionFormat", "c")
+ .set("exclusiveMaximum", "true")
+ .set("exclusiveMinimum", "true")
+ .set("format", "g")
+ .set("items", "{type:'h'}")
+ .set("maximum", "123f")
+ .set("maxItems", "123")
+ .set("maxLength", "123")
+ .set("minimum", "123f")
+ .set("minItems", "123")
+ .set("minLength", "123")
+ .set("multipleOf", "123f")
+ .set("pattern", "i")
+ .set("type", "j")
+ .set("uniqueItems", "true")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{type:'j',format:'g',items:{type:'h'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}", t);
+
+ t
+ .set("default", new StringBuilder("a"))
+ .set("enum", new StringBuilder("['b']"))
+ .set("collectionFormat", new StringBuilder("c"))
+ .set("exclusiveMaximum", new StringBuilder("true"))
+ .set("exclusiveMinimum", new StringBuilder("true"))
+ .set("format", new StringBuilder("g"))
+ .set("items", new StringBuilder("{type:'h'}"))
+ .set("maximum", new StringBuilder("123f"))
+ .set("maxItems", new StringBuilder("123"))
+ .set("maxLength", new StringBuilder("123"))
+ .set("minimum", new StringBuilder("123f"))
+ .set("minItems", new StringBuilder("123"))
+ .set("minLength", new StringBuilder("123"))
+ .set("multipleOf", new StringBuilder("123f"))
+ .set("pattern", new StringBuilder("i"))
+ .set("type", new StringBuilder("j"))
+ .set("uniqueItems", new StringBuilder("true"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{type:'j',format:'g',items:{type:'h'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}", t);
+
+ assertEquals("a", t.get("default", String.class));
+ assertEquals("['b']", t.get("enum", String.class));
+ assertEquals("c", t.get("collectionFormat", String.class));
+ assertEquals("true", t.get("exclusiveMaximum", String.class));
+ assertEquals("true", t.get("exclusiveMinimum", String.class));
+ assertEquals("g", t.get("format", String.class));
+ assertEquals("{type:'h'}", t.get("items", String.class));
+ assertEquals("123.0", t.get("maximum", String.class));
+ assertEquals("123", t.get("maxItems", String.class));
+ assertEquals("123", t.get("maxLength", String.class));
+ assertEquals("123.0", t.get("minimum", String.class));
+ assertEquals("123", t.get("minItems", String.class));
+ assertEquals("123", t.get("minLength", String.class));
+ assertEquals("123.0", t.get("multipleOf", String.class));
+ assertEquals("i", t.get("pattern", String.class));
+ assertEquals("j", t.get("type", String.class));
+ assertEquals("true", t.get("uniqueItems", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(StringBuilder.class, t.get("default", Object.class));
+ assertType(List.class, t.get("enum", Object.class));
+ assertType(String.class, t.get("collectionFormat", Object.class));
+ assertType(Boolean.class, t.get("exclusiveMaximum", Object.class));
+ assertType(Boolean.class, t.get("exclusiveMinimum", Object.class));
+ assertType(String.class, t.get("format", Object.class));
+ assertType(Items.class, t.get("items", Object.class));
+ assertType(Float.class, t.get("maximum", Object.class));
+ assertType(Integer.class, t.get("maxItems", Object.class));
+ assertType(Integer.class, t.get("maxLength", Object.class));
+ assertType(Float.class, t.get("minimum", Object.class));
+ assertType(Integer.class, t.get("minItems", Object.class));
+ assertType(Integer.class, t.get("minLength", Object.class));
+ assertType(Float.class, t.get("multipleOf", Object.class));
+ assertType(String.class, t.get("pattern", Object.class));
+ assertType(String.class, t.get("type", Object.class));
+ assertType(Boolean.class, t.get("uniqueItems", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ JsonSerializer.DEFAULT_LAX.println(t);
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{type:'j',format:'g',items:{type:'h'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, Items.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/LicenseTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/LicenseTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/LicenseTest.java
new file mode 100644
index 0000000..5983e5c
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/LicenseTest.java
@@ -0,0 +1,109 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.net.*;
+
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+/**
+ * Testcase for {@link License}.
+ */
+public class LicenseTest {
+
+ /**
+ * Test method for {@link License#name(java.lang.Object)}.
+ */
+ @Test
+ public void testName() {
+ License t = new License();
+
+ t.name("foo");
+ assertEquals("foo", t.getName());
+
+ t.name(new StringBuilder("foo"));
+ assertEquals("foo", t.getName());
+ assertType(String.class, t.getName());
+
+ t.name(null);
+ assertNull(t.getName());
+ }
+
+ /**
+ * Test method for {@link License#url(java.lang.Object)}.
+ */
+ @Test
+ public void testUrl() {
+ License t = new License();
+
+ t.url(URI.create("foo"));
+ assertEquals("foo", t.getUrl().toString());
+
+ t.url("foo");
+ assertEquals("foo", t.getUrl().toString());
+ assertType(URI.class, t.getUrl());
+
+ t.url(null);
+ assertNull(t.getUrl());
+ }
+
+ /**
+ * Test method for {@link License#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ License t = new License();
+
+ t
+ .set("name", "a")
+ .set("url", URI.create("b"))
+ .set("$ref", "ref");
+
+ assertObjectEquals("{name:'a',url:'b','$ref':'ref'}", t);
+
+ t
+ .set("name", "a")
+ .set("url", "b")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{name:'a',url:'b','$ref':'ref'}", t);
+
+ t
+ .set("name", new StringBuilder("a"))
+ .set("url", new StringBuilder("b"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{name:'a',url:'b','$ref':'ref'}", t);
+
+ assertEquals("a", t.get("name", String.class));
+ assertEquals("b", t.get("url", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(String.class, t.get("name", Object.class));
+ assertType(URI.class, t.get("url", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{name:'a',url:'b','$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, License.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/OperationTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/OperationTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/OperationTest.java
new file mode 100644
index 0000000..1f44ad1
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/OperationTest.java
@@ -0,0 +1,675 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.*;
+
+import org.apache.juneau.http.*;
+import org.apache.juneau.json.*;
+import org.apache.juneau.utils.*;
+
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+
+import org.junit.*;
+
+/**
+ * Testcase for {@link Operation}.
+ */
+public class OperationTest {
+
+ /**
+ * Test method for {@link Operation#setTags(java.util.Collection)}.
+ */
+ @Test
+ public void testSetTags() {
+ Operation t = new Operation();
+
+ t.setTags(new ASet<String>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getTags());
+ assertType(List.class, t.getTags());
+
+ t.setTags(new ASet<String>());
+ assertObjectEquals("[]", t.getTags());
+ assertType(List.class, t.getTags());
+
+ t.setTags(null);
+ assertNull(t.getTags());
+ }
+
+ /**
+ * Test method for {@link Operation#addTags(java.util.Collection)}.
+ */
+ @Test
+ public void testAddTags() {
+ Operation t = new Operation();
+
+ t.addTags(new ASet<String>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getTags());
+ assertType(List.class, t.getTags());
+
+ t.addTags(new ASet<String>());
+ assertObjectEquals("['foo','bar']", t.getTags());
+ assertType(List.class, t.getTags());
+
+ t.addTags(null);
+ assertObjectEquals("['foo','bar']", t.getTags());
+ assertType(List.class, t.getTags());
+ }
+
+ /**
+ * Test method for {@link Operation#tags(java.lang.Object[])}.
+ */
+ @Test
+ public void testTags() {
+ Operation t = new Operation();
+
+ t.tags(new ASet<String>().appendAll("a"));
+ t.tags(new ASet<Object>().appendAll(new StringBuilder("b")));
+ t.tags((Object)new String[] {"c"});
+ t.tags((Object)new Object[] {new StringBuilder("d")});
+ t.tags("e");
+ t.tags("['f']");
+ t.tags("[]");
+ t.tags((Object)null);
+ assertObjectEquals("['a','b','c','d','e','f']", t.getTags());
+ for (String s : t.getTags())
+ assertType(String.class, s);
+ }
+
+ /**
+ * Test method for {@link Operation#summary(java.lang.Object)}.
+ */
+ @Test
+ public void testSummary() {
+ Operation t = new Operation();
+
+ t.summary("foo");
+ assertEquals("foo", t.getSummary());
+
+ t.summary(new StringBuilder("foo"));
+ assertEquals("foo", t.getSummary());
+ assertType(String.class, t.getSummary());
+
+ t.summary(null);
+ assertNull(t.getSummary());
+ }
+
+ /**
+ * Test method for {@link Operation#description(java.lang.Object)}.
+ */
+ @Test
+ public void testDescription() {
+ Operation t = new Operation();
+
+ t.description("foo");
+ assertEquals("foo", t.getDescription());
+
+ t.description(new StringBuilder("foo"));
+ assertEquals("foo", t.getDescription());
+ assertType(String.class, t.getDescription());
+
+ t.description(null);
+ assertNull(t.getDescription());
+ }
+
+ /**
+ * Test method for {@link Operation#externalDocs(java.lang.Object)}.
+ */
+ @Test
+ public void testExternalDocs() {
+ Operation t = new Operation();
+
+ t.externalDocs(externalDocumentation("foo"));
+ assertObjectEquals("{url:'foo'}", t.getExternalDocs());
+
+ t.externalDocs("{url:'foo'}");
+ assertObjectEquals("{url:'foo'}", t.getExternalDocs());
+ assertType(ExternalDocumentation.class, t.getExternalDocs());
+
+ t.externalDocs(null);
+ assertNull(t.getExternalDocs());
+ }
+
+ /**
+ * Test method for {@link Operation#operationId(java.lang.Object)}.
+ */
+ @Test
+ public void testOperationId() {
+ Operation t = new Operation();
+
+ t.operationId("foo");
+ assertEquals("foo", t.getOperationId());
+
+ t.operationId(new StringBuilder("foo"));
+ assertEquals("foo", t.getOperationId());
+ assertType(String.class, t.getOperationId());
+
+ t.operationId(null);
+ assertNull(t.getOperationId());
+ }
+
+ /**
+ * Test method for {@link Operation#setConsumes(java.util.Collection)}.
+ */
+ @Test
+ public void testSetConsumes() {
+ Operation t = new Operation();
+
+ t.setConsumes(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ assertObjectEquals("['text/foo']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+
+ t.setConsumes(new ASet<MediaType>());
+ assertObjectEquals("[]", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+
+ t.setConsumes(null);
+ assertNull(t.getConsumes());
+ }
+
+ /**
+ * Test method for {@link Operation#addConsumes(java.util.Collection)}.
+ */
+ @Test
+ public void testAddConsumes() {
+ Operation t = new Operation();
+
+ t.addConsumes(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ assertObjectEquals("['text/foo']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+
+ t.addConsumes(new ASet<MediaType>());
+ assertObjectEquals("['text/foo']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+
+ t.addConsumes(null);
+ assertObjectEquals("['text/foo']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+ }
+
+ /**
+ * Test method for {@link Operation#consumes(java.lang.Object[])}.
+ */
+ @Test
+ public void testConsumes() {
+ Operation t = new Operation();
+
+ t.consumes(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ t.consumes(MediaType.forString("text/bar"));
+ t.consumes("text/baz");
+ t.consumes(new StringBuilder("text/qux"));
+ t.consumes((Object)new String[]{"text/quux"});
+ t.consumes((Object)new ASet<String>().append("text/quuux"));
+ t.consumes("['text/quuuux']");
+ t.consumes("[]");
+ t.consumes((Object)null);
+ assertObjectEquals("['text/foo','text/bar','text/baz','text/qux','text/quux','text/quuux','text/quuuux']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+ for (MediaType mt : t.getConsumes())
+ assertType(MediaType.class, mt);
+ }
+
+ /**
+ * Test method for {@link Operation#setProduces(java.util.Collection)}.
+ */
+ @Test
+ public void testSetProduces() {
+ Operation t = new Operation();
+
+ t.setProduces(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ assertObjectEquals("['text/foo']", t.getProduces());
+ assertType(List.class, t.getProduces());
+
+ t.setProduces(new ASet<MediaType>());
+ assertObjectEquals("[]", t.getProduces());
+ assertType(List.class, t.getProduces());
+
+ t.setProduces(null);
+ assertNull(t.getProduces());
+ }
+
+ /**
+ * Test method for {@link Operation#addProduces(java.util.Collection)}.
+ */
+ @Test
+ public void testAddProduces() {
+ Operation t = new Operation();
+
+ t.addProduces(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ assertObjectEquals("['text/foo']", t.getProduces());
+ assertType(List.class, t.getProduces());
+
+ t.addProduces(new ASet<MediaType>());
+ assertObjectEquals("['text/foo']", t.getProduces());
+ assertType(List.class, t.getProduces());
+
+ t.addProduces(null);
+ assertObjectEquals("['text/foo']", t.getProduces());
+ assertType(List.class, t.getProduces());
+ }
+
+ /**
+ * Test method for {@link Operation#produces(java.lang.Object[])}.
+ */
+ @Test
+ public void testProduces() {
+ Operation t = new Operation();
+
+ t.produces(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ t.produces(MediaType.forString("text/bar"));
+ t.produces("text/baz");
+ t.produces(new StringBuilder("text/qux"));
+ t.produces((Object)new String[]{"text/quux"});
+ t.produces((Object)new ASet<String>().append("text/quuux"));
+ t.produces("['text/quuuux']");
+ t.produces("[]");
+ t.produces((Object)null);
+ assertObjectEquals("['text/foo','text/bar','text/baz','text/qux','text/quux','text/quuux','text/quuuux']", t.getProduces());
+ assertType(List.class, t.getProduces());
+ for (MediaType mt : t.getProduces())
+ assertType(MediaType.class, mt);
+ }
+
+ /**
+ * Test method for {@link Operation#setParameters(java.util.Collection)}.
+ */
+ @Test
+ public void testSetParameters() {
+ Operation t = new Operation();
+
+ t.setParameters(new ASet<ParameterInfo>().appendAll(parameterInfo("foo","bar")));
+ assertObjectEquals("[{'in':'foo',name:'bar'}]", t.getParameters());
+ assertType(List.class, t.getParameters());
+
+ t.setParameters(new ASet<ParameterInfo>());
+ assertObjectEquals("[]", t.getParameters());
+ assertType(List.class, t.getParameters());
+
+ t.setParameters(null);
+ assertNull(t.getParameters());
+ }
+
+ /**
+ * Test method for {@link Operation#addParameters(java.util.Collection)}.
+ */
+ @Test
+ public void testAddParameters() {
+ Operation t = new Operation();
+
+ t.addParameters(new ASet<ParameterInfo>().appendAll(parameterInfo("foo","bar")));
+ assertObjectEquals("[{'in':'foo',name:'bar'}]", t.getParameters());
+ assertType(List.class, t.getParameters());
+
+ t.addParameters(new ASet<ParameterInfo>());
+ assertObjectEquals("[{'in':'foo',name:'bar'}]", t.getParameters());
+ assertType(List.class, t.getParameters());
+
+ t.addParameters(null);
+ assertObjectEquals("[{'in':'foo',name:'bar'}]", t.getParameters());
+ assertType(List.class, t.getParameters());
+ }
+
+ /**
+ * Test method for {@link Operation#parameters(java.lang.Object[])}.
+ */
+ @Test
+ public void testParameters() {
+ Operation t = new Operation();
+
+ t.parameters(new ASet<ParameterInfo>().appendAll(parameterInfo("a1","a2")));
+ t.parameters(parameterInfo("b1","b2"));
+ t.parameters("{in:'c1',name:'c2'}");
+ t.parameters(new StringBuilder("{in:'d1',name:'d2'}"));
+ t.parameters((Object)new String[]{"{in:'e1',name:'e2'}"});
+ t.parameters((Object)new ASet<String>().append("{in:'f1',name:'f2'}"));
+ t.parameters("[{in:'g1',name:'g2'}]");
+ t.parameters("[]");
+ t.parameters((Object)null);
+ assertObjectEquals("[{'in':'a1',name:'a2'},{'in':'b1',name:'b2'},{'in':'c1',name:'c2'},{'in':'d1',name:'d2'},{'in':'e1',name:'e2'},{'in':'f1',name:'f2'},{'in':'g1',name:'g2'}]", t.getParameters());
+ assertType(List.class, t.getParameters());
+ for (ParameterInfo pi : t.getParameters())
+ assertType(ParameterInfo.class, pi);
+ }
+
+ /**
+ * Test method for {@link Operation#setResponses(java.util.Map)}.
+ */
+ @Test
+ public void testSetResponses() {
+ Operation t = new Operation();
+
+ t.setResponses(new AMap<Integer,ResponseInfo>().append(123,responseInfo("bar")));
+ assertObjectEquals("{'123':{description:'bar'}}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+
+ t.setResponses(new AMap<Integer,ResponseInfo>());
+ assertObjectEquals("{}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+
+ t.setResponses(null);
+ assertNull(t.getResponses());
+ }
+
+ /**
+ * Test method for {@link Operation#addResponses(java.util.Map)}.
+ */
+ @Test
+ public void testAddResponses() {
+ Operation t = new Operation();
+
+ t.addResponses(new AMap<Integer,ResponseInfo>().append(123,responseInfo("bar")));
+ assertObjectEquals("{'123':{description:'bar'}}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+
+ t.addResponses(new AMap<Integer,ResponseInfo>());
+ assertObjectEquals("{'123':{description:'bar'}}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+
+ t.addResponses(null);
+ assertObjectEquals("{'123':{description:'bar'}}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+ }
+
+ /**
+ * Test method for {@link Operation#response(java.lang.Integer, org.apache.juneau.dto.swagger.ResponseInfo)}.
+ */
+ @Test
+ public void testResponse() {
+ Operation t = new Operation();
+
+ t.response(1, responseInfo("foo"));
+ t.response(null, responseInfo("bar"));
+ t.response(2, null);
+ assertObjectEquals("{'1':{description:'foo'},null:{description:'bar'},'2':null}", t.getResponses());
+ }
+
+ /**
+ * Test method for {@link Operation#responses(java.lang.Object[])}.
+ */
+ @Test
+ public void testResponses() {
+ Operation t = new Operation();
+
+ t.responses(new AMap<Integer,ResponseInfo>().append(1,responseInfo("a")));
+ t.responses(new AMap<String,String>().append("2","{description:'b'}"));
+ t.responses("{3:{description:'c'}}");
+ t.responses("{}");
+ t.responses((Object)null);
+
+ assertObjectEquals("{'1':{description:'a'},'2':{description:'b'},'3':{description:'c'}}", t.getResponses());
+ for (Map.Entry<Integer,ResponseInfo> e : t.getResponses().entrySet()) {
+ assertType(Integer.class, e.getKey());
+ assertType(ResponseInfo.class, e.getValue());
+ }
+ }
+
+ /**
+ * Test method for {@link Operation#setSchemes(java.util.Collection)}.
+ */
+ @Test
+ public void testSetSchemes() {
+ Operation t = new Operation();
+
+ t.setSchemes(new ASet<String>().appendAll("foo"));
+ assertObjectEquals("['foo']", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+
+ t.setSchemes(new ASet<String>());
+ assertObjectEquals("[]", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+
+ t.setSchemes(null);
+ assertNull(t.getSchemes());
+ }
+
+ /**
+ * Test method for {@link Operation#setSecurity(java.util.Collection)}.
+ */
+ @Test
+ public void testSetSecurity() {
+ Operation t = new Operation();
+
+ t.setSecurity(new ASet<Map<String, List<String>>>().append(new AMap<String,List<String>>().append("foo",new AList<String>().append("bar"))));
+ assertObjectEquals("[{foo:['bar']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+
+ t.setSecurity(new ASet<Map<String, List<String>>>());
+ assertObjectEquals("[]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+
+ t.setSecurity(null);
+ assertNull(t.getSecurity());
+ }
+
+ /**
+ * Test method for {@link Operation#addSchemes(java.util.Collection)}.
+ */
+ @Test
+ public void testAddSchemes() {
+ Operation t = new Operation();
+
+ t.addSchemes(new ASet<String>().appendAll("foo"));
+ assertObjectEquals("['foo']", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+
+ t.addSchemes(new ASet<String>());
+ assertObjectEquals("['foo']", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+
+ t.addSchemes(null);
+ assertObjectEquals("['foo']", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+ }
+
+ /**
+ * Test method for {@link Operation#schemes(java.lang.Object[])}.
+ */
+ @Test
+ public void testSchemes() {
+ Operation t = new Operation();
+
+ t.schemes(new ASet<String>().appendAll("a"));
+ t.schemes(new ASet<Object>().appendAll(new StringBuilder("b")));
+ t.schemes((Object)new String[] {"c"});
+ t.schemes((Object)new Object[] {new StringBuilder("d")});
+ t.schemes("e");
+ t.schemes("['f']");
+ t.schemes("[]");
+ t.schemes((Object)null);
+ assertObjectEquals("['a','b','c','d','e','f']", t.getSchemes());
+ for (String s : t.getSchemes())
+ assertType(String.class, s);
+ }
+
+ /**
+ * Test method for {@link Operation#deprecated(java.lang.Object)}.
+ */
+ @Test
+ public void testDeprecated() {
+ Operation t = new Operation();
+
+ t.deprecated(true);
+ assertEquals(true, t.getDeprecated());
+ assertType(Boolean.class, t.getDeprecated());
+
+ t.deprecated("true");
+ assertEquals(true, t.getDeprecated());
+ assertType(Boolean.class, t.getDeprecated());
+
+ t.deprecated(new StringBuilder("true"));
+ assertEquals(true, t.getDeprecated());
+ assertType(Boolean.class, t.getDeprecated());
+
+ t.deprecated(null);
+ assertNull(t.getDeprecated());
+ }
+
+ /**
+ * Test method for {@link Operation#addSecurity(java.util.List)}.
+ */
+ @Test
+ public void testAddSecurity() {
+ Operation t = new Operation();
+
+ t.addSecurity(new ASet<Map<String, List<String>>>().append(new AMap<String,List<String>>().append("foo",new AList<String>().append("bar"))));
+ assertObjectEquals("[{foo:['bar']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+
+ t.addSecurity(new ASet<Map<String, List<String>>>());
+ assertObjectEquals("[{foo:['bar']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+
+ t.addSecurity(null);
+ assertObjectEquals("[{foo:['bar']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+ }
+
+ /**
+ * Test method for {@link Operation#security(java.lang.String, java.lang.String[])}.
+ */
+ @Test
+ public void testSecurity() {
+ Operation t = new Operation();
+
+ t.security("a", "a1", "a2");
+ t.security("b");
+ t.security("c", (String)null);
+ t.security(null, "d");
+
+ assertObjectEquals("[{a:['a1','a2']},{b:[]},{c:[null]},{null:['d']}]", t.getSecurity());
+ }
+
+ /**
+ * Test method for {@link Operation#securities(java.lang.Object[])}.
+ */
+ @Test
+ public void testSecurities() {
+ Operation t = new Operation();
+
+ t.securities(new ASet<Map<String,List<String>>>().append(new AMap<String,List<String>>().append("a1",new AList<String>().append("a2"))));
+ t.securities(new AMap<String,List<String>>().append("b1",new AList<String>().append("b2")));
+ t.securities("{c1:['c2']}");
+ t.securities(new StringBuilder("{d1:['d2']}"));
+ t.securities((Object)new String[]{"{e1:['e2']}"});
+ t.securities((Object)new ASet<String>().append("{f1:['f2']}"));
+ t.securities("[{g1:['g2']}]");
+ t.securities("[]");
+ t.securities((Object)null);
+ assertObjectEquals("[{a1:['a2']},{b1:['b2']},{c1:['c2']},{d1:['d2']},{e1:['e2']},{f1:['f2']},{g1:['g2']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+ }
+
+ /**
+ * Test method for {@link Operation#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ Operation t = new Operation();
+
+ t
+ .set("consumes", new ASet<MediaType>().appendAll(MediaType.forString("text/a")))
+ .set("deprecated", true)
+ .set("description", "b")
+ .set("externalDocs", externalDocumentation("c"))
+ .set("operationId", "d")
+ .set("parameters", new ASet<ParameterInfo>().appendAll(parameterInfo("e1","e2")))
+ .set("produces", new ASet<MediaType>().appendAll(MediaType.forString("text/f")))
+ .set("responses", new AMap<Integer,ResponseInfo>().append(1,responseInfo("g")))
+ .set("schemes", new ASet<String>().appendAll("h"))
+ .set("security", new ASet<Map<String,List<String>>>().append(new AMap<String,List<String>>().append("i1",new AList<String>().append("i2"))))
+ .set("summary", "j")
+ .set("tags", new ASet<String>().appendAll("k"))
+ .set("$ref", "ref");
+
+ assertObjectEquals("{operationId:'d',summary:'j',description:'b',tags:['k'],externalDocs:{url:'c'},consumes:['text/a'],produces:['text/f'],parameters:[{'in':'e1',name:'e2'}],responses:{'1':{description:'g'}},schemes:['h'],deprecated:true,security:[{i1:['i2']}],'$ref':'ref'}", t);
+
+ t
+ .set("consumes", "['text/a']")
+ .set("deprecated", "true")
+ .set("description", "b")
+ .set("externalDocs", "{url:'c'}")
+ .set("operationId", "d")
+ .set("parameters", "[{'in':'e1',name:'e2'}]")
+ .set("produces", "['text/f']")
+ .set("responses", "{'1':{description:'g'}}")
+ .set("schemes", "['h']")
+ .set("security", "[{i1:['i2']}]")
+ .set("summary", "j")
+ .set("tags", "['k']")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{operationId:'d',summary:'j',description:'b',tags:['k'],externalDocs:{url:'c'},consumes:['text/a'],produces:['text/f'],parameters:[{'in':'e1',name:'e2'}],responses:{'1':{description:'g'}},schemes:['h'],deprecated:true,security:[{i1:['i2']}],'$ref':'ref'}", t);
+
+ t
+ .set("consumes", new StringBuilder("['text/a']"))
+ .set("deprecated", new StringBuilder("true"))
+ .set("description", new StringBuilder("b"))
+ .set("externalDocs", new StringBuilder("{url:'c'}"))
+ .set("operationId", new StringBuilder("d"))
+ .set("parameters", new StringBuilder("[{'in':'e1',name:'e2'}]"))
+ .set("produces", new StringBuilder("['text/f']"))
+ .set("responses", new StringBuilder("{'1':{description:'g'}}"))
+ .set("schemes", new StringBuilder("['h']"))
+ .set("security", new StringBuilder("[{i1:['i2']}]"))
+ .set("summary", new StringBuilder("j"))
+ .set("tags", new StringBuilder("['k']"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{operationId:'d',summary:'j',description:'b',tags:['k'],externalDocs:{url:'c'},consumes:['text/a'],produces:['text/f'],parameters:[{'in':'e1',name:'e2'}],responses:{'1':{description:'g'}},schemes:['h'],deprecated:true,security:[{i1:['i2']}],'$ref':'ref'}", t);
+
+ assertEquals("['text/a']", t.get("consumes", String.class));
+ assertEquals("true", t.get("deprecated", String.class));
+ assertEquals("b", t.get("description", String.class));
+ assertEquals("{url:'c'}", t.get("externalDocs", String.class));
+ assertEquals("d", t.get("operationId", String.class));
+ assertEquals("[{'in':'e1',name:'e2'}]", t.get("parameters", String.class));
+ assertEquals("['text/f']", t.get("produces", String.class));
+ assertEquals("{'1':{description:'g'}}", t.get("responses", String.class));
+ assertEquals("['h']", t.get("schemes", String.class));
+ assertEquals("[{i1:['i2']}]", t.get("security", String.class));
+ assertEquals("j", t.get("summary", String.class));
+ assertEquals("['k']", t.get("tags", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(List.class, t.get("consumes", Object.class));
+ assertType(MediaType.class, t.get("consumes", List.class).get(0));
+ assertType(Boolean.class, t.get("deprecated", Object.class));
+ assertType(String.class, t.get("description", Object.class));
+ assertType(ExternalDocumentation.class, t.get("externalDocs", Object.class));
+ assertType(String.class, t.get("operationId", Object.class));
+ assertType(List.class, t.get("parameters", Object.class));
+ assertType(ParameterInfo.class, t.get("parameters", List.class).get(0));
+ assertType(List.class, t.get("produces", Object.class));
+ assertType(MediaType.class, t.get("produces", List.class).get(0));
+ assertType(Map.class, t.get("responses", Object.class));
+ assertType(Integer.class, t.get("responses", Map.class).keySet().iterator().next());
+ assertType(ResponseInfo.class, t.get("responses", Map.class).values().iterator().next());
+ assertType(List.class, t.get("schemes", Object.class));
+ assertType(List.class, t.get("security", Object.class));
+ assertType(String.class, t.get("summary", Object.class));
+ assertType(List.class, t.get("tags", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{operationId:'d',summary:'j',description:'b',tags:['k'],externalDocs:{url:'c'},consumes:['text/a'],produces:['text/f'],parameters:[{'in':'e1',name:'e2'}],responses:{'1':{description:'g'}},schemes:['h'],deprecated:true,security:[{i1:['i2']}],'$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, Operation.class));
+ }
+}
[04/10] juneau git commit: JUNEAU-78
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
index 01055c1..3129f8d 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import static org.apache.juneau.internal.ArrayUtils.*;
import java.util.*;
@@ -27,7 +28,7 @@ import org.apache.juneau.annotation.*;
*
* <p>
* There are five possible parameter types.
- * <ul>
+ * <ul class='spaced-list'>
* <li><js>"path"</js> - Used together with Path Templating, where the parameter value is actually part of the
* operation's URL.
* This does not include the host or base path of the API.
@@ -63,51 +64,64 @@ import org.apache.juneau.annotation.*;
* </li>
* </ul>
*
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * ParameterInfo x = <jsm>parameterInfo</jsm>(<js>"query"</js>, <js>"foo"</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'>
+ * <jc>// Output</jc>
+ * {
+ * <js>"in"</js>: <js>"query"</js>,
+ * <js>"name"</js>: <js>"foo"</js>
+ * }
+ * </p>
+ *
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="in,name,type,description,required,schema,format,allowEmptyValue,items,collectionFormat,default,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,enum,multipleOf")
+@Bean(properties="in,name,type,description,required,schema,format,allowEmptyValue,items,collectionFormat,default,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,enum,multipleOf,*")
public class ParameterInfo extends SwaggerElement {
private static final String[] VALID_IN = {"query", "header", "path", "formData", "body"};
private static final String[] VALID_TYPES = {"string", "number", "integer", "boolean", "array", "file"};
private static final String[] VALID_COLLECTION_FORMATS = {"csv", "ssv", "tsv", "pipes", "multi"};
- private String name;
- private String in;
- private String description;
- private Boolean required;
+ private String
+ name,
+ in,
+ description,
+ type,
+ format,
+ pattern,
+ collectionFormat;
+ private Number
+ maximum,
+ minimum,
+ multipleOf;
+ private Integer
+ maxLength,
+ minLength,
+ maxItems,
+ minItems;
+ private Boolean
+ required,
+ allowEmptyValue,
+ exclusiveMaximum,
+ exclusiveMinimum,
+ uniqueItems;
private SchemaInfo schema;
- private String type;
- private String format;
- private Boolean allowEmptyValue;
private Items items;
- private String collectionFormat;
private Object _default;
- private Number maximum;
- private Boolean exclusiveMaximum;
- private Number minimum;
- private Boolean exclusiveMinimum;
- private Integer maxLength;
- private Integer minLength;
- private String pattern;
- private Integer maxItems;
- private Integer minItems;
- private Boolean uniqueItems;
private List<Object> _enum;
- private Number multipleOf;
@Override /* SwaggerElement */
protected ParameterInfo strict() {
@@ -119,18 +133,22 @@ public class ParameterInfo extends SwaggerElement {
* Bean property getter: <property>name</property>.
*
* <p>
- * Required. The name of the parameter.
+ * The name of the parameter.
*
- * <p>
- * Parameter names are case sensitive.
- * If <code>in</code> is <js>"path"</js>, the <code>name</code> field MUST correspond to the associated path segment
- * from the <code>path</code> field in the <a class="doclink"
- * href="http://swagger.io/specification/#pathsObject">Paths Object</a>.
- * See <a class="doclink" href="http://swagger.io/specification/#pathTemplating">Path Templating</a> for further
- * information.
- * For all other cases, the name corresponds to the parameter name used based on the <code>in</code> property.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li>Parameter names are case sensitive.
+ * <li>If <code>in</code> is <js>"path"</js>, the <code>name</code> field MUST correspond to the associated path segment
+ * from the <code>path</code> field in the <a class="doclink" href="http://swagger.io/specification/#pathsObject">Paths Object</a>.
+ * <li>For all other cases, the name corresponds to the parameter name used based on the <code>in</code> property.
+ * </ul>
*
- * @return The value of the <property>name</property> property on this bean, or <jk>null</jk> if it is not set.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#pathTemplating">Path Templating</a>
+ * </ul>
+ *
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getName() {
return name;
@@ -140,46 +158,52 @@ public class ParameterInfo extends SwaggerElement {
* Bean property setter: <property>name</property>.
*
* <p>
- * Required. The name of the parameter.
+ * The name of the parameter.
*
- * <p>
- * Parameter names are case sensitive.
- * If <code>in</code> is <js>"path"</js>, the <code>name</code> field MUST correspond to the associated path segment
- * from the <code>path</code> field in the <a class="doclink"
- * href="http://swagger.io/specification/#pathsObject">Paths Object</a>.
- * See <a class="doclink" href="http://swagger.io/specification/#pathTemplating">Path Templating</a> for further
- * information.
- * For all other cases, the name corresponds to the parameter name used based on the <code>in</code> property.
- *
- * @param name The new value for the <property>name</property> property on this bean.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li>Parameter names are case sensitive.
+ * <li>If <code>in</code> is <js>"path"</js>, the <code>name</code> field MUST correspond to the associated path segment
+ * from the <code>path</code> field in the <a class="doclink" href="http://swagger.io/specification/#pathsObject">Paths Object</a>.
+ * <li>For all other cases, the name corresponds to the parameter name used based on the <code>in</code> property.
+ * </ul>
+ *
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#pathTemplating">Path Templating</a>
+ * </ul>
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public ParameterInfo setName(String name) {
+ public ParameterInfo setName(String value) {
if (! "body".equals(in))
- this.name = name;
+ name = value;
return this;
}
/**
- * Synonym for {@link #setName(String)}.
+ * Same as {@link #setName(String)}.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo name(String name) {
- return setName(name);
+ public ParameterInfo name(Object value) {
+ return setName(toStringVal(value));
}
/**
* Bean property getter: <property>in</property>.
*
* <p>
- * Required. The location of the parameter.
- *
- * <p>
- * Possible values are <js>"query"</js>, <js>"header"</js>, <js>"path"</js>, <js>"formData"</js> or <js>"body"</js>.
+ * The location of the parameter.
*
- * @return The value of the <property>in</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getIn() {
return in;
@@ -189,34 +213,52 @@ public class ParameterInfo extends SwaggerElement {
* Bean property setter: <property>in</property>.
*
* <p>
- * Required. The location of the parameter.
- *
- * <p>
- * Possible values are <js>"query"</js>, <js>"header"</js>, <js>"path"</js>, <js>"formData"</js> or <js>"body"</js>.
+ * The location of the parameter.
*
- * @param in The new value for the <property>in</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"query"</js>
+ * <li><js>"header"</js>
+ * <li><js>"path"</js>
+ * <li><js>"formData"</js>
+ * <li><js>"body"</js>
+ * </ul>
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public ParameterInfo setIn(String in) {
- if (isStrict() && ! contains(in, VALID_IN))
+ public ParameterInfo setIn(String value) {
+ if (isStrict() && ! contains(value, VALID_IN))
throw new FormattedRuntimeException(
"Invalid value passed in to setIn(String). Value=''{0}'', valid values={1}",
- in, VALID_IN
+ value, VALID_IN
);
- this.in = in;
- if ("path".equals(in))
+ in = value;
+ if ("path".equals(value))
required = true;
return this;
}
/**
- * Synonym for {@link #setIn(String)}.
+ * Same as {@link #setIn(String)}.
*
- * @param in The new value for the <property>in</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"query"</js>
+ * <li><js>"header"</js>
+ * <li><js>"path"</js>
+ * <li><js>"formData"</js>
+ * <li><js>"body"</js>
+ * </ul>
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public ParameterInfo in(String in) {
- return setIn(in);
+ public ParameterInfo in(Object value) {
+ return setIn(toStringVal(value));
}
/**
@@ -224,14 +266,9 @@ public class ParameterInfo extends SwaggerElement {
*
* <p>
* A brief description of the parameter.
+ * <br>This could contain examples of use.
*
- * <p>
- * This could contain examples of use.
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used
- * for rich text representation.
- *
- * @return
- * The value of the <property>description</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDescription() {
return description;
@@ -242,28 +279,31 @@ public class ParameterInfo extends SwaggerElement {
*
* <p>
* A brief description of the parameter.
+ * <br>This could contain examples of use.
*
- * <p>
- * This could contain examples of use.
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used
- * for rich text representation.
- *
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo setDescription(String description) {
- this.description = description;
+ public ParameterInfo setDescription(String value) {
+ description = value;
return this;
}
/**
- * Synonym for {@link #setDescription(String)}.
+ * Same as {@link #setDescription(String)}.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo description(String description) {
- return setDescription(description);
+ public ParameterInfo description(Object value) {
+ return setDescription(toStringVal(value));
}
/**
@@ -272,12 +312,7 @@ public class ParameterInfo extends SwaggerElement {
* <p>
* Determines whether this parameter is mandatory.
*
- * <p>
- * If the parameter is <code>in</code> <js>"path"</js>, this property is required and its value MUST be
- * <jk>true</jk>.
- * Otherwise, the property MAY be included and its default value is <jk>false</jk>.
- *
- * @return The value of the <property>required</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getRequired() {
return required;
@@ -290,35 +325,41 @@ public class ParameterInfo extends SwaggerElement {
* Determines whether this parameter is mandatory.
*
* <p>
- * If the parameter is <code>in</code> <js>"path"</js>, this property is required and its value MUST be
- * <jk>true</jk>.
- * Otherwise, the property MAY be included and its default value is <jk>false</jk>.
*
- * @param required The new value for the <property>required</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>If the parameter is <code>in</code> <js>"path"</js>, this property is required and its value MUST be <jk>true</jk>.
+ * <br>Otherwise, the property MAY be included and its default value is <jk>false</jk>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo setRequired(Boolean required) {
- this.required = required;
+ public ParameterInfo setRequired(Boolean value) {
+ required = value;
return this;
}
/**
- * Synonym for {@link #setRequired(Boolean)}.
+ * Same as {@link #setRequired(Boolean)}.
*
- * @param required The new value for the <property>required</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>If the parameter is <code>in</code> <js>"path"</js>, this property is required and its value MUST be <jk>true</jk>.
+ * <br>Otherwise, the property MAY be included and its default value is <jk>false</jk>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo required(Boolean required) {
- return setRequired(required);
+ public ParameterInfo required(Object value) {
+ return setRequired(toBoolean(value));
}
/**
* Bean property getter: <property>schema</property>.
*
* <p>
- * Required. The schema defining the type used for the body parameter.
+ * The schema defining the type used for the body parameter.
*
- * @return The value of the <property>schema</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public SchemaInfo getSchema() {
return schema;
@@ -328,41 +369,46 @@ public class ParameterInfo extends SwaggerElement {
* Bean property setter: <property>schema</property>.
*
* <p>
- * Required. The schema defining the type used for the body parameter.
+ * The schema defining the type used for the body parameter.
*
- * @param schema The new value for the <property>schema</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public ParameterInfo setSchema(SchemaInfo schema) {
- this.schema = schema;
+ public ParameterInfo setSchema(SchemaInfo value) {
+ schema = value;
return this;
}
/**
- * Synonym for {@link #setSchema(SchemaInfo)}.
+ * Same as {@link #setSchema(SchemaInfo)}.
*
- * @param schema The new value for the <property>schema</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link SchemaInfo}
+ * <li><code>String</code> - JSON object representation of {@link SchemaInfo}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * schema(<js>"{type:'type',description:'description',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public ParameterInfo schema(SchemaInfo schema) {
- return setSchema(schema);
+ public ParameterInfo schema(Object value) {
+ return setSchema(toType(value, SchemaInfo.class));
}
/**
* Bean property getter: <property>type</property>.
*
* <p>
- * Required. The type of the parameter.
- *
- * <p>
- * Since the parameter is not located at the request body, it is limited to simple types (that is, not an object).
- * The value MUST be one of <js>"string"</js>, <js>"number"</js>, <js>"integer"</js>, <js>"boolean"</js>,
- * <js>"array"</js> or <js>"file"</js>.
- * If type is <js>"file"</js>, the <code>consumes</code> MUST be either <js>"multipart/form-data"</js>,
- * <js>"application/x-www-form-urlencoded"</js> or both and the parameter MUST be <code>in</code>
- * <js>"formData"</js>.
+ * The type of the parameter.
*
- * @return The value of the <property>type</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getType() {
return type;
@@ -372,37 +418,57 @@ public class ParameterInfo extends SwaggerElement {
* Bean property setter: <property>type</property>.
*
* <p>
- * Required. The type of the parameter.
+ * The type of the parameter.
*
- * <p>
- * Since the parameter is not located at the request body, it is limited to simple types (that is, not an object).
- * The value MUST be one of <js>"string"</js>, <js>"number"</js>, <js>"integer"</js>, <js>"boolean"</js>,
- * <js>"array"</js> or <js>"file"</js>.
- * If type is <js>"file"</js>, the <code>consumes</code> MUST be either <js>"multipart/form-data"</js>,
- * <js>"application/x-www-form-urlencoded"</js> or both and the parameter MUST be <code>in</code>
- * <js>"formData"</js>.
- *
- * @param type The new value for the <property>type</property> property on this bean.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"string"</js>
+ * <li><js>"number"</js>
+ * <li><js>"integer"</js>
+ * <li><js>"boolean"</js>
+ * <li><js>"array"</js>
+ * <li><js>"file"</js>
+ * </ul>
+ * <br>If type is <js>"file"</js>, the <code>consumes</code> MUST be either <js>"multipart/form-data"</js>, <js>"application/x-www-form-urlencoded"</js>
+ * or both and the parameter MUST be <code>in</code> <js>"formData"</js>.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public ParameterInfo setType(String type) {
- if (isStrict() && ! contains(type, VALID_TYPES))
+ public ParameterInfo setType(String value) {
+ if (isStrict() && ! contains(value, VALID_TYPES))
throw new FormattedRuntimeException(
"Invalid value passed in to setType(String). Value=''{0}'', valid values={1}",
- type, VALID_TYPES
+ value, VALID_TYPES
);
- this.type = type;
+ type = value;
return this;
}
/**
- * Synonym for {@link #setType(String)}.
- *
- * @param type The new value for the <property>type</property> property on this bean.
+ * Same as {@link #setType(String)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"string"</js>
+ * <li><js>"number"</js>
+ * <li><js>"integer"</js>
+ * <li><js>"boolean"</js>
+ * <li><js>"array"</js>
+ * <li><js>"file"</js>
+ * </ul>
+ * <br>If type is <js>"file"</js>, the <code>consumes</code> MUST be either <js>"multipart/form-data"</js>, <js>"application/x-www-form-urlencoded"</js>
+ * or both and the parameter MUST be <code>in</code> <js>"formData"</js>.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public ParameterInfo type(String type) {
- return setType(type);
+ public ParameterInfo type(Object value) {
+ return setType(toStringVal(value));
}
/**
@@ -411,11 +477,12 @@ public class ParameterInfo extends SwaggerElement {
* <p>
* The extending format for the previously mentioned type.
*
- * <p>
- * See <a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a> for further
- * details.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a>
+ * </ul>
*
- * @return The value of the <property>format</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getFormat() {
return format;
@@ -427,26 +494,30 @@ public class ParameterInfo extends SwaggerElement {
* <p>
* The extending format for the previously mentioned type.
*
- * <p>
- * See <a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a> for further
- * details.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a>
+ * </ul>
*
- * @param format The new value for the <property>format</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setFormat(String format) {
- this.format = format;
+ public ParameterInfo setFormat(String value) {
+ format = value;
return this;
}
/**
- * Synonym for {@link #setFormat(String)}.
+ * Same as {@link #setFormat(String)}.
*
- * @param format The new value for the <property>format</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo format(String format) {
- return setFormat(format);
+ public ParameterInfo format(Object value) {
+ return setFormat(toStringVal(value));
}
/**
@@ -458,10 +529,8 @@ public class ParameterInfo extends SwaggerElement {
* <p>
* This is valid only for either <code>query</code> or <code>formData</code> parameters and allows you to send a
* parameter with a name only or an empty value.
- * Default value is <jk>false</jk>.
*
- * @return The value of the <property>allowEmptyValue</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getAllowEmptyValue() {
return allowEmptyValue;
@@ -476,36 +545,39 @@ public class ParameterInfo extends SwaggerElement {
* <p>
* This is valid only for either <code>query</code> or <code>formData</code> parameters and allows you to send a
* parameter with a name only or an empty value.
- * Default value is <jk>false</jk>.
*
- * @param allowEmptyValue The new value for the <property>allowEmptyValue</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Can be <jk>null</jk> to unset the property.
+ * <br>Default is <jk>false</jk>.
* @return This object (for method chaining).
*/
- public ParameterInfo setAllowEmptyValue(Boolean allowEmptyValue) {
- this.allowEmptyValue = allowEmptyValue;
+ public ParameterInfo setAllowEmptyValue(Boolean value) {
+ allowEmptyValue = value;
return this;
}
/**
- * Synonym for {@link #setAllowEmptyValue(Boolean)}.
+ * Same as {@link #setAllowEmptyValue(Boolean)}.
*
- * @param allowEmptyValue The new value for the <property>allowEmptyValue</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
+ * <br>Default is <jk>false</jk>.
* @return This object (for method chaining).
*/
- public ParameterInfo allowEmptyValue(Boolean allowEmptyValue) {
- return setAllowEmptyValue(allowEmptyValue);
+ public ParameterInfo allowEmptyValue(Object value) {
+ return setAllowEmptyValue(toBoolean(value));
}
/**
* Bean property getter: <property>items</property>.
*
* <p>
- * Required if <code>type</code> is <js>"array"</js>.
- *
- * <p>
* Describes the type of items in the array.
*
- * @return The value of the <property>items</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Items getItems() {
return items;
@@ -515,27 +587,39 @@ public class ParameterInfo extends SwaggerElement {
* Bean property setter: <property>items</property>.
*
* <p>
- * Required if <code>type</code> is <js>"array"</js>.
- *
- * <p>
* Describes the type of items in the array.
*
- * @param items The new value for the <property>items</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required if <code>type</code> is <js>"array"</js>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo setItems(Items items) {
- this.items = items;
+ public ParameterInfo setItems(Items value) {
+ items = value;
return this;
}
/**
- * Synonym for {@link #setItems(Items)}.
+ * Same as {@link #setItems(Items)}.
*
- * @param items The new value for the <property>items</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required if <code>type</code> is <js>"array"</js>.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link Items}
+ * <li><code>String</code> - JSON object representation of {@link Items}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * items(<js>"{type:'type',format:'format',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo items(Items items) {
- return setItems(items);
+ public ParameterInfo items(Object value) {
+ return setItems(toType(value, Items.class));
}
/**
@@ -544,24 +628,7 @@ public class ParameterInfo extends SwaggerElement {
* <p>
* Determines the format of the array if type array is used.
*
- * <p>
- * Possible values are:
- * <ul>
- * <li><code>csv</code> - comma separated values <code>foo,bar</code>.
- * <li><code>ssv</code> - space separated values <code>foo bar</code>.
- * <li><code>tsv</code> - tab separated values <code>foo\tbar</code>.
- * <li><code>pipes</code> - pipe separated values <code>foo|bar</code>.
- * <li><code>multi</code> - corresponds to multiple parameter instances instead of multiple values for a single
- * instance <code>foo=bar&foo=baz</code>.
- * This is valid only for parameters <code>in</code> <js>"query"</js> or <js>"formData"</js>.
- * </ul>
- *
- * <p>
- * Default value is <code>csv</code>.
- *
- * @return
- * The value of the <property>collectionFormat</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getCollectionFormat() {
return collectionFormat;
@@ -573,42 +640,52 @@ public class ParameterInfo extends SwaggerElement {
* <p>
* Determines the format of the array if type array is used.
*
- * <p>
- * Possible values are:
- * <ul>
- * <li><code>csv</code> - comma separated values <code>foo,bar</code>.
- * <li><code>ssv</code> - space separated values <code>foo bar</code>.
- * <li><code>tsv</code> - tab separated values <code>foo\tbar</code>.
- * <li><code>pipes</code> - pipe separated values <code>foo|bar</code>.
- * <li><code>multi</code> - corresponds to multiple parameter instances instead of multiple values for a single
- * instance <code>foo=bar&foo=baz</code>.
- * This is valid only for parameters <code>in</code> <js>"query"</js> or <js>"formData"</js>.
- * </ul>
- *
- * <p>
- * Default value is <code>csv</code>.
- *
- * @param collectionFormat The new value for the <property>collectionFormat</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"csv"</js> (default) - comma separated values <code>foo,bar</code>.
+ * <li><js>"ssv"</js> - space separated values <code>foo bar</code>.
+ * <li><js>"tsv"</js> - tab separated values <code>foo\tbar</code>.
+ * <li><js>"pipes"</js> - pipe separated values <code>foo|bar</code>.
+ * <li><js>"multi"</js> - corresponds to multiple parameter instances instead of multiple values for a single
+ * instance <code>foo=bar&foo=baz</code>.
+ * <br>This is valid only for parameters <code>in</code> <js>"query"</js> or <js>"formData"</js>.
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo setCollectionFormat(String collectionFormat) {
- if (isStrict() && ! contains(collectionFormat, VALID_COLLECTION_FORMATS))
+ public ParameterInfo setCollectionFormat(String value) {
+ if (isStrict() && ! contains(value, VALID_COLLECTION_FORMATS))
throw new FormattedRuntimeException(
"Invalid value passed in to setCollectionFormat(String). Value=''{0}'', valid values={1}",
- collectionFormat, VALID_COLLECTION_FORMATS
+ value, VALID_COLLECTION_FORMATS
);
- this.collectionFormat = collectionFormat;
+ collectionFormat = value;
return this;
}
/**
- * Synonym for {@link #setCollectionFormat(String)}.
+ * Same as {@link #setCollectionFormat(String)}.
*
- * @param collectionFormat The new value for the <property>collectionFormat</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"csv"</js> (default) - comma separated values <code>foo,bar</code>.
+ * <li><js>"ssv"</js> - space separated values <code>foo bar</code>.
+ * <li><js>"tsv"</js> - tab separated values <code>foo\tbar</code>.
+ * <li><js>"pipes"</js> - pipe separated values <code>foo|bar</code>.
+ * <li><js>"multi"</js> - corresponds to multiple parameter instances instead of multiple values for a single
+ * instance <code>foo=bar&foo=baz</code>.
+ * <br>This is valid only for parameters <code>in</code> <js>"query"</js> or <js>"formData"</js>.
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo collectionFormat(String collectionFormat) {
- return setCollectionFormat(collectionFormat);
+ public ParameterInfo collectionFormat(Object value) {
+ return setCollectionFormat(toStringVal(value));
}
/**
@@ -617,12 +694,17 @@ public class ParameterInfo extends SwaggerElement {
* <p>
* Declares the value of the parameter that the server will use if none is provided, for example a <js>"count"</js>
* to control the number of results per page might default to 100 if not supplied by the client in the request.
+ *
+ *
* (Note: <js>"default"</js> has no meaning for required parameters.)
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">
- * http://json-schema.org/latest/json-schema-validation.html#anchor101</a>.
* Unlike JSON Schema this value MUST conform to the defined <code>type</code> for this parameter.
*
- * @return The value of the <property>default</property> property on this bean, or <jk>null</jk> if it is not set.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">http://json-schema.org/latest/json-schema-validation.html#anchor101</a>
+ * </ul>
+ *
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Object getDefault() {
return _default;
@@ -635,36 +717,40 @@ public class ParameterInfo extends SwaggerElement {
* Declares the value of the parameter that the server will use if none is provided, for example a <js>"count"</js>
* to control the number of results per page might default to 100 if not supplied by the client in the request.
* (Note: <js>"default"</js> has no meaning for required parameters.)
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">
- * http://json-schema.org/latest/json-schema-validation.html#anchor101</a>.
* Unlike JSON Schema this value MUST conform to the defined <code>type</code> for this parameter.
*
- * @param _default The new value for the <property>default</property> property on this bean.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">http://json-schema.org/latest/json-schema-validation.html#anchor101</a>
+ * </ul>
+ *
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setDefault(Object _default) {
- this._default = _default;
+ public ParameterInfo setDefault(Object value) {
+ _default = value;
return this;
}
/**
- * Synonym for {@link #setDefault(Object)}.
+ * Same as {@link #setDefault(Object)}.
*
- * @param _default The new value for the <property>default</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo _default(Object _default) {
- return setDefault(_default);
+ public ParameterInfo _default(Object value) {
+ return setDefault(value);
}
/**
* Bean property getter: <property>maximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @return The value of the <property>maximum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMaximum() {
return maximum;
@@ -673,37 +759,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>maximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setMaximum(Number maximum) {
- this.maximum = maximum;
+ public ParameterInfo setMaximum(Number value) {
+ maximum = value;
return this;
}
/**
- * Synonym for {@link #setMaximum(Number)}.
+ * Same as {@link #setMaximum(Number)}.
*
- * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo maximum(Number maximum) {
- return setMaximum(maximum);
+ public ParameterInfo maximum(Object value) {
+ return setMaximum(toNumber(value));
}
/**
* Bean property getter: <property>exclusiveMaximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @return The value of the <property>exclusiveMaximum</property> property on this bean, or <jk>null</jk>
- * if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getExclusiveMaximum() {
return exclusiveMaximum;
@@ -712,36 +802,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>exclusiveMaximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setExclusiveMaximum(Boolean exclusiveMaximum) {
- this.exclusiveMaximum = exclusiveMaximum;
+ public ParameterInfo setExclusiveMaximum(Boolean value) {
+ exclusiveMaximum = value;
return this;
}
/**
- * Synonym for {@link #setExclusiveMaximum(Boolean)}.
+ * Same as {@link #setExclusiveMaximum(Boolean)}.
*
- * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo exclusiveMaximum(Boolean exclusiveMaximum) {
- return setExclusiveMaximum(exclusiveMaximum);
+ public ParameterInfo exclusiveMaximum(Object value) {
+ return setExclusiveMaximum(toBoolean(value));
}
/**
* Bean property getter: <property>minimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @return The value of the <property>minimum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMinimum() {
return minimum;
@@ -750,37 +845,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>minimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setMinimum(Number minimum) {
- this.minimum = minimum;
+ public ParameterInfo setMinimum(Number value) {
+ minimum = value;
return this;
}
/**
- * Synonym for {@link #setMinimum(Number)}.
+ * Same as {@link #setMinimum(Number)}.
*
- * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo minimum(Number minimum) {
- return setMinimum(minimum);
+ public ParameterInfo minimum(Object value) {
+ return setMinimum(toNumber(value));
}
/**
* Bean property getter: <property>exclusiveMinimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @return The value of the <property>exclusiveMinimum</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getExclusiveMinimum() {
return exclusiveMinimum;
@@ -789,36 +888,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>exclusiveMinimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setExclusiveMinimum(Boolean exclusiveMinimum) {
- this.exclusiveMinimum = exclusiveMinimum;
+ public ParameterInfo setExclusiveMinimum(Boolean value) {
+ exclusiveMinimum = value;
return this;
}
/**
- * Synonym for {@link #setExclusiveMinimum(Boolean)}.
+ * Same as {@link #setExclusiveMinimum(Boolean)}.
*
- * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo exclusiveMinimum(Boolean exclusiveMinimum) {
- return setExclusiveMinimum(exclusiveMinimum);
+ public ParameterInfo exclusiveMinimum(Object value) {
+ return setExclusiveMinimum(toBoolean(value));
}
/**
* Bean property getter: <property>maxLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">
- * http://json-schema.org/latest/json-schema-validation.html#anchor26</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">http://json-schema.org/latest/json-schema-validation.html#anchor26</a>
+ * </ul>
*
- * @return The value of the <property>maxLength</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMaxLength() {
return maxLength;
@@ -827,36 +931,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>maxLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">
- * http://json-schema.org/latest/json-schema-validation.html#anchor26</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">http://json-schema.org/latest/json-schema-validation.html#anchor26</a>
+ * </ul>
*
- * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setMaxLength(Integer maxLength) {
- this.maxLength = maxLength;
+ public ParameterInfo setMaxLength(Integer value) {
+ maxLength = value;
return this;
}
/**
- * Synonym for {@link #setMaxLength(Integer)}.
+ * Same as {@link #setMaxLength(Integer)}.
*
- * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo maxLength(Integer maxLength) {
- return setMaxLength(maxLength);
+ public ParameterInfo maxLength(Object value) {
+ return setMaxLength(toInteger(value));
}
/**
* Bean property getter: <property>minLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">
- * http://json-schema.org/latest/json-schema-validation.html#anchor29</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">http://json-schema.org/latest/json-schema-validation.html#anchor29</a>
+ * </ul>
*
- * @return The value of the <property>minLength</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMinLength() {
return minLength;
@@ -865,36 +974,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>minLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">
- * http://json-schema.org/latest/json-schema-validation.html#anchor29</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">http://json-schema.org/latest/json-schema-validation.html#anchor29</a>
+ * </ul>
*
- * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setMinLength(Integer minLength) {
- this.minLength = minLength;
+ public ParameterInfo setMinLength(Integer value) {
+ minLength = value;
return this;
}
/**
- * Synonym for {@link #setMinLength(Integer)}.
+ * Same as {@link #setMinLength(Integer)}.
*
- * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo minLength(Integer minLength) {
- return setMinLength(minLength);
+ public ParameterInfo minLength(Object value) {
+ return setMinLength(toInteger(value));
}
/**
* Bean property getter: <property>pattern</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">
- * http://json-schema.org/latest/json-schema-validation.html#anchor33</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">http://json-schema.org/latest/json-schema-validation.html#anchor33</a>
+ * </ul>
*
- * @return The value of the <property>pattern</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getPattern() {
return pattern;
@@ -903,36 +1017,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>pattern</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">
- * http://json-schema.org/latest/json-schema-validation.html#anchor33</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">http://json-schema.org/latest/json-schema-validation.html#anchor33</a>
+ * </ul>
*
- * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setPattern(String pattern) {
- this.pattern = pattern;
+ public ParameterInfo setPattern(String value) {
+ pattern = value;
return this;
}
/**
- * Synonym for {@link #setPattern(String)}.
+ * Same as {@link #setPattern(String)}.
*
- * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo pattern(String pattern) {
- return setPattern(pattern);
+ public ParameterInfo pattern(Object value) {
+ return setPattern(toStringVal(value));
}
/**
* Bean property getter: <property>maxItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">
- * http://json-schema.org/latest/json-schema-validation.html#anchor42</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">http://json-schema.org/latest/json-schema-validation.html#anchor42</a>
+ * </ul>
*
- * @return The value of the <property>maxItems</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMaxItems() {
return maxItems;
@@ -941,36 +1060,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>maxItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">
- * http://json-schema.org/latest/json-schema-validation.html#anchor42</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">http://json-schema.org/latest/json-schema-validation.html#anchor42</a>
+ * </ul>
*
- * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setMaxItems(Integer maxItems) {
- this.maxItems = maxItems;
+ public ParameterInfo setMaxItems(Integer value) {
+ maxItems = value;
return this;
}
/**
- * Synonym for {@link #setMaxItems(Integer)}.
+ * Same as {@link #setMaxItems(Integer)}.
*
- * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo maxItems(Integer maxItems) {
- return setMaxItems(maxItems);
+ public ParameterInfo maxItems(Object value) {
+ return setMaxItems(toInteger(value));
}
/**
* Bean property getter: <property>minItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">
- * http://json-schema.org/latest/json-schema-validation.html#anchor45</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">http://json-schema.org/latest/json-schema-validation.html#anchor45</a>
+ * </ul>
*
- * @return The value of the <property>minItems</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMinItems() {
return minItems;
@@ -979,37 +1103,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>minItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">
- * http://json-schema.org/latest/json-schema-validation.html#anchor45</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">http://json-schema.org/latest/json-schema-validation.html#anchor45</a>
+ * </ul>
*
- * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setMinItems(Integer minItems) {
- this.minItems = minItems;
+ public ParameterInfo setMinItems(Integer value) {
+ minItems = value;
return this;
}
/**
- * Synonym for {@link #setMinItems(Integer)}.
+ * Same as {@link #setMinItems(Integer)}.
*
- * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo minItems(Integer minItems) {
- return setMinItems(minItems);
+ public ParameterInfo minItems(Object value) {
+ return setMinItems(toInteger(value));
}
/**
* Bean property getter: <property>uniqueItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">
- * http://json-schema.org/latest/json-schema-validation.html#anchor49</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">http://json-schema.org/latest/json-schema-validation.html#anchor49</a>
+ * </ul>
*
- * @return The value of the <property>uniqueItems</property> property on this bean, or <jk>null</jk> if it is not
- * set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getUniqueItems() {
return uniqueItems;
@@ -1018,36 +1146,41 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>uniqueItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">
- * http://json-schema.org/latest/json-schema-validation.html#anchor49</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">http://json-schema.org/latest/json-schema-validation.html#anchor49</a>
+ * </ul>
*
- * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public ParameterInfo setUniqueItems(Boolean uniqueItems) {
- this.uniqueItems = uniqueItems;
+ public ParameterInfo setUniqueItems(Boolean value) {
+ uniqueItems = value;
return this;
}
/**
- * Synonym for {@link #setUniqueItems(Boolean)}.
+ * Same as {@link #setUniqueItems(Boolean)}.
*
- * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo uniqueItems(Boolean uniqueItems) {
- return setUniqueItems(uniqueItems);
+ public ParameterInfo uniqueItems(Object value) {
+ return setUniqueItems(toBoolean(value));
}
/**
* Bean property getter: <property>enum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">
- * http://json-schema.org/latest/json-schema-validation.html#anchor76</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">http://json-schema.org/latest/json-schema-validation.html#anchor76</a>
+ * </ul>
*
- * @return The value of the <property>enum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<Object> getEnum() {
return _enum;
@@ -1056,66 +1189,71 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>enum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">
- * http://json-schema.org/latest/json-schema-validation.html#anchor76</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">http://json-schema.org/latest/json-schema-validation.html#anchor76</a>
+ * </ul>
*
- * @param _enum The new value for the <property>enum</property> property on this bean.
+ * @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 ParameterInfo setEnum(List<Object> _enum) {
- this._enum = _enum;
+ public ParameterInfo setEnum(Collection<Object> value) {
+ _enum = newList(value);
return this;
}
/**
- * Bean property adder: <property>enum</property>.
- *
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">
- * http://json-schema.org/latest/json-schema-validation.html#anchor76</a>.
+ * Adds one or more values to the <property>enum</property> property.
*
- * @param _enum
- * The new values to add to the <property>enum</property> property on this bean.
- * These can either be individual objects or {@link Collection Collections} of objects.
+ * @param value
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- @SuppressWarnings("unchecked")
- public ParameterInfo addEnum(Object..._enum) {
- for (Object o : _enum) {
- if (o != null) {
- if (o instanceof Collection)
- addEnum((Collection<Object>)o);
- else {
- if (this._enum == null)
- this._enum = new LinkedList<>();
- this._enum.add(o);
- }
- }
- }
+ public ParameterInfo addEnum(Collection<Object> value) {
+ _enum = addToList(_enum, value);
return this;
}
-
- /**
- * Synonym for {@link #addEnum(Object...)}.
- *
- * @param _enum
- * The new values to add to the <property>enum</property> property on this bean.
- * These can either be individual objects or {@link Collection Collections} of objects.
+
+ /**
+ * Adds one or more values to the <property>enum</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Object</code>
+ * <li><code>Collection<Object></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<Object></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * _enum(<js>"['foo','bar']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * _enum(<js>"foo"</js>, <js>"bar"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public ParameterInfo _enum(Object..._enum) {
- return addEnum(_enum);
+ public ParameterInfo _enum(Object...values) {
+ _enum = addToList(_enum, values, Object.class);
+ return this;
}
/**
* Bean property getter: <property>multipleOf</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">
- * http://json-schema.org/latest/json-schema-validation.html#anchor14</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">http://json-schema.org/latest/json-schema-validation.html#anchor14</a>
+ * </ul>
*
- * @return The value of the <property>multipleOf</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMultipleOf() {
return multipleOf;
@@ -1124,25 +1262,97 @@ public class ParameterInfo extends SwaggerElement {
/**
* Bean property setter: <property>multipleOf</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">
- * http://json-schema.org/latest/json-schema-validation.html#anchor14</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">http://json-schema.org/latest/json-schema-validation.html#anchor14</a>
+ * </ul>
*
- * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @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 ParameterInfo setMultipleOf(Number multipleOf) {
- this.multipleOf = multipleOf;
+ public ParameterInfo setMultipleOf(Number value) {
+ multipleOf = value;
return this;
}
/**
- * Synonym for {@link #setMultipleOf(Number)}.
+ * Same as {@link #setMultipleOf(Number)}.
*
- * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ParameterInfo multipleOf(Number multipleOf) {
- return setMultipleOf(multipleOf);
+ public ParameterInfo multipleOf(Object value) {
+ return setMultipleOf(toNumber(value));
+ }
+
+ @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 "in": return toType(getIn(), type);
+ case "description": return toType(getDescription(), type);
+ case "required": return toType(getRequired(), type);
+ case "schema": return toType(getSchema(), type);
+ case "type": return toType(getType(), type);
+ case "format": return toType(getFormat(), type);
+ case "allowEmptyValue": return toType(getAllowEmptyValue(), type);
+ case "items": return toType(getItems(), type);
+ case "collectionFormat": return toType(getCollectionFormat(), type);
+ case "default": return toType(getDefault(), type);
+ case "maximum": return toType(getMaximum(), type);
+ case "exclusiveMaximum": return toType(getExclusiveMaximum(), type);
+ case "minimum": return toType(getMinimum(), type);
+ case "exclusiveMinimum": return toType(getExclusiveMinimum(), type);
+ case "maxLength": return toType(getMaxLength(), type);
+ case "minLength": return toType(getMinLength(), type);
+ case "pattern": return toType(getPattern(), type);
+ case "maxItems": return toType(getMaxItems(), type);
+ case "minItems": return toType(getMinItems(), type);
+ case "uniqueItems": return toType(getUniqueItems(), type);
+ case "enum": return toType(getEnum(), type);
+ case "multipleOf": return toType(getMultipleOf(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public ParameterInfo set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "name": return name(value);
+ case "in": return in(value);
+ case "description": return description(value);
+ case "required": return required(value);
+ case "schema": return schema(value);
+ case "type": return type(value);
+ case "format": return format(value);
+ case "allowEmptyValue": return allowEmptyValue(value);
+ case "items": return items(value);
+ case "collectionFormat": return collectionFormat(value);
+ case "default": return _default(value);
+ case "maximum": return maximum(value);
+ case "exclusiveMaximum": return exclusiveMaximum(value);
+ case "minimum": return minimum(value);
+ case "exclusiveMinimum": return exclusiveMinimum(value);
+ case "maxLength": return maxLength(value);
+ case "minLength": return minLength(value);
+ case "pattern": return pattern(value);
+ case "maxItems": return maxItems(value);
+ case "minItems": return minItems(value);
+ case "uniqueItems": return uniqueItems(value);
+ case "enum": return setEnum(null)._enum(value);
+ case "multipleOf": return multipleOf(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
index ddcba7f..ead018d 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import java.util.*;
import org.apache.juneau.annotation.*;
@@ -21,6 +22,25 @@ import org.apache.juneau.annotation.*;
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * ResponseInfo x = <jsm>responseInfo</jsm>(<js>"A complex object array response"</js>)
+ * .schema(
+ * <jsm>schemaInfo</jsm>
+ * .type(<js>"array"</js>)
+ * .items(
+ * <jsm>items<jsm>()
+ * .set(<js>"$ref"</js>, <js>"#/definitions/VeryComplexType"</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'>
+ * <jc>// Output</jc>
* {
* <js>"description"</js>: <js>"A complex object array response"</js>,
* <js>"schema"</js>: {
@@ -34,20 +54,10 @@ import org.apache.juneau.annotation.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="description,schema,headers,examples")
+@Bean(properties="description,schema,headers,examples,*")
public class ResponseInfo extends SwaggerElement {
private String description;
@@ -59,13 +69,9 @@ public class ResponseInfo extends SwaggerElement {
* Bean property getter: <property>description</property>.
*
* <p>
- * Required. A short description of the response.
+ * A short description of the response.
*
- * <p>
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for
- * rich text representation.
- *
- * @return The value of the <property>description</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDescription() {
return description;
@@ -75,28 +81,30 @@ public class ResponseInfo extends SwaggerElement {
* Bean property setter: <property>description</property>.
*
* <p>
- * Required. A short description of the response.
- *
- * <p>
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used
- * for rich text representation.
+ * A short description of the response.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public ResponseInfo setDescription(String description) {
- this.description = description;
+ public ResponseInfo setDescription(String value) {
+ description = value;
return this;
}
/**
- * Synonym for {@link #setDescription(String)}.
+ * Same as {@link #setDescription(String)}.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ResponseInfo description(String description) {
- return setDescription(description);
+ public ResponseInfo description(Object value) {
+ return setDescription(toStringVal(value));
}
/**
@@ -105,14 +113,15 @@ public class ResponseInfo extends SwaggerElement {
* <p>
* A definition of the response structure.
*
- * <p>
- * It can be a primitive, an array or an object.
- * If this field does not exist, it means no content is returned as part of the response.
- * As an extension to the <a class="doclink" href="http://swagger.io/specification/#schemaObject">Schema Object</a>,
- * its root type value may also be <js>"file"</js>.
- * This SHOULD be accompanied by a relevant produces mime-type.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li>If this field does not exist, it means no content is returned as part of the response.
+ * <li>As an extension to the <a class="doclink" href="http://swagger.io/specification/#schemaObject">Schema Object</a>,
+ * its root type value may also be <js>"file"</js>.
+ * <li>This SHOULD be accompanied by a relevant produces mime-type.
+ * </ul>
*
- * @return The value of the <property>schema</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public SchemaInfo getSchema() {
return schema;
@@ -124,29 +133,44 @@ public class ResponseInfo extends SwaggerElement {
* <p>
* A definition of the response structure.
*
- * <p>
- * It can be a primitive, an array or an object.
- * If this field does not exist, it means no content is returned as part of the response.
- * As an extension to the <a class="doclink" href="http://swagger.io/specification/#schemaObject">Schema Object</a>,
- * its root type value may also be <js>"file"</js>.
- * This SHOULD be accompanied by a relevant produces mime-type.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li>If this field does not exist, it means no content is returned as part of the response.
+ * <li>As an extension to the <a class="doclink" href="http://swagger.io/specification/#schemaObject">Schema Object</a>,
+ * its root type value may also be <js>"file"</js>.
+ * <li>This SHOULD be accompanied by a relevant produces mime-type.
+ * </ul>
*
- * @param schema The new value for the <property>schema</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>It can be a primitive, an array or an object.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ResponseInfo setSchema(SchemaInfo schema) {
- this.schema = schema;
+ public ResponseInfo setSchema(SchemaInfo value) {
+ schema = value;
return this;
}
/**
- * Synonym for {@link #setSchema(SchemaInfo)}.
+ * Same as {@link #setSchema(SchemaInfo)}.
*
- * @param schema The new value for the <property>schema</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link SchemaInfo}
+ * <li><code>String</code> - JSON object representation of {@link SchemaInfo}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * schema(<js>"{type:'type',description:'description',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ResponseInfo schema(SchemaInfo schema) {
- return setSchema(schema);
+ public ResponseInfo schema(Object value) {
+ return setSchema(toType(value, SchemaInfo.class));
}
/**
@@ -155,7 +179,7 @@ public class ResponseInfo extends SwaggerElement {
* <p>
* A list of headers that are sent with the response.
*
- * @return The value of the <property>headers</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,HeaderInfo> getHeaders() {
return headers;
@@ -167,40 +191,61 @@ public class ResponseInfo extends SwaggerElement {
* <p>
* A list of headers that are sent with the response.
*
- * @param headers The new value for the <property>headers</property> property on this bean.
+ * @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 ResponseInfo setHeaders(Map<String,HeaderInfo> headers) {
- this.headers = headers;
+ public ResponseInfo setHeaders(Map<String,HeaderInfo> value) {
+ headers = newMap(value);
return this;
}
/**
- * Bean property adder: <property>headers</property>.
+ * Adds one or more values to the <property>headers</property> property.
*
- * <p>
- * A list of headers that are sent with the response.
- *
- * @param name The header name.
- * @param header The header descriptions
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public ResponseInfo addHeader(String name, HeaderInfo header) {
- if (headers == null)
- headers = new TreeMap<>();
- headers.put(name, header);
+ public ResponseInfo addHeaders(Map<String,HeaderInfo> values) {
+ headers = addToMap(headers, values);
return this;
}
/**
- * Synonym for {@link #addHeader(String,HeaderInfo)}.
+ * Adds a single value to the <property>headers</property> property.
*
* @param name The header name.
* @param header The header descriptions
* @return This object (for method chaining).
*/
public ResponseInfo header(String name, HeaderInfo header) {
- return addHeader(name, header);
+ addHeaders(Collections.singletonMap(name, header));
+ return this;
+ }
+
+ /**
+ * Adds one or more values to the <property>headers</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,{@link HeaderInfo}|String></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,{@link HeaderInfo}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * headers(<js>"{headerName:{description:'description',...}}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public ResponseInfo headers(Object...values) {
+ headers = addToMap(headers, values, String.class, HeaderInfo.class);
+ return this;
}
/**
@@ -209,10 +254,7 @@ public class ResponseInfo extends SwaggerElement {
* <p>
* An example of the response message.
*
- * <p>
- * Keys must be MIME-type strings.
- *
- * @return The value of the <property>examples</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,Object> getExamples() {
return examples;
@@ -224,52 +266,89 @@ public class ResponseInfo extends SwaggerElement {
* <p>
* An example of the response message.
*
- * <p>
- * Keys must be MIME-type strings.
- *
- * @param examples The new value for the <property>examples</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Keys must be MIME-type strings.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ResponseInfo setExamples(Map<String,Object> examples) {
- this.examples = examples;
+ public ResponseInfo setExamples(Map<String,Object> value) {
+ examples = newMap(value);
return this;
}
/**
- * Bean property adder: <property>examples</property>.
+ * Adds one or more values to the <property>examples</property> property.
*
- * <p>
- * An example of the response message.
- *
- * @param mimeType The mimeType of the example.
- * @param example The example output.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public ResponseInfo addExample(String mimeType, Object example) {
- if (examples == null)
- examples = new TreeMap<>();
- examples.put(mimeType, example);
+ public ResponseInfo addExamples(Map<String,Object> values) {
+ examples = addToMap(examples, values);
return this;
}
/**
- * Synonym for {@link #addExample(String,Object)}.
+ * Adds a single value to the <property>examples</property> property.
*
- * @param mimeType The mimeType of the example.
- * @param example The example output.
+ * @param mimeType The mime-type string.
+ * @param example The example.
* @return This object (for method chaining).
*/
public ResponseInfo example(String mimeType, Object example) {
- return addExample(mimeType, example);
+ examples = addToMap(examples, mimeType, example);
+ return this;
}
/**
- * Synonym for {@link #setExamples(Map)}.
+ * Adds one or more values to the <property>examples</property> property.
*
- * @param examples The new value for the <property>examples</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,Object></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,Object></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * examples(<js>"{'text/json':{foo:'bar'}}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public ResponseInfo examples(Map<String,Object> examples) {
- return setExamples(examples);
+ public ResponseInfo examples(Object...values) {
+ examples = addToMap(examples, values, String.class, Object.class);
+ 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 "schema": return toType(getSchema(), type);
+ case "headers": return toType(getHeaders(), type);
+ case "examples": return toType(getExamples(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public ResponseInfo set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "description": return description(value);
+ case "schema": return schema(value);
+ case "headers": return setHeaders(null).headers(value);
+ case "examples": return setExamples(null).examples(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
[08/10] juneau git commit: JUNEAU-78
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SwaggerTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SwaggerTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SwaggerTest.java
new file mode 100644
index 0000000..99aa176
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SwaggerTest.java
@@ -0,0 +1,910 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.*;
+
+import org.apache.juneau.http.*;
+import org.apache.juneau.json.*;
+import org.apache.juneau.utils.*;
+
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+
+import org.junit.*;
+
+/**
+ * Testcase for {@link Swagger}.
+ */
+public class SwaggerTest {
+
+ /**
+ * Test method for {@link Swagger#swagger(java.lang.Object)}.
+ */
+ @Test
+ public void testSwagger() {
+ Swagger t = new Swagger();
+
+ t.swagger("foo");
+ assertEquals("foo", t.getSwagger());
+
+ t.swagger(new StringBuilder("foo"));
+ assertEquals("foo", t.getSwagger());
+ assertType(String.class, t.getSwagger());
+
+ t.swagger(null);
+ assertNull(t.getSwagger());
+ }
+
+ /**
+ * Test method for {@link Swagger#info(java.lang.Object)}.
+ */
+ @Test
+ public void testInfo() {
+ Swagger t = new Swagger();
+
+ t.info(info("foo", "bar"));
+ assertObjectEquals("{title:'foo',version:'bar'}", t.getInfo());
+
+ t.info("{title:'foo',version:'bar'}");
+ assertObjectEquals("{title:'foo',version:'bar'}", t.getInfo());
+ assertType(Info.class, t.getInfo());
+
+ t.info(null);
+ assertNull(t.getInfo());
+ }
+
+ /**
+ * Test method for {@link Swagger#host(java.lang.Object)}.
+ */
+ @Test
+ public void testHost() {
+ Swagger t = new Swagger();
+
+ t.host("foo");
+ assertEquals("foo", t.getHost());
+
+ t.host(new StringBuilder("foo"));
+ assertEquals("foo", t.getHost());
+ assertType(String.class, t.getHost());
+
+ t.host(null);
+ assertNull(t.getHost());
+ }
+
+ /**
+ * Test method for {@link Swagger#basePath(java.lang.Object)}.
+ */
+ @Test
+ public void testBasePath() {
+ Swagger t = new Swagger();
+
+ t.basePath("foo");
+ assertEquals("foo", t.getBasePath());
+
+ t.basePath(new StringBuilder("foo"));
+ assertEquals("foo", t.getBasePath());
+ assertType(String.class, t.getBasePath());
+
+ t.basePath(null);
+ assertNull(t.getBasePath());
+ }
+
+ /**
+ * Test method for {@link Swagger#setSchemes(java.util.Collection)}.
+ */
+ @Test
+ public void testSetSchemes() {
+ Swagger t = new Swagger();
+
+ t.setSchemes(new ASet<String>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+
+ t.setSchemes(new ASet<String>());
+ assertObjectEquals("[]", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+
+ t.setSchemes(null);
+ assertNull(t.getSchemes());
+ }
+
+ /**
+ * Test method for {@link Swagger#addSchemes(java.util.Collection)}.
+ */
+ @Test
+ public void testAddSchemes() {
+ Swagger t = new Swagger();
+
+ t.addSchemes(new ASet<String>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+
+ t.addSchemes(new ASet<String>());
+ assertObjectEquals("['foo','bar']", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+
+ t.addSchemes(null);
+ assertObjectEquals("['foo','bar']", t.getSchemes());
+ assertType(List.class, t.getSchemes());
+ }
+
+ /**
+ * Test method for {@link Swagger#schemes(java.lang.Object[])}.
+ */
+ @Test
+ public void testSchemes() {
+ Swagger t = new Swagger();
+
+ t.schemes(new ASet<String>().appendAll("foo"));
+ t.schemes(new ASet<Object>().appendAll(new StringBuilder("bar")));
+ t.schemes((Object)new String[] {"baz"});
+ t.schemes("['qux']");
+ t.schemes("quux");
+ t.schemes("[]");
+ t.schemes((Object)null);
+
+ assertObjectEquals("['foo','bar','baz','qux','quux']", t.getSchemes());
+ }
+
+ /**
+ * Test method for {@link Swagger#setConsumes(java.util.Collection)}.
+ */
+ @Test
+ public void testSetConsumes() {
+ Swagger t = new Swagger();
+
+ t.setConsumes(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ assertObjectEquals("['text/foo']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+
+ t.setConsumes(new ASet<MediaType>());
+ assertObjectEquals("[]", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+
+ t.setConsumes(null);
+ assertNull(t.getConsumes());
+ }
+
+ /**
+ * Test method for {@link Swagger#addConsumes(java.util.Collection)}.
+ */
+ @Test
+ public void testAddConsumes() {
+ Swagger t = new Swagger();
+
+ t.addConsumes(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ assertObjectEquals("['text/foo']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+
+ t.addConsumes(new ASet<MediaType>());
+ assertObjectEquals("['text/foo']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+
+ t.addConsumes(null);
+ assertObjectEquals("['text/foo']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+ }
+
+ /**
+ * Test method for {@link Swagger#consumes(java.lang.Object[])}.
+ */
+ @Test
+ public void testConsumes() {
+ Swagger t = new Swagger();
+
+ t.consumes(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ t.consumes(MediaType.forString("text/bar"));
+ t.consumes("text/baz");
+ t.consumes(new StringBuilder("text/qux"));
+ t.consumes((Object)new String[]{"text/quux"});
+ t.consumes((Object)new ASet<String>().append("text/quuux"));
+ t.consumes("['text/quuuux']");
+ t.consumes("[]");
+ t.consumes((Object)null);
+ assertObjectEquals("['text/foo','text/bar','text/baz','text/qux','text/quux','text/quuux','text/quuuux']", t.getConsumes());
+ assertType(List.class, t.getConsumes());
+ for (MediaType mt : t.getConsumes())
+ assertType(MediaType.class, mt);
+ }
+
+ /**
+ * Test method for {@link Swagger#setProduces(java.util.Collection)}.
+ */
+ @Test
+ public void testSetProduces() {
+ Swagger t = new Swagger();
+
+ t.setProduces(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ assertObjectEquals("['text/foo']", t.getProduces());
+ assertType(List.class, t.getProduces());
+
+ t.setProduces(new ASet<MediaType>());
+ assertObjectEquals("[]", t.getProduces());
+ assertType(List.class, t.getProduces());
+
+ t.setProduces(null);
+ assertNull(t.getProduces());
+ }
+
+ /**
+ * Test method for {@link Swagger#addProduces(java.util.Collection)}.
+ */
+ @Test
+ public void testAddProduces() {
+ Swagger t = new Swagger();
+
+ t.addProduces(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ assertObjectEquals("['text/foo']", t.getProduces());
+ assertType(List.class, t.getProduces());
+
+ t.addProduces(new ASet<MediaType>());
+ assertObjectEquals("['text/foo']", t.getProduces());
+ assertType(List.class, t.getProduces());
+
+ t.addProduces(null);
+ assertObjectEquals("['text/foo']", t.getProduces());
+ assertType(List.class, t.getProduces());
+ }
+
+ /**
+ * Test method for {@link Swagger#produces(java.lang.Object[])}.
+ */
+ @Test
+ public void testProduces() {
+ Swagger t = new Swagger();
+
+ t.produces(new ASet<MediaType>().appendAll(MediaType.forString("text/foo")));
+ t.produces(MediaType.forString("text/bar"));
+ t.produces("text/baz");
+ t.produces(new StringBuilder("text/qux"));
+ t.produces((Object)new String[]{"text/quux"});
+ t.produces((Object)new ASet<String>().append("text/quuux"));
+ t.produces("['text/quuuux']");
+ t.produces("[]");
+ t.produces((Object)null);
+ assertObjectEquals("['text/foo','text/bar','text/baz','text/qux','text/quux','text/quuux','text/quuuux']", t.getProduces());
+ assertType(List.class, t.getProduces());
+ for (MediaType mt : t.getProduces())
+ assertType(MediaType.class, mt);
+ }
+
+ /**
+ * Test method for {@link Swagger#setPaths(java.util.Map)}.
+ */
+ @Test
+ public void testSetPaths() {
+ Swagger t = new Swagger();
+
+ t.setPaths(new AMap<String,Map<String,Operation>>().append("foo", new AMap<String,Operation>().append("bar",operation().summary("baz"))));
+ assertObjectEquals("{foo:{bar:{summary:'baz'}}}", t.getPaths());
+ assertType(Map.class, t.getPaths());
+
+ t.setPaths(new AMap<String,Map<String,Operation>>());
+ assertObjectEquals("{}", t.getPaths());
+ assertType(Map.class, t.getPaths());
+
+ t.setPaths(null);
+ assertNull(t.getPaths());
+ }
+
+ /**
+ * Test method for {@link Swagger#addPaths(java.util.Map)}.
+ */
+ @Test
+ public void testAddPaths() {
+ Swagger t = new Swagger();
+
+ t.addPaths(new AMap<String,Map<String,Operation>>().append("foo", new AMap<String,Operation>().append("bar",operation().summary("baz"))));
+ assertObjectEquals("{foo:{bar:{summary:'baz'}}}", t.getPaths());
+ assertType(Map.class, t.getPaths());
+
+ t.addPaths(new AMap<String,Map<String,Operation>>());
+ assertObjectEquals("{foo:{bar:{summary:'baz'}}}", t.getPaths());
+ assertType(Map.class, t.getPaths());
+
+ t.addPaths(null);
+ assertObjectEquals("{foo:{bar:{summary:'baz'}}}", t.getPaths());
+ assertType(Map.class, t.getPaths());
+ }
+
+ /**
+ * Test method for {@link Swagger#path(java.lang.String, java.lang.String, org.apache.juneau.dto.swagger.Operation)}.
+ */
+ @Test
+ public void testPath() {
+ Swagger t = new Swagger();
+
+ t.path("a", "a1", operation().description("a2"));
+ t.path("b", null, null);
+ t.path(null, "c1", operation().description("c2"));
+
+ assertObjectEquals("{a:{a1:{description:'a2'}},b:{null:null},null:{c1:{description:'c2'}}}", t.getPaths());
+ }
+
+ /**
+ * Test method for {@link Swagger#paths(java.lang.Object[])}.
+ */
+ @Test
+ public void testPaths() {
+ Swagger t = new Swagger();
+
+ t.paths(new AMap<String,Map<String,Operation>>().append("a", new AMap<String,Operation>().append("a1", operation().operationId("a2"))));
+ t.paths(new AMap<String,Map<String,String>>().append("b", new AMap<String,String>().append("b1", "{operationId:'b2'}")));
+ t.paths(new AMap<String,String>().append("c", "{c1:{operationId:'c2'}}"));
+ t.paths("{d:{d1:{operationId:'d2'}}}");
+ t.paths("{}");
+ t.paths((Object[])null);
+
+ assertObjectEquals("{a:{a1:{operationId:'a2'}},b:{b1:{operationId:'b2'}},c:{c1:{operationId:'c2'}},d:{d1:{operationId:'d2'}}}", t.getPaths());
+ for (Map<String,Operation> m : t.getPaths().values()) {
+ for (Operation o : m.values()) {
+ assertType(Operation.class, o);
+ }
+ }
+ }
+
+ /**
+ * Test method for {@link Swagger#setDefinitions(java.util.Map)}.
+ */
+ @Test
+ public void testSetDefinitions() {
+ Swagger t = new Swagger();
+
+ t.setDefinitions(new AMap<String,SchemaInfo>().append("foo",schemaInfo().title("bar")));
+ assertObjectEquals("{foo:{title:'bar'}}", t.getDefinitions());
+ assertType(Map.class, t.getDefinitions());
+
+ t.setDefinitions(new AMap<String,SchemaInfo>());
+ assertObjectEquals("{}", t.getDefinitions());
+ assertType(Map.class, t.getDefinitions());
+
+ t.setDefinitions(null);
+ assertNull(t.getDefinitions());
+ }
+
+ /**
+ * Test method for {@link Swagger#addDefinitions(java.util.Map)}.
+ */
+ @Test
+ public void testAddDefinitions() {
+ Swagger t = new Swagger();
+
+ t.addDefinitions(new AMap<String,SchemaInfo>().append("foo",schemaInfo().title("bar")));
+ assertObjectEquals("{foo:{title:'bar'}}", t.getDefinitions());
+ assertType(Map.class, t.getDefinitions());
+
+ t.addDefinitions(new AMap<String,SchemaInfo>());
+ assertObjectEquals("{foo:{title:'bar'}}", t.getDefinitions());
+ assertType(Map.class, t.getDefinitions());
+
+ t.addDefinitions(null);
+ assertObjectEquals("{foo:{title:'bar'}}", t.getDefinitions());
+ assertType(Map.class, t.getDefinitions());
+ }
+
+ /**
+ * Test method for {@link Swagger#definition(java.lang.String, org.apache.juneau.dto.swagger.SchemaInfo)}.
+ */
+ @Test
+ public void testDefinition() {
+ Swagger t = new Swagger();
+
+ t.definition("a", schemaInfo().title("a1"));
+ t.definition("b", null);
+ t.definition(null, schemaInfo().title("c1"));
+
+ assertObjectEquals("{a:{title:'a1'},b:null,null:{title:'c1'}}", t.getDefinitions());
+ }
+
+ /**
+ * Test method for {@link Swagger#definitions(java.lang.Object[])}.
+ */
+ @Test
+ public void testDefinitions() {
+ Swagger t = new Swagger();
+
+ t.definitions(new AMap<String,SchemaInfo>().append("a", schemaInfo().type("a1")));
+ t.definitions(new AMap<String,String>().append("b", "{type:'b1'}"));
+ t.definitions("{c:{type:'c1'}}");
+ t.definitions("{}");
+ t.definitions((Object[])null);
+
+ assertObjectEquals("{a:{type:'a1'},b:{type:'b1'},c:{type:'c1'}}", t.getDefinitions());
+ }
+
+ /**
+ * Test method for {@link Swagger#setParameters(java.util.Map)}.
+ */
+ @Test
+ public void testSetParameters() {
+ Swagger t = new Swagger();
+
+ t.setParameters(new AMap<String,ParameterInfo>().append("foo",parameterInfo().name("bar")));
+ assertObjectEquals("{foo:{name:'bar'}}", t.getParameters());
+ assertType(Map.class, t.getParameters());
+
+ t.setParameters(new AMap<String,ParameterInfo>());
+ assertObjectEquals("{}", t.getParameters());
+ assertType(Map.class, t.getParameters());
+
+ t.setParameters(null);
+ assertNull(t.getParameters());
+ }
+
+ /**
+ * Test method for {@link Swagger#addParameters(java.util.Map)}.
+ */
+ @Test
+ public void testAddParameters() {
+ Swagger t = new Swagger();
+
+ t.addParameters(new AMap<String,ParameterInfo>().append("foo",parameterInfo().name("bar")));
+ assertObjectEquals("{foo:{name:'bar'}}", t.getParameters());
+ assertType(Map.class, t.getParameters());
+
+ t.addParameters(new AMap<String,ParameterInfo>());
+ assertObjectEquals("{foo:{name:'bar'}}", t.getParameters());
+ assertType(Map.class, t.getParameters());
+
+ t.addParameters(null);
+ assertObjectEquals("{foo:{name:'bar'}}", t.getParameters());
+ assertType(Map.class, t.getParameters());
+ }
+
+ /**
+ * Test method for {@link Swagger#parameter(java.lang.String, org.apache.juneau.dto.swagger.ParameterInfo)}.
+ */
+ @Test
+ public void testParameter() {
+ Swagger t = new Swagger();
+
+ t.parameter("a", parameterInfo().in("a1"));
+ t.parameter("b", null);
+ t.parameter(null, parameterInfo().in("c1"));
+
+ assertObjectEquals("{a:{'in':'a1'},b:null,null:{'in':'c1'}}", t.getParameters());
+ }
+
+ /**
+ * Test method for {@link Swagger#parameters(java.lang.Object[])}.
+ */
+ @Test
+ public void testParameters() {
+ Swagger t = new Swagger();
+
+ t.parameters(new AMap<String,ParameterInfo>().append("a", parameterInfo("a1", "a2")));
+ t.parameters(new AMap<String,String>().append("b", "{in:'b1',name:'b2'}"));
+ t.parameters("{c:{in:'c1',name:'c2'}}");
+ t.parameters("{}");
+ t.parameters((Object[])null);
+
+ assertObjectEquals("{a:{'in':'a1',name:'a2'},b:{'in':'b1',name:'b2'},c:{'in':'c1',name:'c2'}}", t.getParameters());
+ }
+
+ /**
+ * Test method for {@link Swagger#setResponses(java.util.Map)}.
+ */
+ @Test
+ public void testSetResponses() {
+ Swagger t = new Swagger();
+
+ t.setResponses(new AMap<String,ResponseInfo>().append("123",responseInfo("bar")));
+ assertObjectEquals("{'123':{description:'bar'}}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+
+ t.setResponses(new AMap<String,ResponseInfo>());
+ assertObjectEquals("{}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+
+ t.setResponses(null);
+ assertNull(t.getResponses());
+ }
+
+ /**
+ * Test method for {@link Swagger#addResponses(java.util.Map)}.
+ */
+ @Test
+ public void testAddResponses() {
+ Swagger t = new Swagger();
+
+ t.addResponses(new AMap<String,ResponseInfo>().append("123",responseInfo("bar")));
+ assertObjectEquals("{'123':{description:'bar'}}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+
+ t.addResponses(new AMap<String,ResponseInfo>());
+ assertObjectEquals("{'123':{description:'bar'}}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+
+ t.addResponses(null);
+ assertObjectEquals("{'123':{description:'bar'}}", t.getResponses());
+ assertType(Map.class, t.getResponses());
+ }
+
+ /**
+ * Test method for {@link Swagger#response(java.lang.String, org.apache.juneau.dto.swagger.ResponseInfo)}.
+ */
+ @Test
+ public void testResponse() {
+ Swagger t = new Swagger();
+
+ t.response("a", responseInfo("a1"));
+ t.response(null, responseInfo("b1"));
+ t.response("c", null);
+
+ assertObjectEquals("{a:{description:'a1'},null:{description:'b1'},c:null}", t.getResponses());
+ }
+
+ /**
+ * Test method for {@link Swagger#responses(java.lang.Object[])}.
+ */
+ @Test
+ public void testResponses() {
+ Swagger t = new Swagger();
+
+ t.responses(new AMap<String,ResponseInfo>().append("a", responseInfo("a1")));
+ t.responses(new AMap<String,String>().append("b", "{description:'b1'}"));
+ t.responses("{c:{description:'c1'}}");
+ t.responses("{}");
+ t.responses((Object[])null);
+
+ assertObjectEquals("{a:{description:'a1'},b:{description:'b1'},c:{description:'c1'}}", t.getResponses());
+ for (ResponseInfo ri : t.getResponses().values())
+ assertType(ResponseInfo.class, ri);
+ }
+
+ /**
+ * Test method for {@link Swagger#setSecurityDefinitions(java.util.Map)}.
+ */
+ @Test
+ public void testSetSecurityDefinitions() {
+ Swagger t = new Swagger();
+
+ t.setSecurityDefinitions(new AMap<String,SecurityScheme>().append("foo",securityScheme("bar")));
+ assertObjectEquals("{foo:{type:'bar'}}", t.getSecurityDefinitions());
+ assertType(Map.class, t.getSecurityDefinitions());
+
+ t.setSecurityDefinitions(new AMap<String,SecurityScheme>());
+ assertObjectEquals("{}", t.getSecurityDefinitions());
+ assertType(Map.class, t.getSecurityDefinitions());
+
+ t.setSecurityDefinitions(null);
+ assertNull(t.getSecurityDefinitions());
+ }
+
+ /**
+ * Test method for {@link Swagger#addSecurityDefinitions(java.util.Map)}.
+ */
+ @Test
+ public void testAddSecurityDefinitions() {
+ Swagger t = new Swagger();
+
+ t.addSecurityDefinitions(new AMap<String,SecurityScheme>().append("foo",securityScheme("bar")));
+ assertObjectEquals("{foo:{type:'bar'}}", t.getSecurityDefinitions());
+ assertType(Map.class, t.getSecurityDefinitions());
+
+ t.addSecurityDefinitions(new AMap<String,SecurityScheme>());
+ assertObjectEquals("{foo:{type:'bar'}}", t.getSecurityDefinitions());
+ assertType(Map.class, t.getSecurityDefinitions());
+
+ t.addSecurityDefinitions(null);
+ assertObjectEquals("{foo:{type:'bar'}}", t.getSecurityDefinitions());
+ assertType(Map.class, t.getSecurityDefinitions());
+ }
+
+ /**
+ * Test method for {@link Swagger#securityDefinition(java.lang.String, org.apache.juneau.dto.swagger.SecurityScheme)}.
+ */
+ @Test
+ public void testSecurityDefinition() {
+ Swagger t = new Swagger();
+
+ t.securityDefinition("a", securityScheme("a1"));
+ t.securityDefinition("b", null);
+ t.securityDefinition(null, securityScheme("c1"));
+
+ assertObjectEquals("{a:{type:'a1'},b:null,null:{type:'c1'}}", t.getSecurityDefinitions());
+ }
+
+ /**
+ * Test method for {@link Swagger#securityDefinitions(java.lang.Object[])}.
+ */
+ @Test
+ public void testSecurityDefinitions() {
+ Swagger t = new Swagger();
+
+ t.securityDefinitions(new AMap<String,SecurityScheme>().append("a", securityScheme("a1")));
+ t.securityDefinitions(new AMap<String,String>().append("b", "{type:'b1'}"));
+ t.securityDefinitions("{c:{type:'c1'}}");
+ t.securityDefinitions("{}");
+ t.securityDefinitions((Object[])null);
+
+ assertObjectEquals("{a:{type:'a1'},b:{type:'b1'},c:{type:'c1'}}", t.getSecurityDefinitions());
+ for (SecurityScheme ss : t.getSecurityDefinitions().values())
+ assertType(SecurityScheme.class, ss);
+ }
+
+ /**
+ * Test method for {@link Swagger#setSecurity(java.util.Collection)}.
+ */
+ @Test
+ public void testSetSecurity() {
+ Swagger t = new Swagger();
+
+ t.setSecurity(new ASet<Map<String,List<String>>>().append(new AMap<String,List<String>>().append("foo",new AList<String>().append("bar"))));
+ assertObjectEquals("[{foo:['bar']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+
+ t.setSecurity(new ASet<Map<String,List<String>>>());
+ assertObjectEquals("[]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+
+ t.setSecurity(null);
+ assertNull(t.getSecurity());
+ }
+
+ /**
+ * Test method for {@link Swagger#addSecurity(java.util.Collection)}.
+ */
+ @Test
+ public void testAddSecurity() {
+ Swagger t = new Swagger();
+
+ t.addSecurity(new ASet<Map<String,List<String>>>().append(new AMap<String,List<String>>().append("foo",new AList<String>().append("bar"))));
+ assertObjectEquals("[{foo:['bar']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+
+ t.addSecurity(new ASet<Map<String,List<String>>>());
+ assertObjectEquals("[{foo:['bar']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+
+ t.addSecurity(null);
+ assertObjectEquals("[{foo:['bar']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+ }
+
+ /**
+ * Test method for {@link Swagger#security(java.lang.String, java.lang.String[])}.
+ */
+ @Test
+ public void testSecurity() {
+ Swagger t = new Swagger();
+
+ t.security("a", "a1", "a2");
+ t.security("b", (String)null);
+ t.security("c");
+ t.security(null, "d1", "d2");
+
+ assertObjectEquals("[{a:['a1','a2']},{b:[null]},{c:[]},{null:['d1','d2']}]", t.getSecurity());
+ }
+
+ /**
+ * Test method for {@link Swagger#securities(java.lang.Object[])}.
+ */
+ @Test
+ public void testSecurities() {
+ Swagger t = new Swagger();
+ //Collection<Map<String,List<String>>>
+ t.securities(new ASet<Map<String,List<String>>>().append(new AMap<String,List<String>>().append("a1",new AList<String>().append("a2"))));
+ t.securities(new AMap<String,List<String>>().append("b1",new AList<String>().append("b2")));
+ t.securities("{c1:['c2']}");
+ t.securities(new StringBuilder("{d1:['d2']}"));
+ t.securities((Object)new String[]{"{e1:['e2']}"});
+ t.securities((Object)new ASet<String>().append("{f1:['f2']}"));
+ t.securities("[{g1:['g2']}]");
+ t.securities("[]");
+ t.securities((Object)null);
+ assertObjectEquals("[{a1:['a2']},{b1:['b2']},{c1:['c2']},{d1:['d2']},{e1:['e2']},{f1:['f2']},{g1:['g2']}]", t.getSecurity());
+ assertType(List.class, t.getSecurity());
+ }
+
+ /**
+ * Test method for {@link Swagger#setTags(java.util.Collection)}.
+ */
+ @Test
+ public void testSetTags() {
+ Swagger t = new Swagger();
+
+ t.setTags(new ASet<Tag>().appendAll(tag("foo")));
+ assertObjectEquals("[{name:'foo'}]", t.getTags());
+ assertType(List.class, t.getTags());
+
+ t.setTags(new ASet<Tag>());
+ assertObjectEquals("[]", t.getTags());
+ assertType(List.class, t.getTags());
+
+ t.setTags(null);
+ assertNull(t.getTags());
+ }
+
+ /**
+ * Test method for {@link Swagger#addTags(java.util.Collection)}.
+ */
+ @Test
+ public void testAddTags() {
+ Swagger t = new Swagger();
+
+ t.addTags(new ASet<Tag>().appendAll(tag("foo")));
+ assertObjectEquals("[{name:'foo'}]", t.getTags());
+ assertType(List.class, t.getTags());
+
+ t.addTags(new ASet<Tag>());
+ assertObjectEquals("[{name:'foo'}]", t.getTags());
+ assertType(List.class, t.getTags());
+
+ t.addTags(null);
+ assertObjectEquals("[{name:'foo'}]", t.getTags());
+ assertType(List.class, t.getTags());
+ }
+
+ /**
+ * Test method for {@link Swagger#tags(java.lang.Object[])}.
+ */
+ @Test
+ public void testTags() {
+ Swagger t = new Swagger();
+
+ t.tags(new ASet<Tag>().appendAll(tag("a")));
+ t.tags(new ASet<String>().appendAll("{name:'b'}"));
+ t.tags((Object)new Tag[] {tag("c")});
+ t.tags((Object)new String[] {"{name:'d'}"});
+ t.tags("{name:'e'}");
+ t.tags(new StringBuilder("{name:'f'}"));
+ t.tags("[{name:'g'}]");
+ t.tags("[]");
+ t.tags((Object)null);
+ assertObjectEquals("[{name:'a'},{name:'b'},{name:'c'},{name:'d'},{name:'e'},{name:'f'},{name:'g'}]", t.getTags());
+ assertType(List.class, t.getTags());
+ for (Tag tag : t.getTags())
+ assertType(Tag.class, tag);
+ }
+
+ /**
+ * Test method for {@link Swagger#externalDocs(java.lang.Object)}.
+ */
+ @Test
+ public void testExternalDocs() {
+ Swagger t = new Swagger();
+
+ t.externalDocs(externalDocumentation("foo"));
+ assertObjectEquals("{url:'foo'}", t.getExternalDocs());
+
+ t.externalDocs("{url:'foo'}");
+ assertObjectEquals("{url:'foo'}", t.getExternalDocs());
+ assertType(ExternalDocumentation.class, t.getExternalDocs());
+
+ t.externalDocs(null);
+ assertNull(t.getExternalDocs());
+ }
+
+ /**
+ * Test method for {@link Swagger#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ Swagger t = new Swagger();
+
+ t
+ .set("basePath", "a")
+ .set("consumes", new ASet<MediaType>().appendAll(MediaType.forString("text/b")))
+ .set("definitions", new AMap<String,SchemaInfo>().append("c", schemaInfo().type("c1")))
+ .set("externalDocs", externalDocumentation("d"))
+ .set("host", "e")
+ .set("info", info("f1", "f2"))
+ .set("parameters", new AMap<String,ParameterInfo>().append("g", parameterInfo("g1", "g2")))
+ .set("paths", new AMap<String,Map<String,Operation>>().append("h", new AMap<String,Operation>().append("h1", operation().operationId("h2"))))
+ .set("produces", new ASet<MediaType>().appendAll(MediaType.forString("text/i")))
+ .set("responses", new AMap<String,ResponseInfo>().append("j", responseInfo("j1")))
+ .set("schemes", new ASet<String>().appendAll("k1"))
+ .set("security", new ASet<Map<String,List<String>>>().append(new AMap<String,List<String>>().append("l1",new AList<String>().append("l2"))))
+ .set("securityDefinitions", new AMap<String,SecurityScheme>().append("m", securityScheme("m1")))
+ .set("swagger", "n")
+ .set("tags", new ASet<Tag>().appendAll(tag("o")))
+ .set("$ref", "ref");
+
+ assertObjectEquals("{swagger:'n',info:{title:'f1',version:'f2'},tags:[{name:'o'}],externalDocs:{url:'d'},basePath:'a',schemes:['k1'],consumes:['text/b'],produces:['text/i'],paths:{h:{h1:{operationId:'h2'}}},definitions:{c:{type:'c1'}},parameters:{g:{'in':'g1',name:'g2'}},responses:{j:{description:'j1'}},securityDefinitions:{m:{type:'m1'}},security:[{l1:['l2']}],'$ref':'ref'}", t);
+
+ t
+ .set("basePath", "a")
+ .set("consumes", "['text/b']")
+ .set("definitions", "{c:{type:'c1'}}")
+ .set("externalDocs", "{url:'d'}")
+ .set("host", "e")
+ .set("info", "{title:'f1',version:'f2'}")
+ .set("parameters", "{g:{'in':'g1',name:'g2'}}")
+ .set("paths", "{h:{h1:{operationId:'h2'}}}")
+ .set("produces", "['text/i']")
+ .set("responses", "{j:{description:'j1'}}")
+ .set("schemes", "['k1']")
+ .set("security", "[{l1:['l2']}]")
+ .set("securityDefinitions", "{m:{type:'m1'}}")
+ .set("swagger", "n")
+ .set("tags", "[{name:'o'}]")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{swagger:'n',info:{title:'f1',version:'f2'},tags:[{name:'o'}],externalDocs:{url:'d'},basePath:'a',schemes:['k1'],consumes:['text/b'],produces:['text/i'],paths:{h:{h1:{operationId:'h2'}}},definitions:{c:{type:'c1'}},parameters:{g:{'in':'g1',name:'g2'}},responses:{j:{description:'j1'}},securityDefinitions:{m:{type:'m1'}},security:[{l1:['l2']}],'$ref':'ref'}", t);
+
+ t
+ .set("basePath", new StringBuilder("a"))
+ .set("consumes", new StringBuilder("['text/b']"))
+ .set("definitions", new StringBuilder("{c:{type:'c1'}}"))
+ .set("externalDocs", new StringBuilder("{url:'d'}"))
+ .set("host", new StringBuilder("e"))
+ .set("info", new StringBuilder("{title:'f1',version:'f2'}"))
+ .set("parameters", new StringBuilder("{g:{'in':'g1',name:'g2'}}"))
+ .set("paths", new StringBuilder("{h:{h1:{operationId:'h2'}}}"))
+ .set("produces", new StringBuilder("['text/i']"))
+ .set("responses", new StringBuilder("{j:{description:'j1'}}"))
+ .set("schemes", new StringBuilder("['k1']"))
+ .set("security", new StringBuilder("[{l1:['l2']}]"))
+ .set("securityDefinitions", new StringBuilder("{m:{type:'m1'}}"))
+ .set("swagger", new StringBuilder("n"))
+ .set("tags", new StringBuilder("[{name:'o'}]"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{swagger:'n',info:{title:'f1',version:'f2'},tags:[{name:'o'}],externalDocs:{url:'d'},basePath:'a',schemes:['k1'],consumes:['text/b'],produces:['text/i'],paths:{h:{h1:{operationId:'h2'}}},definitions:{c:{type:'c1'}},parameters:{g:{'in':'g1',name:'g2'}},responses:{j:{description:'j1'}},securityDefinitions:{m:{type:'m1'}},security:[{l1:['l2']}],'$ref':'ref'}", t);
+
+ assertEquals("a", t.get("basePath", String.class));
+ assertEquals("['text/b']", t.get("consumes", String.class));
+ assertEquals("{c:{type:'c1'}}", t.get("definitions", String.class));
+ assertEquals("{url:'d'}", t.get("externalDocs", String.class));
+ assertEquals("e", t.get("host", String.class));
+ assertEquals("{title:'f1',version:'f2'}", t.get("info", String.class));
+ assertEquals("{g:{'in':'g1',name:'g2'}}", t.get("parameters", String.class));
+ assertEquals("{h:{h1:{operationId:'h2'}}}", t.get("paths", String.class));
+ assertEquals("['text/i']", t.get("produces", String.class));
+ assertEquals("{j:{description:'j1'}}", t.get("responses", String.class));
+ assertEquals("['k1']", t.get("schemes", String.class));
+ assertEquals("[{l1:['l2']}]", t.get("security", String.class));
+ assertEquals("{m:{type:'m1'}}", t.get("securityDefinitions", String.class));
+ assertEquals("n", t.get("swagger", String.class));
+ assertEquals("[{name:'o'}]", t.get("tags", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(String.class, t.get("basePath", Object.class));
+ assertType(List.class, t.get("consumes", Object.class));
+ assertType(MediaType.class, t.get("consumes", List.class).get(0));
+ assertType(Map.class, t.get("definitions", Object.class));
+ assertType(SchemaInfo.class, t.get("definitions", Map.class).values().iterator().next());
+ assertType(ExternalDocumentation.class, t.get("externalDocs", Object.class));
+ assertType(String.class, t.get("host", Object.class));
+ assertType(Info.class, t.get("info", Object.class));
+ assertType(Map.class, t.get("parameters", Object.class));
+ assertType(ParameterInfo.class, t.get("parameters", Map.class).values().iterator().next());
+ assertType(Map.class, t.get("paths", Object.class));
+ assertType(List.class, t.get("produces", Object.class));
+ assertType(MediaType.class, t.get("consumes", List.class).get(0));
+ assertType(Map.class, t.get("responses", Object.class));
+ assertType(ResponseInfo.class, t.get("responses", Map.class).values().iterator().next());
+ assertType(List.class, t.get("schemes", Object.class));
+ assertType(List.class, t.get("security", Object.class));
+ assertType(Map.class, t.get("securityDefinitions", Object.class));
+ assertType(SecurityScheme.class, t.get("securityDefinitions", Map.class).values().iterator().next());
+ assertType(String.class, t.get("swagger", Object.class));
+ assertType(List.class, t.get("tags", Object.class));
+ assertType(Tag.class, t.get("tags", List.class).get(0));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{swagger:'n',info:{title:'f1',version:'f2'},tags:[{name:'o'}],externalDocs:{url:'d'},basePath:'a',schemes:['k1'],consumes:['text/b'],produces:['text/i'],paths:{h:{h1:{operationId:'h2'}}},definitions:{c:{type:'c1'}},parameters:{g:{'in':'g1',name:'g2'}},responses:{j:{description:'j1'}},securityDefinitions:{m:{type:'m1'}},security:[{l1:['l2']}],'$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, Swagger.class));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/TagTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/TagTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/TagTest.java
new file mode 100644
index 0000000..537301c
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/TagTest.java
@@ -0,0 +1,133 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.juneau.json.*;
+
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+
+import org.junit.*;
+
+/**
+ * Testcase for {@link Tag}.
+ */
+public class TagTest {
+
+ /**
+ * Test method for {@link Tag#name(java.lang.Object)}.
+ */
+ @Test
+ public void testName() {
+ Tag t = new Tag();
+
+ t.name("foo");
+ assertEquals("foo", t.getName());
+
+ t.name(new StringBuilder("foo"));
+ assertEquals("foo", t.getName());
+ assertType(String.class, t.getName());
+
+ t.name(null);
+ assertNull(t.getName());
+ }
+
+ /**
+ * Test method for {@link Tag#description(java.lang.Object)}.
+ */
+ @Test
+ public void testDescription() {
+ Tag t = new Tag();
+
+ t.description("foo");
+ assertEquals("foo", t.getDescription());
+
+ t.description(new StringBuilder("foo"));
+ assertEquals("foo", t.getDescription());
+ assertType(String.class, t.getDescription());
+
+ t.description(null);
+ assertNull(t.getDescription());
+ }
+
+ /**
+ * Test method for {@link Tag#externalDocs(java.lang.Object)}.
+ */
+ @Test
+ public void testExternalDocs() {
+ Tag t = new Tag();
+
+ t.externalDocs(externalDocumentation("foo"));
+ assertObjectEquals("{url:'foo'}", t.getExternalDocs());
+
+ t.externalDocs("{url:'foo'}");
+ assertObjectEquals("{url:'foo'}", t.getExternalDocs());
+ assertType(ExternalDocumentation.class, t.getExternalDocs());
+
+ t.externalDocs(null);
+ assertNull(t.getExternalDocs());
+ }
+
+ /**
+ * Test method for {@link Tag#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ Tag t = new Tag();
+
+ t
+ .set("description", "a")
+ .set("externalDocs", externalDocumentation("b"))
+ .set("name", "c")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{name:'c',description:'a',externalDocs:{url:'b'},'$ref':'ref'}", t);
+
+ t
+ .set("description", "a")
+ .set("externalDocs", "{url:'b'}")
+ .set("name", "c")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{name:'c',description:'a',externalDocs:{url:'b'},'$ref':'ref'}", t);
+
+ t
+ .set("description", new StringBuilder("a"))
+ .set("externalDocs", new StringBuilder("{url:'b'}"))
+ .set("name", new StringBuilder("c"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{name:'c',description:'a',externalDocs:{url:'b'},'$ref':'ref'}", t);
+
+ assertEquals("a", t.get("description", String.class));
+ assertEquals("{url:'b'}", t.get("externalDocs", String.class));
+ assertEquals("c", t.get("name", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(String.class, t.get("description", Object.class));
+ assertType(ExternalDocumentation.class, t.get("externalDocs", Object.class));
+ assertType(String.class, t.get("name", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{name:'c',description:'a',externalDocs:{url:'b'},'$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, Tag.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/XmlTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/XmlTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/XmlTest.java
new file mode 100644
index 0000000..695c1ce
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/XmlTest.java
@@ -0,0 +1,186 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+/**
+ * Testcase for {@link Xml}.
+ */
+public class XmlTest {
+
+ /**
+ * Test method for {@link Xml#name(java.lang.Object)}.
+ */
+ @Test
+ public void testName() {
+ Xml t = new Xml();
+
+ t.name("foo");
+ assertEquals("foo", t.getName());
+
+ t.name(new StringBuilder("foo"));
+ assertEquals("foo", t.getName());
+ assertType(String.class, t.getName());
+
+ t.name(null);
+ assertNull(t.getName());
+ }
+
+ /**
+ * Test method for {@link Xml#namespace(java.lang.Object)}.
+ */
+ @Test
+ public void testNamespace() {
+ Xml t = new Xml();
+
+ t.namespace("foo");
+ assertEquals("foo", t.getNamespace());
+
+ t.namespace(new StringBuilder("foo"));
+ assertEquals("foo", t.getNamespace());
+ assertType(String.class, t.getNamespace());
+
+ t.namespace(null);
+ assertNull(t.getNamespace());
+ }
+
+ /**
+ * Test method for {@link Xml#prefix(java.lang.Object)}.
+ */
+ @Test
+ public void testPrefix() {
+ Xml t = new Xml();
+
+ t.prefix("foo");
+ assertEquals("foo", t.getPrefix());
+
+ t.prefix(new StringBuilder("foo"));
+ assertEquals("foo", t.getPrefix());
+ assertType(String.class, t.getPrefix());
+
+ t.prefix(null);
+ assertNull(t.getPrefix());
+ }
+
+ /**
+ * Test method for {@link Xml#attribute(java.lang.Object)}.
+ */
+ @Test
+ public void testAttribute() {
+ Xml t = new Xml();
+
+ t.attribute(true);
+ assertEquals(true, t.getAttribute());
+ assertType(Boolean.class, t.getAttribute());
+
+ t.attribute("true");
+ assertEquals(true, t.getAttribute());
+ assertType(Boolean.class, t.getAttribute());
+
+ t.attribute(new StringBuilder("true"));
+ assertEquals(true, t.getAttribute());
+ assertType(Boolean.class, t.getAttribute());
+
+ t.attribute(null);
+ assertNull(t.getAttribute());
+ }
+
+ /**
+ * Test method for {@link Xml#wrapped(java.lang.Object)}.
+ */
+ @Test
+ public void testWrapped() {
+ Xml t = new Xml();
+
+ t.wrapped(true);
+ assertEquals(true, t.getWrapped());
+ assertType(Boolean.class, t.getWrapped());
+
+ t.wrapped("true");
+ assertEquals(true, t.getWrapped());
+ assertType(Boolean.class, t.getWrapped());
+
+ t.wrapped(new StringBuilder("true"));
+ assertEquals(true, t.getWrapped());
+ assertType(Boolean.class, t.getWrapped());
+
+ t.wrapped(null);
+ assertNull(t.getWrapped());
+ }
+
+ /**
+ * Test method for {@link Xml#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ Xml t = new Xml();
+
+ t
+ .set("attribute", true)
+ .set("name", "a")
+ .set("namespace", "b")
+ .set("prefix", "c")
+ .set("wrapped", true)
+ .set("$ref", "ref");
+
+ assertObjectEquals("{name:'a',namespace:'b',prefix:'c',attribute:true,wrapped:true,'$ref':'ref'}", t);
+
+ t
+ .set("attribute", "true")
+ .set("name", "a")
+ .set("namespace", "b")
+ .set("prefix", "c")
+ .set("wrapped", "true")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{name:'a',namespace:'b',prefix:'c',attribute:true,wrapped:true,'$ref':'ref'}", t);
+
+ t
+ .set("attribute", new StringBuilder("true"))
+ .set("name", new StringBuilder("a"))
+ .set("namespace", new StringBuilder("b"))
+ .set("prefix", new StringBuilder("c"))
+ .set("wrapped", new StringBuilder("true"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{name:'a',namespace:'b',prefix:'c',attribute:true,wrapped:true,'$ref':'ref'}", t);
+
+ assertEquals("true", t.get("attribute", String.class));
+ assertEquals("a", t.get("name", String.class));
+ assertEquals("b", t.get("namespace", String.class));
+ assertEquals("c", t.get("prefix", String.class));
+ assertEquals("true", t.get("wrapped", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(Boolean.class, t.get("attribute", Object.class));
+ assertType(String.class, t.get("name", Object.class));
+ assertType(String.class, t.get("namespace", Object.class));
+ assertType(String.class, t.get("prefix", Object.class));
+ assertType(Boolean.class, t.get("wrapped", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{name:'a',namespace:'b',prefix:'c',attribute:true,wrapped:true,'$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, Xml.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElement.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElement.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElement.java
index 1ce5ccd..c7047c5 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElement.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElement.java
@@ -137,7 +137,7 @@ public abstract class HtmlElement {
* @return The attribute value, or <jk>null</jk> if the named attribute does not exist.
*/
public <T> T getAttr(Class<T> type, String key) {
- return attrs == null ? null : ObjectUtils.convertToType(attrs.get(key), type);
+ return attrs == null ? null : ObjectUtils.toType(attrs.get(key), type);
}
/**
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementContainer.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementContainer.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementContainer.java
index bae530d..a0a3b48 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementContainer.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementContainer.java
@@ -113,7 +113,7 @@ public class HtmlElementContainer extends HtmlElement {
public <T> T getChild(Class<T> type, int index) {
return (children == null || children.size() <= index || index < 0
? null
- : ObjectUtils.convertToType(children.get(index), type)
+ : ObjectUtils.toType(children.get(index), type)
);
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementMixed.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementMixed.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementMixed.java
index d717973..0255253 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementMixed.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/html5/HtmlElementMixed.java
@@ -114,7 +114,7 @@ public class HtmlElementMixed extends HtmlElement {
return (
children == null || children.size() <= index || index < 0
? null
- : ObjectUtils.convertToType(children.get(index), type)
+ : ObjectUtils.toType(children.get(index), type)
);
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Contact.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Contact.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Contact.java
index e5fbc5b..4587f36 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Contact.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Contact.java
@@ -12,7 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import java.net.*;
import java.net.URI;
@@ -25,6 +25,17 @@ import org.apache.juneau.annotation.*;
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * Contact x = <jsm>contact</jsm>(<js>"API Support"</js>, <js>"http://www.swagger.io/support"</js>, <js>"support@swagger.io"</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'>
+ * <jc>// Output</jc>
* {
* <js>"name"</js>: <js>"API Support"</js>,
* <js>"url"</js>: <js>"http://www.swagger.io/support"</js>,
@@ -34,20 +45,10 @@ import org.apache.juneau.annotation.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="name,url,email")
+@Bean(properties="name,url,email,*")
public class Contact extends SwaggerElement {
private String name;
@@ -60,7 +61,7 @@ public class Contact extends SwaggerElement {
* <p>
* The identifying name of the contact person/organization.
*
- * @return The value of the <property>name</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getName() {
return name;
@@ -72,31 +73,36 @@ public class Contact extends SwaggerElement {
* <p>
* The identifying name of the contact person/organization.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @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 Contact setName(String name) {
- this.name = name;
+ public Contact setName(String value) {
+ name = value;
return this;
}
/**
- * Synonym for {@link #setName(String)}.
+ * Same as {@link #setName(String)}.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Contact name(String name) {
- return setName(name);
+ public Contact name(Object value) {
+ return setName(toStringVal(value));
}
/**
* Bean property getter: <property>url</property>.
*
* <p>
- * The URL pointing to the contact information. MUST be in the format of a URL.
+ * The URL pointing to the contact information.
*
- * @return The value of the <property>url</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public URI getUrl() {
return url;
@@ -107,36 +113,41 @@ public class Contact extends SwaggerElement {
*
* <p>
* The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
- * Strings must be valid URIs.
+ * <br>Strings must be valid URIs.
*
* <p>
* URIs defined by {@link UriResolver} can be used for values.
*
- * @param url The new value for the <property>url</property> property on this bean.
+ * @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 Contact setUrl(Object url) {
- this.url = toURI(url);
+ public Contact setUrl(URI value) {
+ url = value;
return this;
}
/**
- * Synonym for {@link #setUrl(Object)}.
+ * Same as {@link #setUrl(URI)}.
*
- * @param url The new value for the <property>url</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-URI values will be converted to URI using <code><jk>new</jk> URI(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Contact url(Object url) {
- return setUrl(url);
+ public Contact url(Object value) {
+ return setUrl(toURI(value));
}
/**
* Bean property getter: <property>email</property>.
*
* <p>
- * The email address of the contact person/organization. MUST be in the format of an email address.
+ * The email address of the contact person/organization.
*
- * @return The value of the <property>email</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getEmail() {
return email;
@@ -146,23 +157,56 @@ public class Contact extends SwaggerElement {
* Bean property setter: <property>email</property>.
*
* <p>
- * The email address of the contact person/organization. MUST be in the format of an email address.
+ * The email address of the contact person/organization.
*
- * @param email The new value for the <property>email</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>MUST be in the format of an email address.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Contact setEmail(String email) {
- this.email = email;
+ public Contact setEmail(String value) {
+ email = value;
return this;
}
/**
- * Synonym for {@link #setEmail(String)}.
+ * Same as {@link #setEmail(String)}.
*
- * @param email The new value for the <property>email</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>MUST be in the format of an email address.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Contact email(String email) {
- return setEmail(email);
+ public Contact email(Object value) {
+ return setEmail(toStringVal(value));
+ }
+
+ @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 "url": return toType(getUrl(), type);
+ case "email": return toType(getEmail(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public Contact set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "name": return name(value);
+ case "url": return url(value);
+ case "email": return email(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java
index f780486..3b9e02b 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java
@@ -12,7 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
-import static org.apache.juneau.internal.StringUtils.*;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import java.net.*;
import java.net.URI;
@@ -25,6 +25,17 @@ import org.apache.juneau.annotation.*;
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * ExternalDocumentation x = <jsm>externalDocumentation</jsm>(<js>"https://swagger.io"</js>, <js>"Find more info here"</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'>
+ * <jc>// Output</jc>
* {
* <js>"description"</js>: <js>"Find more info here"</js>,
* <js>"url"</js>: <js>"https://swagger.io"</js>
@@ -33,20 +44,10 @@ import org.apache.juneau.annotation.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="description,url")
+@Bean(properties="description,url,*")
public class ExternalDocumentation extends SwaggerElement {
private String description;
@@ -56,10 +57,9 @@ public class ExternalDocumentation extends SwaggerElement {
* Bean property getter: <property>description</property>.
*
* <p>
- * A short description of the target documentation. GFM syntax can be used for rich text representation.
+ * A short description of the target documentation.
*
- * @return
- * The value of the <property>description</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDescription() {
return description;
@@ -69,40 +69,39 @@ public class ExternalDocumentation extends SwaggerElement {
* Bean property setter: <property>description</property>.
*
* <p>
- * A short description of the target documentation. GFM syntax can be used for rich text representation.
+ * A short description of the target documentation.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ExternalDocumentation setDescription(String description) {
- this.description = description;
+ public ExternalDocumentation setDescription(String value) {
+ description = value;
return this;
}
/**
- * Synonym for {@link #setDescription(String)}.
+ * Same as {@link #setDescription(String)}.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ExternalDocumentation description(String description) {
- return setDescription(description);
+ public ExternalDocumentation description(Object value) {
+ return setDescription(toStringVal(value));
}
/**
* Bean property getter: <property>url</property>.
*
* <p>
- * Required. The URL for the target documentation.
- *
- * <p>
- * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
- * Strings must be valid URIs.
- *
- * <p>
- * URIs defined by {@link UriResolver} can be used for values.
+ * The URL for the target documentation.
*
- * @return The value of the <property>url</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public URI getUrl() {
return url;
@@ -112,27 +111,61 @@ public class ExternalDocumentation extends SwaggerElement {
* Bean property setter: <property>url</property>.
*
* <p>
- * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
- * Strings must be valid URIs.
- *
- * <p>
- * URIs defined by {@link UriResolver} can be used for values.
+ * The URL for the target documentation.
*
- * @param url The new value for the <property>url</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
+ * <br>URIs defined by {@link UriResolver} can be used for values.
* @return This object (for method chaining).
*/
- public ExternalDocumentation setUrl(Object url) {
- this.url = toURI(url);
+ public ExternalDocumentation setUrl(URI value) {
+ url = value;
return this;
}
/**
- * Synonym for {@link #setUrl(Object)}.
+ * Same as {@link #setUrl(URI)}.
*
- * @param url The new value for the <property>url</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>URIs defined by {@link UriResolver} can be used for values.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link URI}
+ * <li>{@link URL}
+ * <li>{@link String}
+ * <br>Converted to URI using <code><jk>new</jk> URI(value.toString())</code>.
+ * <li>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public ExternalDocumentation url(Object url) {
- return setUrl(url);
+ public ExternalDocumentation url(Object value) {
+ return setUrl(toURI(value));
+ }
+
+ @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(value);
+ case "url": return url(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
[03/10] juneau git commit: JUNEAU-78
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
index fe27eba..34bef24 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import java.util.*;
import org.apache.juneau.annotation.*;
@@ -28,63 +29,80 @@ import org.apache.juneau.annotation.*;
* Further information about the properties can be found in JSON Schema Core and JSON Schema Validation.
* Unless stated otherwise, the property definitions follow the JSON Schema specification as referenced here.
*
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * SchemaInfo x = <jsm>schemaInfo</jsm>()
+ * .type("string")
+ * .title("foo")
+ *
+ * <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'>
+ * <jc>// Output</jc>
+ * {
+ * <js>"type"</js>: <js>"string"</js>,
+ * <js>"title"</js>: <js>"foo"</js>
+ * }
+ * </p>
+ *
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="format,title,description,default,multipleOf,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,maxProperties,minProperties,required,enum,type,items,allOf,properties,additionalProperties,discriminator,readOnly,xml,externalDocs,example")
-@SuppressWarnings({ "unchecked" })
+@Bean(properties="format,title,description,default,multipleOf,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,maxProperties,minProperties,required,enum,type,items,allOf,properties,additionalProperties,discriminator,readOnly,xml,externalDocs,example,*")
public class SchemaInfo extends SwaggerElement {
- private String format;
- private String title;
- private String description;
- private Object _default;
- private Number multipleOf;
- private Number maximum;
- private Boolean exclusiveMaximum;
- private Number minimum;
- private Boolean exclusiveMinimum;
- private Integer maxLength;
- private Integer minLength;
- private String pattern;
- private Integer maxItems;
- private Integer minItems;
- private Boolean uniqueItems;
- private Integer maxProperties;
- private Integer minProperties;
- private Boolean required;
- private List<Object> _enum;
- private String type;
+ private String
+ format,
+ title,
+ description,
+ pattern,
+ type,
+ discriminator;
+ private Number
+ multipleOf,
+ maximum,
+ minimum;
+ private Integer
+ maxLength,
+ minLength,
+ maxItems,
+ minItems,
+ maxProperties,
+ minProperties;
+ private Boolean
+ exclusiveMaximum,
+ exclusiveMinimum,
+ uniqueItems,
+ required,
+ readOnly;
+ private Object
+ _default,
+ example;
private Items items;
- private List<Object> allOf;
- private Map<String,Map<String,Object>> properties;
- private Map<String,Object> additionalProperties;
- private String discriminator;
- private Boolean readOnly;
private Xml xml;
private ExternalDocumentation externalDocs;
- private Object example;
+ private List<Object>
+ _enum,
+ allOf;
+ private Map<String,Map<String,Object>> properties;
+ private Map<String,Object> additionalProperties;
/**
* Bean property getter: <property>format</property>.
*
- * <p>
- * See <a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a> for further
- * details.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a>
+ * </ul>
*
- * @return The value of the <property>format</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getFormat() {
return format;
@@ -93,32 +111,38 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>format</property>.
*
- * <p>
- * See <a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a> for further
- * details.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a>
+ * </ul>
*
- * @param format The new value for the <property>format</property> property on this bean.
+ * @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 SchemaInfo setFormat(String format) {
- this.format = format;
+ public SchemaInfo setFormat(String value) {
+ format = value;
return this;
}
/**
- * Synonym for {@link #setFormat(String)}.
+ * Same as {@link #setFormat(String)}.
*
- * @param format The new value for the <property>format</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo format(String format) {
- return setFormat(format);
+ public SchemaInfo format(Object value) {
+ return setFormat(toStringVal(value));
}
/**
* Bean property getter: <property>title</property>.
*
- * @return The value of the <property>title</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getTitle() {
return title;
@@ -127,32 +151,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>title</property>.
*
- * @param title The new value for the <property>title</property> property on this bean.
+ * @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 SchemaInfo setTitle(String title) {
- this.title = title;
+ public SchemaInfo setTitle(String value) {
+ title = value;
return this;
}
/**
- * Synonym for {@link #setTitle(String)}.
+ * Same as {@link #setTitle(String)}.
*
- * @param title The new value for the <property>title</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo title(String title) {
- return setTitle(title);
+ public SchemaInfo title(Object value) {
+ return setTitle(toStringVal(value));
}
/**
* Bean property getter: <property>description</property>.
*
- * <p>
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used
- * for rich text representation.
- *
- * @return The value of the <property>description</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDescription() {
return description;
@@ -161,26 +186,28 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>description</property>.
*
- * <p>
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used
- * for rich text representation.
- *
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo setDescription(String description) {
- this.description = description;
+ public SchemaInfo setDescription(String value) {
+ description = value;
return this;
}
/**
- * Synonym for {@link #setDescription(String)}.
+ * Same as {@link #setDescription(String)}.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo description(String description) {
- return setDescription(description);
+ public SchemaInfo description(Object value) {
+ return setDescription(toStringVal(value));
}
/**
@@ -189,7 +216,7 @@ public class SchemaInfo extends SwaggerElement {
* <p>
* Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object.
*
- * @return The value of the <property>default</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Object getDefault() {
return _default;
@@ -201,28 +228,30 @@ public class SchemaInfo extends SwaggerElement {
* <p>
* Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object.
*
- * @param _default The new value for the <property>default</property> property on this bean.
+ * @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 SchemaInfo setDefault(Object _default) {
- this._default = _default;
+ public SchemaInfo setDefault(Object value) {
+ _default = value;
return this;
}
/**
- * Synonym for {@link #setDefault(Object)}.
+ * Same as {@link #setDefault(Object)}.
*
- * @param _default The new value for the <property>default</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public SchemaInfo _default(Object _default) {
- return setDefault(_default);
+ public SchemaInfo _default(Object value) {
+ return setDefault(value);
}
/**
* Bean property getter: <property>multipleOf</property>.
*
- * @return The value of the <property>multipleOf</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMultipleOf() {
return multipleOf;
@@ -231,28 +260,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>multipleOf</property>.
*
- * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @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 SchemaInfo setMultipleOf(Number multipleOf) {
- this.multipleOf = multipleOf;
+ public SchemaInfo setMultipleOf(Number value) {
+ multipleOf = value;
return this;
}
/**
- * Synonym for {@link #setMultipleOf(Number)}.
+ * Same as {@link #setMultipleOf(Number)}.
*
- * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo multipleOf(Number multipleOf) {
- return setMultipleOf(multipleOf);
+ public SchemaInfo multipleOf(Object value) {
+ return setMultipleOf(toNumber(value));
}
/**
* Bean property getter: <property>maximum</property>.
*
- * @return The value of the <property>maximum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMaximum() {
return maximum;
@@ -261,30 +295,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>maximum</property>.
*
- * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @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 SchemaInfo setMaximum(Number maximum) {
- this.maximum = maximum;
+ public SchemaInfo setMaximum(Number value) {
+ maximum = value;
return this;
}
/**
- * Synonym for {@link #setMaximum(Number)}.
+ * Same as {@link #setMaximum(Number)}.
*
- * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo maximum(Number maximum) {
- return setMaximum(maximum);
+ public SchemaInfo maximum(Object value) {
+ return setMaximum(toNumber(value));
}
/**
* Bean property getter: <property>exclusiveMaximum</property>.
*
- * @return
- * The value of the <property>exclusiveMaximum</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getExclusiveMaximum() {
return exclusiveMaximum;
@@ -293,28 +330,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>exclusiveMaximum</property>.
*
- * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @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 SchemaInfo setExclusiveMaximum(Boolean exclusiveMaximum) {
- this.exclusiveMaximum = exclusiveMaximum;
+ public SchemaInfo setExclusiveMaximum(Boolean value) {
+ exclusiveMaximum = value;
return this;
}
/**
- * Synonym for {@link #setExclusiveMaximum(Boolean)}.
+ * Same as {@link #setExclusiveMaximum(Boolean)}.
*
- * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo exclusiveMaximum(Boolean exclusiveMaximum) {
- return setExclusiveMaximum(exclusiveMaximum);
+ public SchemaInfo exclusiveMaximum(Object value) {
+ return setExclusiveMaximum(toBoolean(value));
}
/**
* Bean property getter: <property>minimum</property>.
*
- * @return The value of the <property>minimum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMinimum() {
return minimum;
@@ -323,30 +365,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>minimum</property>.
*
- * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @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 SchemaInfo setMinimum(Number minimum) {
- this.minimum = minimum;
+ public SchemaInfo setMinimum(Number value) {
+ minimum = value;
return this;
}
/**
- * Synonym for {@link #setMinimum(Number)}.
+ * Same as {@link #setMinimum(Number)}.
*
- * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo minimum(Number minimum) {
- return setMinimum(minimum);
+ public SchemaInfo minimum(Object value) {
+ return setMinimum(toNumber(value));
}
/**
* Bean property getter: <property>exclusiveMinimum</property>.
*
- * @return
- * The value of the <property>exclusiveMinimum</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getExclusiveMinimum() {
return exclusiveMinimum;
@@ -355,28 +400,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>exclusiveMinimum</property>.
*
- * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @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 SchemaInfo setExclusiveMinimum(Boolean exclusiveMinimum) {
- this.exclusiveMinimum = exclusiveMinimum;
+ public SchemaInfo setExclusiveMinimum(Boolean value) {
+ exclusiveMinimum = value;
return this;
}
/**
- * Synonym for {@link #setExclusiveMinimum(Boolean)}.
+ * Same as {@link #setExclusiveMinimum(Boolean)}.
*
- * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo exclusiveMinimum(Boolean exclusiveMinimum) {
- return setExclusiveMinimum(exclusiveMinimum);
+ public SchemaInfo exclusiveMinimum(Object value) {
+ return setExclusiveMinimum(toBoolean(value));
}
/**
* Bean property getter: <property>maxLength</property>.
*
- * @return The value of the <property>maxLength</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMaxLength() {
return maxLength;
@@ -385,28 +435,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>maxLength</property>.
*
- * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @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 SchemaInfo setMaxLength(Integer maxLength) {
- this.maxLength = maxLength;
+ public SchemaInfo setMaxLength(Integer value) {
+ maxLength = value;
return this;
}
/**
- * Synonym for {@link #setMaxLength(Integer)}.
+ * Same as {@link #setMaxLength(Integer)}.
*
- * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo maxLength(Integer maxLength) {
- return setMaxLength(maxLength);
+ public SchemaInfo maxLength(Object value) {
+ return setMaxLength(toInteger(value));
}
/**
* Bean property getter: <property>minLength</property>.
*
- * @return The value of the <property>minLength</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMinLength() {
return minLength;
@@ -415,28 +470,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>minLength</property>.
*
- * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @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 SchemaInfo setMinLength(Integer minLength) {
- this.minLength = minLength;
+ public SchemaInfo setMinLength(Integer value) {
+ minLength = value;
return this;
}
/**
- * Synonym for {@link #setMinLength(Integer)}.
+ * Same as {@link #setMinLength(Integer)}.
*
- * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo minLength(Integer minLength) {
- return setMinLength(minLength);
+ public SchemaInfo minLength(Object value) {
+ return setMinLength(toInteger(value));
}
/**
* Bean property getter: <property>pattern</property>.
*
- * @return The value of the <property>pattern</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getPattern() {
return pattern;
@@ -445,28 +505,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>pattern</property>.
*
- * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @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 SchemaInfo setPattern(String pattern) {
- this.pattern = pattern;
+ public SchemaInfo setPattern(String value) {
+ pattern = value;
return this;
}
/**
- * Synonym for {@link #setPattern(String)}.
+ * Same as {@link #setPattern(String)}.
*
- * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo pattern(String pattern) {
- return setPattern(pattern);
+ public SchemaInfo pattern(Object value) {
+ return setPattern(toStringVal(value));
}
/**
* Bean property getter: <property>maxItems</property>.
*
- * @return The value of the <property>maxItems</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMaxItems() {
return maxItems;
@@ -475,28 +540,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>maxItems</property>.
*
- * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @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 SchemaInfo setMaxItems(Integer maxItems) {
- this.maxItems = maxItems;
+ public SchemaInfo setMaxItems(Integer value) {
+ maxItems = value;
return this;
}
/**
- * Synonym for {@link #setMaxItems(Integer)}.
+ * Same as {@link #setMaxItems(Integer)}.
*
- * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo maxItems(Integer maxItems) {
- return setMaxItems(maxItems);
+ public SchemaInfo maxItems(Object value) {
+ return setMaxItems(toInteger(value));
}
/**
* Bean property getter: <property>minItems</property>.
*
- * @return The value of the <property>minItems</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMinItems() {
return minItems;
@@ -505,29 +575,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>minItems</property>.
*
- * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @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 SchemaInfo setMinItems(Integer minItems) {
- this.minItems = minItems;
+ public SchemaInfo setMinItems(Integer value) {
+ minItems = value;
return this;
}
/**
- * Synonym for {@link #setMinItems(Integer)}.
+ * Same as {@link #setMinItems(Integer)}.
*
- * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo minItems(Integer minItems) {
- return setMinItems(minItems);
+ public SchemaInfo minItems(Object value) {
+ return setMinItems(toInteger(value));
}
/**
* Bean property getter: <property>uniqueItems</property>.
*
- * @return The value of the <property>uniqueItems</property> property on this bean, or <jk>null</jk> if it is not
- * set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getUniqueItems() {
return uniqueItems;
@@ -535,29 +609,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>uniqueItems</property>.
*
- * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @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 SchemaInfo setUniqueItems(Boolean uniqueItems) {
- this.uniqueItems = uniqueItems;
+ public SchemaInfo setUniqueItems(Boolean value) {
+ uniqueItems = value;
return this;
}
/**
- * Synonym for {@link #setUniqueItems(Boolean)}.
+ * Same as {@link #setUniqueItems(Boolean)}.
*
- * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo uniqueItems(Boolean uniqueItems) {
- return setUniqueItems(uniqueItems);
+ public SchemaInfo uniqueItems(Object value) {
+ return setUniqueItems(toBoolean(value));
}
/**
* Bean property getter: <property>maxProperties</property>.
*
- * @return The value of the <property>maxProperties</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMaxProperties() {
return maxProperties;
@@ -566,29 +644,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>maxProperties</property>.
*
- * @param maxProperties The new value for the <property>maxProperties</property> property on this bean.
+ * @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 SchemaInfo setMaxProperties(Integer maxProperties) {
- this.maxProperties = maxProperties;
+ public SchemaInfo setMaxProperties(Integer value) {
+ maxProperties = value;
return this;
}
/**
- * Synonym for {@link #setMaxProperties(Integer)}.
+ * Same as {@link #setMaxProperties(Integer)}.
*
- * @param maxProperties The new value for the <property>maxProperties</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo maxProperties(Integer maxProperties) {
- return setMaxProperties(maxProperties);
+ public SchemaInfo maxProperties(Object value) {
+ return setMaxProperties(toInteger(value));
}
/**
* Bean property getter: <property>minProperties</property>.
*
- * @return The value of the <property>minProperties</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMinProperties() {
return minProperties;
@@ -597,28 +679,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>minProperties</property>.
*
- * @param minProperties The new value for the <property>minProperties</property> property on this bean.
+ * @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 SchemaInfo setMinProperties(Integer minProperties) {
- this.minProperties = minProperties;
+ public SchemaInfo setMinProperties(Integer value) {
+ minProperties = value;
return this;
}
/**
- * Synonym for {@link #setMinProperties(Integer)}.
+ * Same as {@link #setMinProperties(Integer)}.
*
- * @param minProperties The new value for the <property>minProperties</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo minProperties(Integer minProperties) {
- return setMinProperties(minProperties);
+ public SchemaInfo minProperties(Object value) {
+ return setMinProperties(toInteger(value));
}
/**
* Bean property getter: <property>required</property>.
*
- * @return The value of the <property>required</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getRequired() {
return required;
@@ -627,28 +714,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>required</property>.
*
- * @param required The new value for the <property>required</property> property on this bean.
+ * @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 SchemaInfo setRequired(Boolean required) {
- this.required = required;
+ public SchemaInfo setRequired(Boolean value) {
+ required = value;
return this;
}
/**
- * Synonym for {@link #setRequired(Boolean)}.
+ * Same as {@link #setRequired(Boolean)}.
*
- * @param required The new value for the <property>required</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo required(Boolean required) {
- return setRequired(required);
+ public SchemaInfo required(Object value) {
+ return setRequired(toBoolean(value));
}
/**
* Bean property getter: <property>enum</property>.
*
- * @return The value of the <property>enum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<Object> getEnum() {
return _enum;
@@ -657,52 +749,66 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>enum</property>.
*
- * @param _enum The new value for the <property>enum</property> property on this bean.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">http://json-schema.org/latest/json-schema-validation.html#anchor76</a>
+ * </ul>
+ *
+ * @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 SchemaInfo setEnum(List<Object> _enum) {
- this._enum = _enum;
+ public SchemaInfo setEnum(Collection<Object> value) {
+ _enum = newList(value);
return this;
}
/**
- * Bean property adder: <property>enum</property>.
+ * Adds one or more values to the <property>enum</property> property.
*
- * @param _enum The new values to add to the <property>enum</property> property on this bean.
- * These can either be individual objects or {@link Collection Collections} of objects.
+ * @param value
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public SchemaInfo addEnum(Object..._enum) {
- for (Object o : _enum) {
- if (o != null) {
- if (o instanceof Collection)
- addEnum((Collection<Object>)o);
- else {
- if (this._enum == null)
- this._enum = new LinkedList<>();
- this._enum.add(o);
- }
- }
- }
+ public SchemaInfo addEnum(Collection<Object> value) {
+ _enum = addToList(_enum, value);
return this;
}
-
- /**
- * Synonym for {@link #addEnum(Object...)}.
- *
- * @param _enum
- * The new values to add to the <property>enum</property> property on this bean.
- * These can either be individual objects or {@link Collection Collections} of objects.
+
+ /**
+ * Adds one or more values to the <property>enum</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Object</code>
+ * <li><code>Collection<Object></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<Object></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * _enum(<js>"['foo','bar']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * _enum(<js>"foo"</js>, <js>"bar"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public SchemaInfo _enum(Object..._enum) {
- return addEnum(_enum);
+ public SchemaInfo _enum(Object...values) {
+ _enum = addToList(_enum, values, Object.class);
+ return this;
}
/**
* Bean property getter: <property>type</property>.
*
- * @return The value of the <property>type</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getType() {
return type;
@@ -711,28 +817,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>type</property>.
*
- * @param type The new value for the <property>type</property> property on this bean.
+ * @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 SchemaInfo setType(String type) {
- this.type = type;
+ public SchemaInfo setType(String value) {
+ type = value;
return this;
}
/**
- * Synonym for {@link #setType(String)}.
+ * Same as {@link #setType(String)}.
*
- * @param type The new value for the <property>type</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo type(String type) {
- return setType(type);
+ public SchemaInfo type(Object value) {
+ return setType(toStringVal(value));
}
/**
* Bean property getter: <property>items</property>.
*
- * @return The value of the <property>items</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Items getItems() {
return items;
@@ -741,28 +852,41 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>items</property>.
*
- * @param items The new value for the <property>items</property> property on this bean.
+ * @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 SchemaInfo setItems(Items items) {
- this.items = items;
+ public SchemaInfo setItems(Items value) {
+ items = value;
return this;
}
/**
- * Synonym for {@link #setItems(Items)}.
+ * Same as {@link #setItems(Items)}.
*
- * @param items The new value for the <property>items</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link Items}
+ * <li><code>String</code> - JSON object representation of {@link Items}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * items(<js>"{type:'type',format:'format',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo items(Items items) {
- return setItems(items);
+ public SchemaInfo items(Object value) {
+ return setItems(toType(value, Items.class));
}
/**
* Bean property getter: <property>allOf</property>.
*
- * @return The value of the <property>allOf</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<Object> getAllOf() {
return allOf;
@@ -771,53 +895,61 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>allOf</property>.
*
- * @param allOf The new value for the <property>allOf</property> property on this bean.
+ * @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 SchemaInfo setAllOf(List<Object> allOf) {
- this.allOf = allOf;
+ public SchemaInfo setAllOf(Collection<Object> value) {
+ allOf = newList(value);
return this;
}
/**
- * Bean property adder: <property>enum</property>.
+ * Adds one or more values to the <property>allOf</property> property.
*
- * @param allOf
- * The new values to add to the <property>allOf</property> property on this bean.
- * These can either be individual objects or {@link Collection Collections} of objects.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public SchemaInfo addAllOf(Object...allOf) {
- for (Object o : allOf) {
- if (o != null) {
- if (o instanceof Collection)
- addAllOf((Collection<Object>)o);
- else {
- if (this.allOf == null)
- this.allOf = new LinkedList<>();
- this.allOf.add(o);
- }
- }
- }
+ public SchemaInfo addAllOf(Collection<Object> values) {
+ allOf = addToList(allOf, values);
return this;
}
/**
- * Synonym for {@link #addAllOf(Object...)}.
- *
- * @param allOf
- * The new values to add to the <property>allOf</property> property on this bean.
- * These can either be individual objects or {@link Collection Collections} of objects.
+ * Adds one or more values to the <property>allOf</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Object</code>
+ * <li><code>Collection<Object></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<Object></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * allOf(<js>"['foo','bar']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * allOf(<js>"foo"</js>, <js>"bar"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public SchemaInfo allOf(Object...allOf) {
- return addAllOf(allOf);
+ public SchemaInfo allOf(Object...values) {
+ allOf = addToList(allOf, values, Object.class);
+ return this;
}
/**
* Bean property getter: <property>properties</property>.
*
- * @return The value of the <property>properties</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,Map<String,Object>> getProperties() {
return properties;
@@ -826,50 +958,56 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>properties</property>.
*
- * @param properties The new value for the <property>properties</property> property on this bean.
+ * @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 SchemaInfo setProperties(Map<String,Map<String,Object>> properties) {
- this.properties = properties;
+ public SchemaInfo setProperties(Map<String,Map<String,Object>> value) {
+ properties = newMap(value);
return this;
}
/**
- * Bean property setter: <property>properties</property>.
+ * Adds one or more values to the <property>properties</property> property.
*
- * @param name The property name.
- * @param propertyProperties The properties of the property.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public SchemaInfo addProperty(String name, Map<String,Object> propertyProperties) {
- if (this.properties == null)
- this.properties = new TreeMap<>();
- this.properties.put(name, propertyProperties);
+ public SchemaInfo addProperties(Map<String,Map<String,Object>> values) {
+ properties = addToMap(properties, values);
return this;
}
/**
- * Synonym for {@link #addProperty(String,Map)}.
+ * Adds one or more values to the <property>properties</property> property.
*
- * @param name The property name.
- * @param propertyProperties The properties of the property.
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,Map<String,Object>></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,Map<String,Object>></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * properties(<js>"{name:{foo:'bar'}}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public SchemaInfo property(String name, Object...propertyProperties) {
- if (propertyProperties.length % 2 != 0)
- throw new RuntimeException("Invalid number of arguments passed to SchemaInfo.property(String,Object...)");
- Map<String,Object> m = new LinkedHashMap<>();
- for (int i = 0; i < propertyProperties.length; i += 2)
- m.put(String.valueOf(propertyProperties[i]), propertyProperties[i+1]);
- return addProperty(name, m);
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public SchemaInfo properties(Object...values) {
+ properties = addToMap((Map)properties, values, String.class, Map.class, String.class, Object.class);
+ return this;
}
/**
* Bean property getter: <property>additionalProperties</property>.
*
- * @return
- * The value of the <property>additionalProperties</property> property on this bean, or <jk>null</jk> if it
- * is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,Object> getAdditionalProperties() {
return additionalProperties;
@@ -878,35 +1016,67 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>additionalProperties</property>.
*
- * @param additionalProperties The new value for the <property>additionalProperties</property> property on this bean.
+ * @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 SchemaInfo setAdditionalProperties(Map<String,Object> additionalProperties) {
- this.additionalProperties = additionalProperties;
+ public SchemaInfo setAdditionalProperties(Map<String,Object> value) {
+ additionalProperties = newMap(value);
return this;
}
/**
- * Synonym for {@link #setAdditionalProperties(Map)}.
+ * Adds one or more values to the <property>additionalProperties</property> property.
*
- * @param additionalProperties The new value for the <property>additionalProperties</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public SchemaInfo additionalProperties(Object...additionalProperties) {
- if (additionalProperties.length % 2 != 0)
- throw new RuntimeException("Invalid number of arguments passed to SchemaInfo.additionalProperties(Object...)");
- Map<String,Object> m = new LinkedHashMap<>();
- for (int i = 0; i < additionalProperties.length; i += 2)
- m.put(String.valueOf(additionalProperties[i]), additionalProperties[i+1]);
- return setAdditionalProperties(m);
+ public SchemaInfo addAdditionalProperties(Map<String,Object> values) {
+ additionalProperties = addToMap(additionalProperties, values);
+ return this;
+ }
+
+ /**
+ * Adds a single value to the <property>additionalProperties</property> property.
+ *
+ * @param name The extra property name.
+ * @param value The extra property value.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo additionalProperty(String name, Object value) {
+ additionalProperties = addToMap(additionalProperties, name, value);
+ return this;
+ }
+
+ /**
+ * Adds one or more values to the <property>properties</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,Object></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,Object></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * extraProperties(<js>"{name:'value'}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo additionalProperties(Object...values) {
+ additionalProperties = addToMap(additionalProperties, values, String.class, Object.class);
+ return this;
}
/**
* Bean property getter: <property>discriminator</property>.
*
- * @return
- * The value of the <property>discriminator</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDiscriminator() {
return discriminator;
@@ -915,28 +1085,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>discriminator</property>.
*
- * @param discriminator The new value for the <property>discriminator</property> property on this bean.
+ * @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 SchemaInfo setDiscriminator(String discriminator) {
- this.discriminator = discriminator;
+ public SchemaInfo setDiscriminator(String value) {
+ discriminator = value;
return this;
}
/**
- * Synonym for {@link #setDiscriminator(String)}.
+ * Same as {@link #setDiscriminator(String)}.
*
- * @param discriminator The new value for the <property>discriminator</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo discriminator(String discriminator) {
- return setDiscriminator(discriminator);
+ public SchemaInfo discriminator(Object value) {
+ return setDiscriminator(toStringVal(value));
}
/**
* Bean property getter: <property>readOnly</property>.
*
- * @return The value of the <property>readOnly</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getReadOnly() {
return readOnly;
@@ -945,28 +1120,33 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>readOnly</property>.
*
- * @param readOnly The new value for the <property>readOnly</property> property on this bean.
+ * @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 SchemaInfo setReadOnly(Boolean readOnly) {
- this.readOnly = readOnly;
+ public SchemaInfo setReadOnly(Boolean value) {
+ readOnly = value;
return this;
}
/**
- * Synonym for {@link #setReadOnly(Boolean)}.
+ * Same as {@link #setReadOnly(Boolean)}.
*
- * @param readOnly The new value for the <property>readOnly</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo readOnly(Boolean readOnly) {
- return setReadOnly(readOnly);
+ public SchemaInfo readOnly(Object value) {
+ return setReadOnly(toBoolean(value));
}
/**
* Bean property getter: <property>xml</property>.
*
- * @return The value of the <property>xml</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Xml getXml() {
return xml;
@@ -975,30 +1155,41 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>xml</property>.
*
- * @param xml The new value for the <property>xml</property> property on this bean.
+ * @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 SchemaInfo setXml(Xml xml) {
- this.xml = xml;
+ public SchemaInfo setXml(Xml value) {
+ xml = value;
return this;
}
/**
- * Synonym for {@link #setXml(Xml)}.
+ * Same as {@link #setXml(Xml)}.
*
- * @param xml The new value for the <property>xml</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link Xml}
+ * <li><code>String</code> - JSON object representation of {@link Xml}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * xml(<js>"{name:'name',namespace:'namespace',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SchemaInfo xml(Xml xml) {
- return setXml(xml);
+ public SchemaInfo xml(Object value) {
+ return setXml(toType(value, Xml.class));
}
/**
* Bean property getter: <property>externalDocs</property>.
*
- * @return
- * The value of the <property>externalDocs</property> property on this bean, or <jk>null</jk> if it is not
- * set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public ExternalDocumentation getExternalDocs() {
return externalDocs;
@@ -1007,28 +1198,41 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>externalDocs</property>.
*
- * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @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 SchemaInfo setExternalDocs(ExternalDocumentation externalDocs) {
- this.externalDocs = externalDocs;
+ public SchemaInfo setExternalDocs(ExternalDocumentation value) {
+ externalDocs = value;
return this;
}
/**
- * Synonym for {@link #setExternalDocs(ExternalDocumentation)}.
+ * Same as {@link #setExternalDocs(ExternalDocumentation)}.
*
- * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link ExternalDocumentation}
+ * <li><code>String</code> - JSON object representation of {@link ExternalDocumentation}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * 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 SchemaInfo externalDocs(ExternalDocumentation externalDocs) {
- return setExternalDocs(externalDocs);
+ public SchemaInfo externalDocs(Object value) {
+ return setExternalDocs(toType(value, ExternalDocumentation.class));
}
/**
* Bean property getter: <property>example</property>.
*
- * @return The value of the <property>example</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Object getExample() {
return example;
@@ -1037,21 +1241,103 @@ public class SchemaInfo extends SwaggerElement {
/**
* Bean property setter: <property>example</property>.
*
- * @param example The new value for the <property>example</property> property on this bean.
+ * @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 SchemaInfo setExample(Object example) {
- this.example = example;
+ public SchemaInfo setExample(Object value) {
+ example = value;
return this;
}
/**
- * Synonym for {@link #setExample(Object)}.
+ * Same as {@link #setExample(Object)}.
*
- * @param example The new value for the <property>example</property> property on this bean.
+ * @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 SchemaInfo example(Object example) {
- return setExample(example);
+ public SchemaInfo example(Object value) {
+ return setExample(value);
+ }
+
+ @Override /* SwaggerElement */
+ public <T> T get(String property, Class<T> type) {
+ if (property == null)
+ return null;
+ switch (property) {
+ case "format": return toType(getFormat(), type);
+ case "title": return toType(getTitle(), type);
+ case "description": return toType(getDescription(), type);
+ case "default": return toType(getDefault(), type);
+ case "multipleOf": return toType(getMultipleOf(), type);
+ case "maximum": return toType(getMaximum(), type);
+ case "exclusiveMaximum": return toType(getExclusiveMaximum(), type);
+ case "minimum": return toType(getMinimum(), type);
+ case "exclusiveMinimum": return toType(getExclusiveMinimum(), type);
+ case "maxLength": return toType(getMaxLength(), type);
+ case "minLength": return toType(getMinLength(), type);
+ case "pattern": return toType(getPattern(), type);
+ case "maxItems": return toType(getMaxItems(), type);
+ case "minItems": return toType(getMinItems(), type);
+ case "uniqueItems": return toType(getUniqueItems(), type);
+ case "maxProperties": return toType(getMaxProperties(), type);
+ case "minProperties": return toType(getMinProperties(), type);
+ case "required": return toType(getRequired(), type);
+ case "enum": return toType(getEnum(), type);
+ case "type": return toType(getType(), type);
+ case "items": return toType(getItems(), type);
+ case "allOf": return toType(getAllOf(), type);
+ case "properties": return toType(getProperties(), type);
+ case "additionalProperties": return toType(getAdditionalProperties(), type);
+ case "discriminator": return toType(getDiscriminator(), type);
+ case "readOnly": return toType(getReadOnly(), type);
+ case "xml": return toType(getXml(), type);
+ case "externalDocs": return toType(getExternalDocs(), type);
+ case "example": return toType(getExample(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public SchemaInfo set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "format": return format(value);
+ case "title": return title(value);
+ case "description": return description(value);
+ case "default": return _default(value);
+ case "multipleOf": return multipleOf(value);
+ case "maximum": return maximum(value);
+ case "exclusiveMaximum": return exclusiveMaximum(value);
+ case "minimum": return minimum(value);
+ case "exclusiveMinimum": return exclusiveMinimum(value);
+ case "maxLength": return maxLength(value);
+ case "minLength": return minLength(value);
+ case "pattern": return pattern(value);
+ case "maxItems": return maxItems(value);
+ case "minItems": return minItems(value);
+ case "uniqueItems": return uniqueItems(value);
+ case "maxProperties": return maxProperties(value);
+ case "minProperties": return minProperties(value);
+ case "required": return required(value);
+ case "enum": return setEnum(null)._enum(value);
+ case "type": return type(value);
+ case "items": return items(value);
+ case "allOf": return setAllOf(null).allOf(value);
+ case "properties": return setProperties(null).properties(value);
+ case "additionalProperties": return setAdditionalProperties(null).additionalProperties(value);
+ case "discriminator": return discriminator(value);
+ case "readOnly": return readOnly(value);
+ case "xml": return xml(value);
+ case "externalDocs": return externalDocs(value);
+ case "example": return example(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java
index 5ef3383..92097de 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import static org.apache.juneau.internal.ArrayUtils.*;
import java.util.*;
@@ -54,31 +55,22 @@ import org.apache.juneau.annotation.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="type,description,name,in,flow,authorizationUrl,tokenUrl,scopes")
+@Bean(properties="type,description,name,in,flow,authorizationUrl,tokenUrl,scopes,*")
public class SecurityScheme extends SwaggerElement {
private static final String[] VALID_TYPES = {"basic", "apiKey", "oauth2"};
- private String type;
- private String description;
- private String name;
- private String in;
- private String flow;
- private String authorizationUrl;
- private String tokenUrl;
+ private String
+ type,
+ description,
+ name,
+ in,
+ flow,
+ authorizationUrl,
+ tokenUrl;
private Map<String,String> scopes;
@Override /* SwaggerElement */
@@ -91,12 +83,9 @@ public class SecurityScheme extends SwaggerElement {
* Bean property getter: <property>type</property>.
*
* <p>
- * Required. The type of the security scheme.
+ * The type of the security scheme.
*
- * <p>
- * Valid values are <js>"basic"</js>, <js>"apiKey"</js> or <js>"oauth2"</js>.
- *
- * @return The value of the <property>type</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getType() {
return type;
@@ -106,32 +95,49 @@ public class SecurityScheme extends SwaggerElement {
* Bean property setter: <property>type</property>.
*
* <p>
- * Required. The type of the security scheme.
+ * The type of the security scheme.
*
* <p>
- * Valid values are <js>"basic"</js>, <js>"apiKey"</js> or <js>"oauth2"</js>.
- *
- * @param type The new value for the <property>type</property> property on this bean.
+ * Valid values are .
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"basic"</js>
+ * <li><js>"apiKey"</js>
+ * <li><js>"oauth2"</js>
+ * </ul>
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public SecurityScheme setType(String type) {
- if (isStrict() && ! contains(type, VALID_TYPES))
+ public SecurityScheme setType(String value) {
+ if (isStrict() && ! contains(value, VALID_TYPES))
throw new FormattedRuntimeException(
"Invalid value passed in to setType(String). Value=''{0}'', valid values={1}",
- type, VALID_TYPES
+ value, VALID_TYPES
);
- this.type = type;
+ type = value;
return this;
}
/**
- * Synonym for {@link #setType(String)}.
- *
- * @param type The new value for the <property>type</property> property on this bean.
+ * Same as {@link #setType(String)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"basic"</js>
+ * <li><js>"apiKey"</js>
+ * <li><js>"oauth2"</js>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme type(String type) {
- return setType(type);
+ public SecurityScheme type(Object value) {
+ return setType(toStringVal(value));
}
/**
@@ -140,8 +146,7 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* A short description for security scheme.
*
- * @return
- * The value of the <property>description</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDescription() {
return description;
@@ -153,22 +158,27 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* A short description for security scheme.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @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 SecurityScheme setDescription(String description) {
- this.description = description;
+ public SecurityScheme setDescription(String value) {
+ description = value;
return this;
}
/**
- * Synonym for {@link #setDescription(String)}.
+ * Same as {@link #setDescription(String)}.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme description(String description) {
- return setDescription(description);
+ public SecurityScheme description(Object value) {
+ return setDescription(toStringVal(value));
}
/**
@@ -177,7 +187,7 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The name of the header or query parameter to be used.
*
- * @return The value of the <property>name</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getName() {
return name;
@@ -189,31 +199,36 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The name of the header or query parameter to be used.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @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 SecurityScheme setName(String name) {
- this.name = name;
+ public SecurityScheme setName(String value) {
+ name = value;
return this;
}
/**
- * Synonym for {@link #setName(String)}.
+ * Same as {@link #setName(String)}.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme name(String name) {
- return setName(name);
+ public SecurityScheme name(Object value) {
+ return setName(toStringVal(value));
}
/**
* Bean property getter: <property>in</property>.
*
* <p>
- * The location of the API key. Valid values are <js>"query"</js> or <js>"header"</js>.
+ * The location of the API key.
*
- * @return The value of the <property>in</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getIn() {
return in;
@@ -223,24 +238,39 @@ public class SecurityScheme extends SwaggerElement {
* Bean property setter: <property>in</property>.
*
* <p>
- * The location of the API key. Valid values are <js>"query"</js> or <js>"header"</js>.
- *
- * @param in The new value for the <property>in</property> property on this bean.
+ * The location of the API key.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"query"</js>
+ * <li><js>"header"</js>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme setIn(String in) {
- this.in = in;
+ public SecurityScheme setIn(String value) {
+ in = value;
return this;
}
/**
- * Synonym for {@link #setIn(String)}.
- *
- * @param in The new value for the <property>in</property> property on this bean.
+ * Same as {@link #setIn(String)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"query"</js>
+ * <li><js>"header"</js>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme in(String in) {
- return setIn(in);
+ public SecurityScheme in(Object value) {
+ return setIn(toStringVal(value));
}
/**
@@ -249,10 +279,7 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The flow used by the OAuth2 security scheme.
*
- * <p>
- * Valid values are <js>"implicit"</js>, <js>"password"</js>, <js>"application"</js> or <js>"accessCode"</js>.
- *
- * @return The value of the <property>flow</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getFlow() {
return flow;
@@ -264,25 +291,41 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The flow used by the OAuth2 security scheme.
*
- * <p>
- * Valid values are <js>"implicit"</js>, <js>"password"</js>, <js>"application"</js> or <js>"accessCode"</js>.
- *
- * @param flow The new value for the <property>flow</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"implicit"</js>
+ * <li><js>"password"</js>
+ * <li><js>"application"</js>
+ * <li><js>"accessCode"</js>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme setFlow(String flow) {
- this.flow = flow;
+ public SecurityScheme setFlow(String value) {
+ flow = value;
return this;
}
/**
- * Synonym for {@link #setFlow(String)}.
- *
- * @param flow The new value for the <property>flow</property> property on this bean.
+ * Same as {@link #setFlow(String)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"implicit"</js>
+ * <li><js>"password"</js>
+ * <li><js>"application"</js>
+ * <li><js>"accessCode"</js>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme flow(String flow) {
- return setFlow(flow);
+ public SecurityScheme flow(Object value) {
+ return setFlow(toStringVal(value));
}
/**
@@ -291,12 +334,7 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The authorization URL to be used for this flow.
*
- * <p>
- * This SHOULD be in the form of a URL.
- *
- * @return
- * The value of the <property>authorizationUrl</property> property on this bean, or <jk>null</jk> if it
- * is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getAuthorizationUrl() {
return authorizationUrl;
@@ -308,25 +346,29 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The authorization URL to be used for this flow.
*
- * <p>
- * This SHOULD be in the form of a URL.
- *
- * @param authorizationUrl The new value for the <property>authorizationUrl</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>This SHOULD be in the form of a URL.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme setAuthorizationUrl(String authorizationUrl) {
- this.authorizationUrl = authorizationUrl;
+ public SecurityScheme setAuthorizationUrl(String value) {
+ authorizationUrl = value;
return this;
}
/**
- * Synonym for {@link #setAuthorizationUrl(String)}.
+ * Same as {@link #setAuthorizationUrl(String)}.
*
- * @param authorizationUrl The new value for the <property>authorizationUrl</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>This SHOULD be in the form of a URL.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme authorizationUrl(String authorizationUrl) {
- return setAuthorizationUrl(authorizationUrl);
+ public SecurityScheme authorizationUrl(Object value) {
+ return setAuthorizationUrl(toStringVal(value));
}
/**
@@ -335,10 +377,7 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The token URL to be used for this flow.
*
- * <p>
- * This SHOULD be in the form of a URL.
- *
- * @return The value of the <property>tokenUrl</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getTokenUrl() {
return tokenUrl;
@@ -350,25 +389,29 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The token URL to be used for this flow.
*
- * <p>
- * This SHOULD be in the form of a URL.
- *
- * @param tokenUrl The new value for the <property>tokenUrl</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>This SHOULD be in the form of a URL.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme setTokenUrl(String tokenUrl) {
- this.tokenUrl = tokenUrl;
+ public SecurityScheme setTokenUrl(String value) {
+ tokenUrl = value;
return this;
}
/**
- * Synonym for {@link #setTokenUrl(String)}.
+ * Same as {@link #setTokenUrl(String)}.
*
- * @param tokenUrl The new value for the <property>tokenUrl</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>This SHOULD be in the form of a URL.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public SecurityScheme tokenUrl(String tokenUrl) {
- return setTokenUrl(tokenUrl);
+ public SecurityScheme tokenUrl(Object value) {
+ return setTokenUrl(toStringVal(value));
}
/**
@@ -377,7 +420,7 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The available scopes for the OAuth2 security scheme.
*
- * @return The value of the <property>scopes</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,String> getScopes() {
return scopes;
@@ -389,39 +432,84 @@ public class SecurityScheme extends SwaggerElement {
* <p>
* The available scopes for the OAuth2 security scheme.
*
- * @param scopes The new value for the <property>scopes</property> property on this bean.
+ * @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 SecurityScheme setScopes(Map<String,String> scopes) {
- this.scopes = scopes;
+ public SecurityScheme setScopes(Map<String,String> value) {
+ scopes = newMap(value);
return this;
}
/**
- * Bean property adder: <property>scopes</property>.
- *
- * <p>
- * The available scopes for the OAuth2 security scheme.
+ * Adds one or more values to the <property>scopes</property> property.
*
- * @param name The name of the scope.
- * @param description A short description of the scope.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public SecurityScheme addScope(String name, String description) {
- if (scopes == null)
- scopes = new TreeMap<>();
- scopes.put(name, description);
+ public SecurityScheme addScopes(Map<String,String> values) {
+ scopes = addToMap(scopes, values);
return this;
}
-
+
/**
- * Synonym for {@link #addScope(String,String)}.
- *
- * @param name The name of the scope.
- * @param description A short description of the scope.
+ * Adds one or more values to the <property>enum</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,{@link HeaderInfo}|String></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,{@link HeaderInfo}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * scopes(<js>"{name:'value'}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public SecurityScheme scope(String name, String description) {
- return addScope(name, description);
+ public SecurityScheme scopes(Object...values) {
+ scopes = addToMap(scopes, values, String.class, String.class);
+ return this;
+ }
+
+ @Override /* SwaggerElement */
+ public <T> T get(String property, Class<T> type) {
+ if (property == null)
+ return null;
+ switch (property) {
+ case "type": return toType(getType(), type);
+ case "description": return toType(getDescription(), type);
+ case "name": return toType(getName(), type);
+ case "in": return toType(getIn(), type);
+ case "flow": return toType(getFlow(), type);
+ case "authorizationUrl": return toType(getAuthorizationUrl(), type);
+ case "tokenUrl": return toType(getTokenUrl(), type);
+ case "scopes": return toType(getScopes(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public SecurityScheme set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "type": return type(value);
+ case "description": return description(value);
+ case "name": return name(value);
+ case "in": return in(value);
+ case "flow": return flow(value);
+ case "authorizationUrl": return authorizationUrl(value);
+ case "tokenUrl": return tokenUrl(value);
+ case "scopes": return setScopes(null).scopes(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
[06/10] juneau git commit: JUNEAU-78
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Items.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Items.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Items.java
index c5a4793..3956827 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Items.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Items.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import static org.apache.juneau.internal.ArrayUtils.*;
import java.util.*;
@@ -25,6 +26,17 @@ import org.apache.juneau.json.*;
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * Items x = <jsm>items</jsm>(<js>"string"</js>).minLength(2);
+ *
+ * <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'>
+ * <jc>// Output</jc>
* {
* <js>"type"</js>: <js>"string"</js>,
* <js>"minLength"</js>: 2
@@ -33,43 +45,36 @@ import org.apache.juneau.json.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="type,format,items,collectionFormat,default,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,enum,multipleOf")
-@SuppressWarnings({ "unchecked" })
+@Bean(properties="type,format,items,collectionFormat,default,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,enum,multipleOf,*")
public class Items extends SwaggerElement {
private static final String[] VALID_TYPES = {"string", "number", "integer", "boolean", "array"};
private static final String[] VALID_COLLECTION_FORMATS = {"csv","ssv","tsv","pipes","multi"};
- private String type;
- private String format;
+ private String
+ type,
+ format,
+ collectionFormat,
+ pattern;
+ private Number
+ maximum,
+ minimum,
+ multipleOf;
+ private Integer
+ maxLength,
+ minLength,
+ maxItems,
+ minItems;
+ private Boolean
+ exclusiveMaximum,
+ exclusiveMinimum,
+ uniqueItems;
private Items items;
- private String collectionFormat;
private Object _default;
- private Number maximum;
- private Boolean exclusiveMaximum;
- private Number minimum;
- private Boolean exclusiveMinimum;
- private Integer maxLength;
- private Integer minLength;
- private String pattern;
- private Integer maxItems;
- private Integer minItems;
- private Boolean uniqueItems;
private List<Object> _enum;
- private Number multipleOf;
@Override /* SwaggerElement */
protected Items strict() {
@@ -81,11 +86,9 @@ public class Items extends SwaggerElement {
* Bean property getter: <property>type</property>.
*
* <p>
- * Required. The internal type of the array.
- * The value MUST be one of <js>"string"</js>, <js>"number"</js>, <js>"integer"</js>, <js>"boolean"</js>, or
- * <js>"array"</js>.
+ * The internal type of the array.
*
- * @return The value of the <property>type</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getType() {
return type;
@@ -95,40 +98,63 @@ public class Items extends SwaggerElement {
* Bean property setter: <property>type</property>.
*
* <p>
- * Required. The internal type of the array.
- * The value MUST be one of <js>"string"</js>, <js>"number"</js>, <js>"integer"</js>, <js>"boolean"</js>, or
- * <js>"array"</js>.
+ * The internal type of the array.
*
- * @param type The new value for the <property>type</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"string"</js>
+ * <li><js>"number"</js>
+ * <li><js>"integer"</js>
+ * <li><js>"boolean"</js>
+ * <li><js>"array"</js>
+ * </ul>
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public Items setType(String type) {
- if (isStrict() && ! contains(type, VALID_TYPES))
+ public Items setType(String value) {
+ if (isStrict() && ! contains(value, VALID_TYPES))
throw new RuntimeException(
- "Invalid value passed in to setType(String). Value='"+type+"', valid values="
+ "Invalid value passed in to setType(String). Value='"+value+"', valid values="
+ JsonSerializer.DEFAULT_LAX.toString(VALID_TYPES));
- this.type = type;
+ type = value;
return this;
}
/**
- * Synonym for {@link #setType(String)}.
+ * Same as {@link #setType(String)}.
*
- * @param type The new value for the <property>type</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"string"</js>
+ * <li><js>"number"</js>
+ * <li><js>"integer"</js>
+ * <li><js>"boolean"</js>
+ * <li><js>"array"</js>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items type(String type) {
- return setType(type);
+ public Items type(Object value) {
+ return setType(toStringVal(value));
}
/**
* Bean property getter: <property>format</property>.
*
* <p>
- * The extending format for the previously mentioned <code>type</code>. See <a class="doclink"
- * href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a> for further details.
+ * The extending format for the previously mentioned <code>type</code>.
*
- * @return The value of the <property>format</property> property on this bean, or <jk>null</jk> if it is not set.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a>
+ * </ul>
+ *
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getFormat() {
return format;
@@ -138,35 +164,43 @@ public class Items extends SwaggerElement {
* Bean property setter: <property>format</property>.
*
* <p>
- * The extending format for the previously mentioned <code>type</code>. See <a class="doclink"
- * href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a> for further details.
+ * The extending format for the previously mentioned <code>type</code>.
+ *
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a>
+ * </ul>
*
- * @param format The new value for the <property>format</property> property on this bean.
+ * @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 Items setFormat(String format) {
- this.format = format;
+ public Items setFormat(String value) {
+ format = value;
return this;
}
/**
- * Synonym for {@link #setFormat(String)}.
+ * Same as {@link #setFormat(String)}.
*
- * @param format The new value for the <property>format</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items format(String format) {
- return setFormat(format);
+ public Items format(Object value) {
+ return setFormat(toStringVal(value));
}
/**
* Bean property getter: <property>items</property>.
*
* <p>
- * Required if <code>type</code> is <js>"array"</js>.
* Describes the type of items in the array.
*
- * @return The value of the <property>items</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Items getItems() {
return items;
@@ -176,25 +210,39 @@ public class Items extends SwaggerElement {
* Bean property setter: <property>items</property>.
*
* <p>
- * Required if <code>type</code> is <js>"array"</js>.
* Describes the type of items in the array.
*
- * @param items The new value for the <property>items</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required if <code>type</code> is <js>"array"</js>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items setItems(Items items) {
- this.items = items;
+ public Items setItems(Items value) {
+ items = value;
return this;
}
/**
- * Synonym for {@link #setItems(Items)}.
+ * Same as {@link #setItems(Items)}.
*
- * @param items The new value for the <property>items</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required if <code>type</code> is <js>"array"</js>.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link Items}
+ * <li><code>String</code> - JSON object representation of {@link Items}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * items(<js>"{type:'type',format:'format',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items items(Items items) {
- return setItems(items);
+ public Items items(Object value) {
+ return setItems(toType(value, Items.class));
}
/**
@@ -203,21 +251,7 @@ public class Items extends SwaggerElement {
* <p>
* Determines the format of the array if type array is used.
*
- * <p>
- * Possible values are:
- * <ul>
- * <li><code>csv</code> - comma separated values <code>foo,bar</code>.
- * <li><code>ssv</code> - space separated values <code>foo bar</code>.
- * <li><code>tsv</code> - tab separated values <code>foo\tbar</code>.
- * <li><code>pipes</code> - pipe separated values <code>foo|bar</code>.
- * </ul>
- *
- * <p>
- * Default value is <code>csv</code>.
- *
- * @return
- * The value of the <property>collectionFormat</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getCollectionFormat() {
return collectionFormat;
@@ -229,39 +263,46 @@ public class Items extends SwaggerElement {
* <p>
* Determines the format of the array if type array is used.
*
- * <p>
- * Possible values are:
- * <ul>
- * <li><code>csv</code> - comma separated values <code>foo,bar</code>.
- * <li><code>ssv</code> - space separated values <code>foo bar</code>.
- * <li><code>tsv</code> - tab separated values <code>foo\tbar</code>.
- * <li><code>pipes</code> - pipe separated values <code>foo|bar</code>.
- * </ul>
- *
- * <p>
- * Default value is <code>csv</code>.
- *
- * @param collectionFormat The new value for the <property>collectionFormat</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"csv"</js> (default) - comma separated values <code>foo,bar</code>.
+ * <li><js>"ssv"</js> - space separated values <code>foo bar</code>.
+ * <li><js>"tsv"</js> - tab separated values <code>foo\tbar</code>.
+ * <li><js>"pipes"</js> - pipe separated values <code>foo|bar</code>.
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items setCollectionFormat(String collectionFormat) {
- if (isStrict() && ! contains(collectionFormat, VALID_COLLECTION_FORMATS))
+ public Items setCollectionFormat(String value) {
+ if (isStrict() && ! contains(value, VALID_COLLECTION_FORMATS))
throw new FormattedRuntimeException(
"Invalid value passed in to setCollectionFormat(String). Value=''{0}'', valid values={1}",
- collectionFormat, VALID_COLLECTION_FORMATS
+ value, VALID_COLLECTION_FORMATS
);
- this.collectionFormat = collectionFormat;
+ collectionFormat = value;
return this;
}
/**
- * Synonym for {@link #setCollectionFormat(String)}.
+ * Same as {@link #setCollectionFormat(String)}.
*
- * @param collectionFormat The new value for the <property>collectionFormat</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"csv"</js> (default) - comma separated values <code>foo,bar</code>.
+ * <li><js>"ssv"</js> - space separated values <code>foo bar</code>.
+ * <li><js>"tsv"</js> - tab separated values <code>foo\tbar</code>.
+ * <li><js>"pipes"</js> - pipe separated values <code>foo|bar</code>.
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items collectionFormat(String collectionFormat) {
- return setCollectionFormat(collectionFormat);
+ public Items collectionFormat(Object value) {
+ return setCollectionFormat(toStringVal(value));
}
/**
@@ -269,12 +310,19 @@ public class Items extends SwaggerElement {
*
* <p>
* Declares the value of the item that the server will use if none is provided.
- * (Note: <js>"default"</js> has no meaning for required items.)
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">
- * http://json-schema.org/latest/json-schema-validation.html#anchor101</a>.
- * Unlike JSON Schema this value MUST conform to the defined <code>type</code> for the data type.
*
- * @return The value of the <property>default</property> property on this bean, or <jk>null</jk> if it is not set.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li><js>"default"</js> has no meaning for required items.
+ * <li>Unlike JSON Schema this value MUST conform to the defined <code>type</code> for the data type.
+ * </ul>
+ *
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">http://json-schema.org/latest/json-schema-validation.html#anchor101</a>
+ * </ul>
+ *
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Object getDefault() {
return _default;
@@ -285,37 +333,49 @@ public class Items extends SwaggerElement {
*
* <p>
* Declares the value of the item that the server will use if none is provided.
- * (Note: <js>"default"</js> has no meaning for required items.)
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">
- * http://json-schema.org/latest/json-schema-validation.html#anchor101</a>.
- * Unlike JSON Schema this value MUST conform to the defined <code>type</code> for the data type.
*
- * @param _default The new value for the <property>default</property> property on this bean.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li><js>"default"</js> has no meaning for required items.
+ * <li>Unlike JSON Schema this value MUST conform to the defined <code>type</code> for the data type.
+ * </ul>
+ *
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">http://json-schema.org/latest/json-schema-validation.html#anchor101</a>
+ * </ul>
+ *
+ * @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 Items setDefault(Object _default) {
- this._default = _default;
+ public Items setDefault(Object value) {
+ _default = value;
return this;
}
/**
- * Synonym for {@link #setDefault(Object)}.
+ * Same as {@link #setDefault(Object)}.
*
- * @param _default The new value for the <property>default</property> property on this bean.
+ * @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 Items _default(Object _default) {
- return setDefault(_default);
+ public Items _default(Object value) {
+ return setDefault(value);
}
/**
* Bean property getter: <property>maximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @return The value of the <property>maximum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMaximum() {
return maximum;
@@ -324,38 +384,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>maximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @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 Items setMaximum(Number maximum) {
- this.maximum = maximum;
+ public Items setMaximum(Number value) {
+ maximum = value;
return this;
}
/**
- * Synonym for {@link #setMaximum(Number)}.
+ * Same as {@link #setMaximum(Number)}.
*
- * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items maximum(Number maximum) {
- return setMaximum(maximum);
+ public Items maximum(Object value) {
+ return setMaximum(toNumber(value));
}
/**
* Bean property getter: <property>exclusiveMaximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @return
- * The value of the <property>exclusiveMaximum</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getExclusiveMaximum() {
return exclusiveMaximum;
@@ -364,36 +429,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>exclusiveMaximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @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 Items setExclusiveMaximum(Boolean exclusiveMaximum) {
- this.exclusiveMaximum = exclusiveMaximum;
+ public Items setExclusiveMaximum(Boolean value) {
+ exclusiveMaximum = value;
return this;
}
/**
- * Synonym for {@link #setExclusiveMaximum(Boolean)}.
+ * Same as {@link #setExclusiveMaximum(Boolean)}.
*
- * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items exclusiveMaximum(Boolean exclusiveMaximum) {
- return setExclusiveMaximum(exclusiveMaximum);
+ public Items exclusiveMaximum(Object value) {
+ return setExclusiveMaximum(toBoolean(value));
}
/**
* Bean property getter: <property>minimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @return The value of the <property>minimum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMinimum() {
return minimum;
@@ -402,37 +474,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>minimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @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 Items setMinimum(Number minimum) {
- this.minimum = minimum;
+ public Items setMinimum(Number value) {
+ minimum = value;
return this;
}
/**
- * Synonym for {@link #setMinimum(Number)}.
+ * Same as {@link #setMinimum(Number)}.
*
- * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items minimum(Number minimum) {
- return setMinimum(minimum);
+ public Items minimum(Object value) {
+ return setMinimum(toNumber(value));
}
/**
* Bean property getter: <property>exclusiveMinimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @return The value of the <property>exclusiveMinimum</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getExclusiveMinimum() {
return exclusiveMinimum;
@@ -441,36 +519,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>exclusiveMinimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @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 Items setExclusiveMinimum(Boolean exclusiveMinimum) {
- this.exclusiveMinimum = exclusiveMinimum;
+ public Items setExclusiveMinimum(Boolean value) {
+ exclusiveMinimum = value;
return this;
}
/**
- * Synonym for {@link #setExclusiveMinimum(Boolean)}.
+ * Same as {@link #setExclusiveMinimum(Boolean)}.
*
- * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items exclusiveMinimum(Boolean exclusiveMinimum) {
- return setExclusiveMinimum(exclusiveMinimum);
+ public Items exclusiveMinimum(Object value) {
+ return setExclusiveMinimum(toBoolean(value));
}
/**
* Bean property getter: <property>maxLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">
- * http://json-schema.org/latest/json-schema-validation.html#anchor26</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">http://json-schema.org/latest/json-schema-validation.html#anchor26</a>
+ * </ul>
*
- * @return The value of the <property>maxLength</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMaxLength() {
return maxLength;
@@ -479,36 +564,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>maxLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">
- * http://json-schema.org/latest/json-schema-validation.html#anchor26</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">http://json-schema.org/latest/json-schema-validation.html#anchor26</a>
+ * </ul>
*
- * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @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 Items setMaxLength(Integer maxLength) {
- this.maxLength = maxLength;
+ public Items setMaxLength(Integer value) {
+ maxLength = value;
return this;
}
/**
- * Synonym for {@link #setMaxLength(Integer)}.
+ * Same as {@link #setMaxLength(Integer)}.
*
- * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items maxLength(Integer maxLength) {
- return setMaxLength(maxLength);
+ public Items maxLength(Object value) {
+ return setMaxLength(toInteger(value));
}
/**
* Bean property getter: <property>minLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">
- * http://json-schema.org/latest/json-schema-validation.html#anchor29</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">http://json-schema.org/latest/json-schema-validation.html#anchor29</a>
+ * </ul>
*
- * @return The value of the <property>minLength</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMinLength() {
return minLength;
@@ -517,36 +609,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>minLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">
- * http://json-schema.org/latest/json-schema-validation.html#anchor29</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">http://json-schema.org/latest/json-schema-validation.html#anchor29</a>
+ * </ul>
*
- * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @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 Items setMinLength(Integer minLength) {
- this.minLength = minLength;
+ public Items setMinLength(Integer value) {
+ minLength = value;
return this;
}
/**
- * Synonym for {@link #setMinLength(Integer)}.
+ * Same as {@link #setMinLength(Integer)}.
*
- * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items minLength(Integer minLength) {
- return setMinLength(minLength);
+ public Items minLength(Object value) {
+ return setMinLength(toInteger(value));
}
/**
* Bean property getter: <property>pattern</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">
- * http://json-schema.org/latest/json-schema-validation.html#anchor33</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">http://json-schema.org/latest/json-schema-validation.html#anchor33</a>
+ * </ul>
*
- * @return The value of the <property>pattern</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getPattern() {
return pattern;
@@ -555,36 +654,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>pattern</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">
- * http://json-schema.org/latest/json-schema-validation.html#anchor33</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">http://json-schema.org/latest/json-schema-validation.html#anchor33</a>
+ * </ul>
*
- * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @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 Items setPattern(String pattern) {
- this.pattern = pattern;
+ public Items setPattern(String value) {
+ pattern = value;
return this;
}
/**
- * Synonym for {@link #setPattern(String)}.
+ * Same as {@link #setPattern(String)}.
*
- * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items pattern(String pattern) {
- return setPattern(pattern);
+ public Items pattern(Object value) {
+ return setPattern(toStringVal(value));
}
/**
* Bean property getter: <property>maxItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">
- * http://json-schema.org/latest/json-schema-validation.html#anchor42</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">http://json-schema.org/latest/json-schema-validation.html#anchor42</a>
+ * </ul>
*
- * @return The value of the <property>maxItems</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMaxItems() {
return maxItems;
@@ -593,36 +699,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>maxItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">
- * http://json-schema.org/latest/json-schema-validation.html#anchor42</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">http://json-schema.org/latest/json-schema-validation.html#anchor42</a>
+ * </ul>
*
- * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @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 Items setMaxItems(Integer maxItems) {
- this.maxItems = maxItems;
+ public Items setMaxItems(Integer value) {
+ maxItems = value;
return this;
}
/**
- * Synonym for {@link #setMaxItems(Integer)}.
+ * Same as {@link #setMaxItems(Integer)}.
*
- * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items maxItems(Integer maxItems) {
- return setMaxItems(maxItems);
+ public Items maxItems(Object value) {
+ return setMaxItems(toInteger(value));
}
/**
* Bean property getter: <property>minItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">
- * http://json-schema.org/latest/json-schema-validation.html#anchor45</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">http://json-schema.org/latest/json-schema-validation.html#anchor45</a>
+ * </ul>
*
- * @return The value of the <property>minItems</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMinItems() {
return minItems;
@@ -631,37 +744,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>minItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">
- * http://json-schema.org/latest/json-schema-validation.html#anchor45</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">http://json-schema.org/latest/json-schema-validation.html#anchor45</a>
+ * </ul>
*
- * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @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 Items setMinItems(Integer minItems) {
- this.minItems = minItems;
+ public Items setMinItems(Integer value) {
+ minItems = value;
return this;
}
/**
- * Synonym for {@link #setMinItems(Integer)}.
+ * Same as {@link #setMinItems(Integer)}.
*
- * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items minItems(Integer minItems) {
- return setMinItems(minItems);
+ public Items minItems(Object value) {
+ return setMinItems(toInteger(value));
}
/**
* Bean property getter: <property>uniqueItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">
- * http://json-schema.org/latest/json-schema-validation.html#anchor49</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">http://json-schema.org/latest/json-schema-validation.html#anchor49</a>
+ * </ul>
*
- * @return The value of the <property>uniqueItems</property> property on this bean, or <jk>null</jk> if it is not
- * set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getUniqueItems() {
return uniqueItems;
@@ -670,36 +789,43 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>uniqueItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">
- * http://json-schema.org/latest/json-schema-validation.html#anchor49</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">http://json-schema.org/latest/json-schema-validation.html#anchor49</a>
+ * </ul>
*
- * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @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 Items setUniqueItems(Boolean uniqueItems) {
- this.uniqueItems = uniqueItems;
+ public Items setUniqueItems(Boolean value) {
+ uniqueItems = value;
return this;
}
/**
- * Synonym for {@link #setUniqueItems(Boolean)}.
+ * Same as {@link #setUniqueItems(Boolean)}.
*
- * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items uniqueItems(Boolean uniqueItems) {
- return setUniqueItems(uniqueItems);
+ public Items uniqueItems(Object value) {
+ return setUniqueItems(toBoolean(value));
}
/**
* Bean property getter: <property>enum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">
- * http://json-schema.org/latest/json-schema-validation.html#anchor76</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">http://json-schema.org/latest/json-schema-validation.html#anchor76</a>
+ * </ul>
*
- * @return The value of the <property>enum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<Object> getEnum() {
return _enum;
@@ -708,65 +834,71 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>enum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">
- * http://json-schema.org/latest/json-schema-validation.html#anchor76</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">http://json-schema.org/latest/json-schema-validation.html#anchor76</a>
+ * </ul>
*
- * @param _enum The new value for the <property>enum</property> property on this bean.
+ * @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 Items setEnum(List<Object> _enum) {
- this._enum = _enum;
- return this;
- }
-
- /**
- * Bean property adder: <property>enum</property>.
- *
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">
- * http://json-schema.org/latest/json-schema-validation.html#anchor76</a>.
- *
- * @param _enum
- * The new values to add to the <property>enum</property> property on this bean.
- * These can either be individual objects or {@link Collection Collections} of objects.
- * @return This object (for method chaining).
- */
- public Items addEnum(Object..._enum) {
- for (Object o : _enum) {
- if (o != null) {
- if (o instanceof Collection)
- addEnum((Collection<Object>)o);
- else {
- if (this._enum == null)
- this._enum = new LinkedList<>();
- this._enum.add(o);
- }
- }
- }
+ public Items setEnum(Collection<Object> value) {
+ _enum = newList(value);
return this;
}
/**
- * Synonym for {@link #addEnum(Object...)}.
+ * Adds one or more values to the <property>enum</property> property.
*
- * @param _enum
- * The new values to add to the <property>enum</property> property on this bean.
- * These can either be individual objects or {@link Collection Collections} of objects.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Items _enum(Object..._enum) {
- return addEnum(_enum);
+ public Items addEnum(Collection<Object> values) {
+ _enum = addToList(_enum, values);
+ return this;
+ }
+
+ /**
+ * Adds one or more values to the <property>enum</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Object</code>
+ * <li><code>Collection<Object></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<Object></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * _enum(<js>"['foo','bar']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * _enum(<js>"foo"</js>, <js>"bar"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public Items _enum(Object...values) {
+ _enum = addToList(_enum, values, Object.class);
+ return this;
}
/**
* Bean property getter: <property>multipleOf</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">
- * http://json-schema.org/latest/json-schema-validation.html#anchor14</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">http://json-schema.org/latest/json-schema-validation.html#anchor14</a>
+ * </ul>
*
- * @return The value of the <property>multipleOf</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMultipleOf() {
return multipleOf;
@@ -775,25 +907,85 @@ public class Items extends SwaggerElement {
/**
* Bean property setter: <property>multipleOf</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">
- * http://json-schema.org/latest/json-schema-validation.html#anchor14</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">http://json-schema.org/latest/json-schema-validation.html#anchor14</a>
+ * </ul>
*
- * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @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 Items setMultipleOf(Number multipleOf) {
- this.multipleOf = multipleOf;
+ public Items setMultipleOf(Number value) {
+ multipleOf = value;
return this;
}
/**
- * Synonym for {@link #setMultipleOf(Number)}.
+ * Same as {@link #setMultipleOf(Number)}.
*
- * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Items multipleOf(Number multipleOf) {
- return setMultipleOf(multipleOf);
+ public Items multipleOf(Object value) {
+ return setMultipleOf(toNumber(value));
+ }
+
+ @Override /* SwaggerElement */
+ public <T> T get(String property, Class<T> type) {
+ if (property == null)
+ return null;
+ switch (property) {
+ case "type": return toType(getType(), type);
+ case "format": return toType(getFormat(), type);
+ case "items": return toType(getItems(), type);
+ case "collectionFormat": return toType(getCollectionFormat(), type);
+ case "default": return toType(getDefault(), type);
+ case "maximum": return toType(getMaximum(), type);
+ case "exclusiveMaximum": return toType(getExclusiveMaximum(), type);
+ case "minimum": return toType(getMinimum(), type);
+ case "exclusiveMinimum": return toType(getExclusiveMinimum(), type);
+ case "maxLength": return toType(getMaxLength(), type);
+ case "minLength": return toType(getMinLength(), type);
+ case "pattern": return toType(getPattern(), type);
+ case "maxItems": return toType(getMaxItems(), type);
+ case "minItems": return toType(getMinItems(), type);
+ case "uniqueItems": return toType(getUniqueItems(), type);
+ case "enum": return toType(getEnum(), type);
+ case "multipleOf": return toType(getMultipleOf(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public Items set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "type": return type(value);
+ case "format": return format(value);
+ case "items": return items(value);
+ case "collectionFormat": return collectionFormat(value);
+ case "default": return _default(value);
+ case "maximum": return maximum(value);
+ case "exclusiveMaximum": return exclusiveMaximum(value);
+ case "minimum": return minimum(value);
+ case "exclusiveMinimum": return exclusiveMinimum(value);
+ case "maxLength": return maxLength(value);
+ case "minLength": return minLength(value);
+ case "pattern": return pattern(value);
+ case "maxItems": return maxItems(value);
+ case "minItems": return minItems(value);
+ case "uniqueItems": return uniqueItems(value);
+ case "enum": return setEnum(null)._enum(value);
+ case "multipleOf": return multipleOf(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/License.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/License.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/License.java
index 51aae5d..e238fa3 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/License.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/License.java
@@ -12,8 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
-import static org.apache.juneau.internal.StringUtils.*;
-
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import java.net.*;
import java.net.URI;
@@ -25,6 +24,17 @@ import org.apache.juneau.annotation.*;
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * License x = <jsm>license</jsm>(<js>"Apache 2.0"</js>, <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</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'>
+ * <jc>// Output</jc>
* {
* <js>"name"</js>: <js>"Apache 2.0"</js>,
* <js>"url"</js>: <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</js>
@@ -33,20 +43,10 @@ import org.apache.juneau.annotation.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="name,url")
+@Bean(properties="name,url,*")
public class License extends SwaggerElement {
private String name;
@@ -56,9 +56,9 @@ public class License extends SwaggerElement {
* Bean property getter: <property>name</property>.
*
* <p>
- * Required. The license name used for the API.
+ * The license name used for the API.
*
- * @return The value of the <property>name</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getName() {
return name;
@@ -68,24 +68,29 @@ public class License extends SwaggerElement {
* Bean property setter: <property>name</property>.
*
* <p>
- * Required. The license name used for the API.
+ * The license name used for the API.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public License setName(String name) {
- this.name = name;
+ public License setName(String value) {
+ name = value;
return this;
}
/**
- * Synonym for {@link #setName(String)}.
+ * Same as {@link #setName(String)}.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public License name(String name) {
- return setName(name);
+ public License name(Object value) {
+ return setName(toStringVal(value));
}
/**
@@ -94,14 +99,7 @@ public class License extends SwaggerElement {
* <p>
* A URL to the license used for the API.
*
- * <p>
- * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
- * Strings must be valid URIs.
- *
- * <p>
- * URIs defined by {@link UriResolver} can be used for values.
- *
- * @return The value of the <property>url</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public URI getUrl() {
return url;
@@ -111,27 +109,60 @@ public class License extends SwaggerElement {
* Bean property setter: <property>url</property>.
*
* <p>
- * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
- * Strings must be valid URIs.
- *
- * <p>
- * URIs defined by {@link UriResolver} can be used for values.
+ * A URL to the license used for the API.
*
- * @param url The new value for the <property>url</property> property on this bean.
+ * @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 License setUrl(Object url) {
- this.url = toURI(url);
+ public License setUrl(URI value) {
+ url = value;
return this;
}
/**
- * Synonym for {@link #setUrl(Object)}.
+ * Same as {@link #setUrl(URI)}.
*
- * @param url The new value for the <property>url</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-URI values will be converted to URI using <code><jk>new</jk> URI(value.toString())</code>.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link URI}
+ * <li>{@link URL}
+ * <li>{@link String}
+ * <br>Converted to a URI using <code>URI.<jsm>create</jsm>(value.toString())</code>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public License url(Object url) {
- return setUrl(url);
+ public License url(Object value) {
+ return setUrl(toURI(value));
+ }
+
+ @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 "url": return toType(getUrl(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public License set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "name": return name(value);
+ case "url": return url(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
[05/10] juneau git commit: JUNEAU-78
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Operation.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Operation.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Operation.java
index be867bb..935048a 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Operation.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Operation.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import java.util.*;
import org.apache.juneau.annotation.*;
@@ -22,12 +23,52 @@ import org.apache.juneau.http.*;
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * Operation x = <jsm>operation</jsm>()
+ * .tags(<js>"pet"</js>)
+ * .summary(<js>"Updates a pet in the store with form data"</js>)
+ * .description(<js>""</js>)
+ * .operationId(<js>"updatePetWithForm"</js>)
+ * .consumes(<js>"application/x-www-form-urlencoded"</js>)
+ * .produces(<js>"application/json"</js>, <js>"application/xml"</js>)
+ * .parameters(
+ * <jsm>parameter</jsm>()
+ * .name(<js>"petId"</js>)
+ * .in(<js>"path"</js>)
+ * .description(<js>"ID of pet that needs to be updated"</js>)
+ * .required(<jk>true</jk>)
+ * .type(<js>"string"</js>),
+ * <jsm>parameter</jsm>()
+ * .name(<js>"name"</js>)
+ * .in(<js>"formData"</js>)
+ * .description(<js>"Updated name of the pet"</js>)
+ * .required(<jk>false</jk>)
+ * .type(<js>"string"</js>),
+ * <jsm>parameter</jsm>()
+ * .name(<js>"status"</js>)
+ * .in(<js>"formData"</js>)
+ * .description(<js>"Updated status of the pet"</js>)
+ * .required(<jk>false</jk>)
+ * .type(<js>"string"</js>)
+ * )
+ * .response(200, <jsm>responseInfo</jsm>(<js>"Pet updated."</js>))
+ * .response(405, <jsm>responseInfo</jsm>(<js>"Invalid input."</js>))
+ * .security(<js>"petstore_auth"</js>, <js>"write:pets"</js>, <js>"read:pets"</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'>
+ * <jc>// Output</jc>
* {
* <js>"tags"</js>: [
* <js>"pet"</js>
* ],
* <js>"summary"</js>: <js>"Updates a pet in the store with form data"</js>,
- * <js>"description"</js>: "",
+ * <js>"description"</js>: <js>""</js>,
* <js>"operationId"</js>: <js>"updatePetWithForm"</js>,
* <js>"consumes"</js>: [
* <js>"application/x-www-form-urlencoded"</js>
@@ -80,43 +121,36 @@ import org.apache.juneau.http.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="operationId,summary,description,tags,externalDocs,consumes,produces,parameters,responses,schemes,deprecated,security")
+@Bean(properties="operationId,summary,description,tags,externalDocs,consumes,produces,parameters,responses,schemes,deprecated,security,*")
public class Operation extends SwaggerElement {
- private List<String> tags;
- private String summary;
- private String description;
+ private String
+ summary,
+ description,
+ operationId;
+ private Boolean deprecated;
private ExternalDocumentation externalDocs;
- private String operationId;
- private List<MediaType> consumes;
- private List<MediaType> produces;
+ private List<String>
+ tags,
+ schemes;
+ private List<MediaType>
+ consumes,
+ produces;
private List<ParameterInfo> parameters;
- private Map<Integer,ResponseInfo> responses;
- private List<String> schemes;
- private Boolean deprecated;
private List<Map<String,List<String>>> security;
+ private Map<Integer,ResponseInfo> responses;
/**
* Bean property getter: <property>tags</property>.
*
* <p>
* A list of tags for API documentation control.
- * Tags can be used for logical grouping of operations by resources or any other qualifier.
+ * <br>Tags can be used for logical grouping of operations by resources or any other qualifier.
*
- * @return The value of the <property>tags</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<String> getTags() {
return tags;
@@ -127,69 +161,59 @@ public class Operation extends SwaggerElement {
*
* <p>
* A list of tags for API documentation control.
- * Tags can be used for logical grouping of operations by resources or any other qualifier.
+ * <br>Tags can be used for logical grouping of operations by resources or any other qualifier.
*
- * @param tags The new value for the <property>tags</property> property on this bean.
+ * @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 Operation setTags(List<String> tags) {
- this.tags = tags;
+ public Operation setTags(Collection<String> value) {
+ tags = newList(value);
return this;
}
/**
- * Bean property adder: <property>tags</property>.
- *
- * <p>
- * A list of tags for API documentation control.
- * Tags can be used for logical grouping of operations by resources or any other qualifier.
- *
- * @param tags The values to add for the <property>tags</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation addTags(String...tags) {
- return addTags(Arrays.asList(tags));
- }
-
- /**
- * Bean property adder: <property>tags</property>.
+ * Adds one or more values to the <property>tags</property> property.
*
* <p>
* A list of tags for API documentation control.
- * Tags can be used for logical grouping of operations by resources or any other qualifier.
+ * <br>Tags can be used for logical grouping of operations by resources or any other qualifier.
*
- * @param tags
- * The values to add for the <property>tags</property> property on this bean.
- * Ignored if <jk>null</jk>.
+ * @param value
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Operation addTags(Collection<String> tags) {
- if (tags != null) {
- if (this.tags == null)
- this.tags = new LinkedList<>();
- this.tags.addAll(tags);
- }
+ public Operation addTags(Collection<String> value) {
+ tags = addToList(tags, value);
return this;
}
/**
- * Synonym for {@link #addTags(String...)}.
- *
- * @param tags The new value for the <property>tags</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation tags(String...tags) {
- return addTags(tags);
- }
-
- /**
- * Synonym for {@link #addTags(Collection)}.
+ * Same as {@link #addTags(Collection)}.
*
- * @param tags The new value for the <property>tags</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Collection<String></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<String></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * tags(<js>"['foo','bar']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * tags(<js>"foo"</js>, <js>"bar"</js>);
+ * </p>
+ * </ul>
* @return This object (for method chaining).
*/
- public Operation tags(Collection<String> tags) {
- return addTags(tags);
+ public Operation tags(Object...values) {
+ tags = addToList(tags, values, String.class);
+ return this;
}
/**
@@ -197,9 +221,8 @@ public class Operation extends SwaggerElement {
*
* <p>
* A short summary of what the operation does.
- * For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
*
- * @return The value of the <property>summary</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getSummary() {
return summary;
@@ -210,24 +233,28 @@ public class Operation extends SwaggerElement {
*
* <p>
* A short summary of what the operation does.
- * For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
*
- * @param summary The new value for the <property>summary</property> property on this bean.
+ * @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 Operation setSummary(String summary) {
- this.summary = summary;
+ public Operation setSummary(String value) {
+ summary = value;
return this;
}
/**
- * Synonym for {@link #setSummary(String)}.
+ * Same as {@link #setSummary(String)}.
*
- * @param summary The new value for the <property>summary</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Operation summary(String summary) {
- return setSummary(summary);
+ public Operation summary(Object value) {
+ return setSummary(toStringVal(value));
}
/**
@@ -235,11 +262,8 @@ public class Operation extends SwaggerElement {
*
* <p>
* A verbose explanation of the operation behavior.
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used
- * for rich text representation.
*
- * @return
- * The value of the <property>description</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDescription() {
return description;
@@ -250,25 +274,30 @@ public class Operation extends SwaggerElement {
*
* <p>
* A verbose explanation of the operation behavior.
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used
- * for rich text representation.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Operation setDescription(String description) {
- this.description = description;
+ public Operation setDescription(String value) {
+ description = value;
return this;
}
/**
- * Synonym for {@link #setDescription(String)}.
+ * Same as {@link #setDescription(String)}.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Operation description(String description) {
- return setDescription(description);
+ public Operation description(Object value) {
+ return setDescription(toStringVal(value));
}
/**
@@ -277,8 +306,7 @@ public class Operation extends SwaggerElement {
* <p>
* Additional external documentation for this operation.
*
- * @return
- * The value of the <property>externalDocs</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public ExternalDocumentation getExternalDocs() {
return externalDocs;
@@ -290,34 +318,44 @@ public class Operation extends SwaggerElement {
* <p>
* Additional external documentation for this operation.
*
- * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @param value
+ * The values to add to this property.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Operation setExternalDocs(ExternalDocumentation externalDocs) {
- this.externalDocs = externalDocs;
+ public Operation setExternalDocs(ExternalDocumentation value) {
+ externalDocs = value;
return this;
}
/**
- * Synonym for {@link #setExternalDocs(ExternalDocumentation)}.
+ * Same as {@link #setExternalDocs(ExternalDocumentation)}.
*
- * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link ExternalDocumentation}
+ * <li><code>String</code> - JSON object representation of {@link ExternalDocumentation}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * 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 Operation externalDocs(ExternalDocumentation externalDocs) {
- return setExternalDocs(externalDocs);
+ public Operation externalDocs(Object value) {
+ return setExternalDocs(toType(value, ExternalDocumentation.class));
}
/**
* Bean property getter: <property>operationId</property>.
*
* <p>
- * Unique string used to identify the operation. The id MUST be unique among all operations described in the API.
- * Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to
- * follow common programming naming conventions.
+ * Unique string used to identify the operation.
*
- * @return
- * The value of the <property>operationId</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getOperationId() {
return operationId;
@@ -327,26 +365,35 @@ public class Operation extends SwaggerElement {
* Bean property setter: <property>operationId</property>.
*
* <p>
- * Unique string used to identify the operation. The id MUST be unique among all operations described in the API.
- * Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to
- * follow common programming naming conventions.
+ * Unique string used to identify the operation.
*
- * @param operationId The new value for the <property>operationId</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>The id MUST be unique among all operations described in the API.
+ * <br>Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to
+ * follow common programming naming conventions.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Operation setOperationId(String operationId) {
- this.operationId = operationId;
+ public Operation setOperationId(String value) {
+ operationId = value;
return this;
}
/**
- * Synonym for {@link #setOperationId(String)}.
+ * Same as {@link #setOperationId(String)}.
*
- * @param operationId The new value for the <property>operationId</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>The id MUST be unique among all operations described in the API.
+ * <br>Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to
+ * follow common programming naming conventions.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Operation operationId(String operationId) {
- return setOperationId(operationId);
+ public Operation operationId(Object value) {
+ return setOperationId(toStringVal(value));
}
/**
@@ -354,11 +401,12 @@ public class Operation extends SwaggerElement {
*
* <p>
* A list of MIME types the operation can consume.
+ *
+ * <p>
* This overrides the <code>consumes</code> definition at the Swagger Object.
- * An empty value MAY be used to clear the global definition.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>An empty value MAY be used to clear the global definition.
*
- * @return The value of the <property>consumes</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<MediaType> getConsumes() {
return consumes;
@@ -369,85 +417,83 @@ public class Operation extends SwaggerElement {
*
* <p>
* A list of MIME types the operation can consume.
+ *
+ * <p>
* This overrides the <code>consumes</code> definition at the Swagger Object.
- * An empty value MAY be used to clear the global definition.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>An empty value MAY be used to clear the global definition.
*
- * @param consumes The new value for the <property>consumes</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Values MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Operation setConsumes(List<MediaType> consumes) {
- this.consumes = consumes;
+ public Operation setConsumes(Collection<MediaType> value) {
+ consumes = newList(value);
return this;
}
/**
- * Bean property adder: <property>consumes</property>.
+ * Adds one or more values to the <property>consumes</property> property.
*
* <p>
* A list of MIME types the operation can consume.
- * This overrides the <code>consumes</code> definition at the Swagger Object.
- * An empty value MAY be used to clear the global definition.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
- *
- * @param consumes The new values to add to the <property>consumes</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation addConsumes(MediaType...consumes) {
- return addConsumes(Arrays.asList(consumes));
- }
-
- /**
- * Bean property adder: <property>consumes</property>.
*
* <p>
- * A list of MIME types the operation can consume.
* This overrides the <code>consumes</code> definition at the Swagger Object.
- * An empty value MAY be used to clear the global definition.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>An empty value MAY be used to clear the global definition.
*
- * @param consumes The new values to add to the <property>consumes</property> property on this bean.
+ * @param value
+ * The values to add to this property.
+ * <br>Values MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Operation addConsumes(Collection<MediaType> consumes) {
- if (consumes != null) {
- if (this.consumes == null)
- this.consumes = new LinkedList<>();
- this.consumes.addAll(consumes);
- }
+ public Operation addConsumes(Collection<MediaType> value) {
+ consumes = addToList(consumes, value);
return this;
}
/**
- * Synonym for {@link #addConsumes(MediaType...)}.
- *
- * @param consumes The new values to add to the <property>consumes</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation consumes(MediaType...consumes) {
- return addConsumes(consumes);
+ * Adds one or more values to the <property>consumes</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link MediaType}
+ * <li><code>Collection<{@link MediaType}|String></code>
+ * <li><code>{@link MediaType}[]</code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<{@link MediaType}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * consumes(<js>"['text/json']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * consumes(<js>"text/json"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public Operation consumes(Object...values) {
+ consumes = addToList(consumes, values, MediaType.class);
+ return this;
}
-
- /**
- * Synonym for {@link #addConsumes(Collection)}.
- *
- * @param consumes The new values to add to the <property>consumes</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation consumes(Collection<MediaType> consumes) {
- return addConsumes(consumes);
- }
-
+
/**
* Bean property getter: <property>produces</property>.
*
* <p>
* A list of MIME types the operation can produce.
+ *
+ * <p>
* This overrides the <code>produces</code> definition at the Swagger Object.
- * An empty value MAY be used to clear the global definition.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>An empty value MAY be used to clear the global definition.
*
- * @return The value of the <property>produces</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<MediaType> getProduces() {
return produces;
@@ -458,78 +504,69 @@ public class Operation extends SwaggerElement {
*
* <p>
* A list of MIME types the operation can produce.
- * This overrides the <code>produces</code> definition at the Swagger Object.
- * An empty value MAY be used to clear the global definition.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
- *
- * @param produces The new value for the <property>produces</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation setProduces(List<MediaType> produces) {
- this.produces = produces;
- return this;
- }
-
- /**
- * Bean property adder: <property>produces</property>.
*
* <p>
- * A list of MIME types the operation can produce.
* This overrides the <code>produces</code> definition at the Swagger Object.
- * An empty value MAY be used to clear the global definition.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>An empty value MAY be used to clear the global definition.
*
- * @param produces The new value for the <property>produces</property> property on this bean.
+ * @param value
+ * The values to add to this property.
+ * <br>Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Operation addProduces(MediaType...produces) {
- if (produces != null) {
- if (this.produces == null)
- this.produces = new LinkedList<>();
- this.produces.addAll(Arrays.asList(produces));
- }
+ public Operation setProduces(Collection<MediaType> value) {
+ produces = newList(value);
return this;
}
/**
- * Bean property adder: <property>produces</property>.
+ * Adds one or more values to the <property>produces</property> property.
*
* <p>
* A list of MIME types the operation can produces.
+ *
+ * <p>
* This overrides the <code>produces</code> definition at the Swagger Object.
- * An empty value MAY be used to clear the global definition.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>An empty value MAY be used to clear the global definition.
*
- * @param produces The new values to add to the <property>produces</property> property on this bean.
+ * @param value
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Operation addProduces(Collection<MediaType> produces) {
- if (produces != null) {
- if (this.produces == null)
- this.produces = new LinkedList<>();
- this.produces.addAll(produces);
- }
+ public Operation addProduces(Collection<MediaType> value) {
+ produces = addToList(produces, value);
return this;
}
/**
- * Synonym for {@link #addProduces(MediaType...)}.
- *
- * @param produces The new value for the <property>produces</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation produces(MediaType...produces) {
- return addProduces(produces);
- }
-
- /**
- * Synonym for {@link #addProduces(Collection)}.
- *
- * @param produces The new value for the <property>produces</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation produces(Collection<MediaType> produces) {
- return addProduces(produces);
+ * Same as {@link #addProduces(Collection)}.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link MediaType}
+ * <li><code>Collection<{@link MediaType}|String></code>
+ * <li><code>{@link MediaType}[]</code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<{@link MediaType}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * produces(<js>"['text/json']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * produces(<js>"text/json"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public Operation produces(Object...values) {
+ produces = addToList(produces, values, MediaType.class);
+ return this;
}
/**
@@ -537,16 +574,19 @@ public class Operation extends SwaggerElement {
*
* <p>
* A list of parameters that are applicable for this operation.
- * If a parameter is already defined at the <a class="doclink"
- * href="http://swagger.io/specification/#pathItemParameters">Path Item</a>, the new definition will override it,
- * but can never remove it.
- * The list MUST NOT include duplicated parameters.
- * A unique parameter is defined by a combination of a <code>name</code> and <code>location</code>.
- * The list can use the <a class="doclink" href="http://swagger.io/specification/#referenceObject">Reference Object</a>
- * to link to parameters that are defined at the <a class="doclink" href="http://swagger.io/specification/#swaggerParameters">Swagger Object's parameters</a>.
- * There can be one <js>"body"</js> parameter at most.
*
- * @return The value of the <property>parameters</property> property on this bean, or <jk>null</jk> if it is not set.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li>If a parameter is already defined at the <a class="doclink" href="http://swagger.io/specification/#pathItemParameters">Path Item</a>,
+ * the new definition will override it, but can never remove it.
+ * <li>The list MUST NOT include duplicated parameters.
+ * <li>A unique parameter is defined by a combination of a <code>name</code> and <code>location</code>.
+ * <li>The list can use the <a class="doclink" href="http://swagger.io/specification/#referenceObject">Reference Object</a>
+ * to link to parameters that are defined at the <a class="doclink" href="http://swagger.io/specification/#swaggerParameters">Swagger Object's parameters</a>.
+ * <li>There can be one <js>"body"</js> parameter at most.
+ * </ul>
+ *
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<ParameterInfo> getParameters() {
return parameters;
@@ -557,78 +597,90 @@ public class Operation extends SwaggerElement {
*
* <p>
* A list of parameters that are applicable for this operation.
- * If a parameter is already defined at the <a class="doclink"
- * href="http://swagger.io/specification/#pathItemParameters">Path Item</a>, the new definition will override it,
- * but can never remove it.
- * The list MUST NOT include duplicated parameters.
- * A unique parameter is defined by a combination of a <code>name</code> and <code>location</code>.
- * The list can use the <a class="doclink"
- * href="http://swagger.io/specification/#referenceObject">Reference Object</a> to link to parameters that are
- * defined at the <a class="doclink"
- * href="http://swagger.io/specification/#swaggerParameters">Swagger Object's parameters</a>.
- * There can be one <js>"body"</js> parameter at most.
- *
- * @param parameters The new value for the <property>parameters</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation setParameters(List<ParameterInfo> parameters) {
- this.parameters = parameters;
+ *
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li>If a parameter is already defined at the <a class="doclink" href="http://swagger.io/specification/#pathItemParameters">Path Item</a>,
+ * the new definition will override it, but can never remove it.
+ * <li>The list MUST NOT include duplicated parameters.
+ * <li>A unique parameter is defined by a combination of a <code>name</code> and <code>location</code>.
+ * <li>The list can use the <a class="doclink" href="http://swagger.io/specification/#referenceObject">Reference Object</a>
+ * to link to parameters that are defined at the <a class="doclink" href="http://swagger.io/specification/#swaggerParameters">Swagger Object's parameters</a>.
+ * <li>There can be one <js>"body"</js> parameter at most.
+ * </ul>
+ *
+ * @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 Operation setParameters(Collection<ParameterInfo> value) {
+ parameters = newList(value);
return this;
}
/**
- * Bean property adder: <property>parameters</property>.
+ * Adds one or more values to the <property>parameters</property> property.
*
* <p>
* A list of parameters that are applicable for this operation.
- * If a parameter is already defined at the <a class="doclink"
- * href="http://swagger.io/specification/#pathItemParameters">Path Item</a>, the new definition will override it,
- * but can never remove it.
- * The list MUST NOT include duplicated parameters.
- * A unique parameter is defined by a combination of a <code>name</code> and <code>location</code>.
- * The list can use the <a class="doclink"
- * href="http://swagger.io/specification/#referenceObject">Reference Object</a> to link to parameters that are
- * defined at the <a class="doclink"
- * href="http://swagger.io/specification/#swaggerParameters">Swagger Object's parameters</a>.
- * There can be one <js>"body"</js> parameter at most.
- *
- * @param parameters The new value to add to the <property>parameters</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation addParameters(ParameterInfo...parameters) {
- if (this.parameters == null)
- this.parameters = new LinkedList<>();
- this.parameters.addAll(Arrays.asList(parameters));
- return this;
- }
-
- /**
- * Synonym for {@link #addParameters(ParameterInfo...)}.
*
- * @param parameters The new value to add to the <property>parameters</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation parameters(ParameterInfo...parameters) {
- return addParameters(parameters);
- }
-
- /**
- * Synonym for {@link #setParameters(List)}.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li>If a parameter is already defined at the <a class="doclink" href="http://swagger.io/specification/#pathItemParameters">Path Item</a>,
+ * the new definition will override it, but can never remove it.
+ * <li>The list MUST NOT include duplicated parameters.
+ * <li>A unique parameter is defined by a combination of a <code>name</code> and <code>location</code>.
+ * <li>The list can use the <a class="doclink" href="http://swagger.io/specification/#referenceObject">Reference Object</a>
+ * to link to parameters that are defined at the <a class="doclink" href="http://swagger.io/specification/#swaggerParameters">Swagger Object's parameters</a>.
+ * <li>There can be one <js>"body"</js> parameter at most.
+ * </ul>
*
- * @param parameters The new value to add to the <property>parameters</property> property on this bean.
+ * @param value
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Operation parameters(List<ParameterInfo> parameters) {
- return setParameters(parameters);
+ public Operation addParameters(Collection<ParameterInfo> value) {
+ parameters = addToList(parameters, value);
+ return this;
+ }
+
+ /**
+ * Same as {@link #addParameters(Collection)}.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link ParameterInfo}
+ * <li><code>Collection<{@link ParameterInfo}|String></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<{@link ParameterInfo}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * parameters(<js>"[{path:'path',id:'id'}]"</js>);
+ * </p>
+ * <li><code>String</code> - JSON object representation of {@link ParameterInfo}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * parameters(<js>"{path:'path',id:'id'}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public Operation parameters(Object...values) {
+ parameters = addToList(parameters, values, ParameterInfo.class);
+ return this;
}
/**
* Bean property getter: <property>responses</property>.
*
* <p>
- * Required. The list of possible responses as they are returned from executing this operation.
+ * The list of possible responses as they are returned from executing this operation.
*
- * @return The value of the <property>responses</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<Integer,ResponseInfo> getResponses() {
return responses;
@@ -638,52 +690,64 @@ public class Operation extends SwaggerElement {
* Bean property setter: <property>responses</property>.
*
* <p>
- * Required. The list of possible responses as they are returned from executing this operation.
+ * The list of possible responses as they are returned from executing this operation.
*
- * @param responses The new value for the <property>responses</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public Operation setResponses(Map<Integer,ResponseInfo> responses) {
- this.responses = responses;
+ public Operation setResponses(Map<Integer,ResponseInfo> value) {
+ responses = newMap(value);
return this;
}
/**
- * Bean property adder: <property>responses</property>.
+ * Adds one or more values to the <property>responses</property> property.
*
* <p>
- * Required. The list of possible responses as they are returned from executing this operation.
+ * The list of possible responses as they are returned from executing this operation.
*
- * @param statusCode The HTTP status code.
- * @param response The response description.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Operation addResponse(Integer statusCode, ResponseInfo response) {
- if (responses == null)
- responses = new TreeMap<>();
- responses.put(statusCode, response);
+ public Operation addResponses(Map<Integer,ResponseInfo> values) {
+ responses = addToMap(responses, values);
return this;
}
/**
- * Synonym for {@link #addResponse(Integer,ResponseInfo)}.
+ * Adds a single value to the <property>responses</property> property.
*
* @param statusCode The HTTP status code.
* @param response The response description.
* @return This object (for method chaining).
*/
public Operation response(Integer statusCode, ResponseInfo response) {
- return addResponse(statusCode, response);
+ return addResponses(Collections.singletonMap(statusCode, response));
}
/**
- * Synonym for {@link #setResponses(Map)}.
+ * Same as {@link #addResponses(Map)}.
*
- * @param responses The new value for the <property>responses</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<Integer,{@link ResponseInfo}|String></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<Integer,{@link ResponseInfo}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * responses(<js>"{'404':{description:'description',...}}"</js>);
+ * </p>
+ * </ul>
* @return This object (for method chaining).
*/
- public Operation responses(Map<Integer,ResponseInfo> responses) {
- return setResponses(responses);
+ public Operation responses(Object...value) {
+ responses = addToMap(responses, value, Integer.class, ResponseInfo.class);
+ return this;
}
/**
@@ -691,10 +755,9 @@ public class Operation extends SwaggerElement {
*
* <p>
* The transfer protocol for the operation.
- * Values MUST be from the list: <js>"http"</js>, <js>"https"</js>, <js>"ws"</js>, <js>"wss"</js>.
- * The value overrides the Swagger Object <code>schemes</code> definition.
+ * <br>The value overrides the Swagger Object <code>schemes</code> definition.
*
- * @return The value of the <property>schemes</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<String> getSchemes() {
return schemes;
@@ -705,58 +768,66 @@ public class Operation extends SwaggerElement {
*
* <p>
* The transfer protocol for the operation.
- * Values MUST be from the list: <js>"http"</js>, <js>"https"</js>, <js>"ws"</js>, <js>"wss"</js>.
- * The value overrides the Swagger Object <code>schemes</code> definition.
- *
- * @param schemes The new value for the <property>schemes</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation setSchemes(List<String> schemes) {
- this.schemes = schemes;
+ * <br>The value overrides the Swagger Object <code>schemes</code> definition.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"http"</js>
+ * <li><js>"https"</js>
+ * <li><js>"ws"</js>
+ * <li><js>"wss"</js>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
+ * @return This object (for method chaining).
+ */
+ public Operation setSchemes(Collection<String> value) {
+ schemes = newList(value);
return this;
}
/**
- * Bean property adder: <property>schemes</property>.
- *
- * <p>
- * The transfer protocol for the operation.
- * Values MUST be from the list: <js>"http"</js>, <js>"https"</js>, <js>"ws"</js>, <js>"wss"</js>.
- * The value overrides the Swagger Object <code>schemes</code> definition.
- *
- * @param schemes The new values to add to the <property>schemes</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Operation addSchemes(String...schemes) {
- return addSchemes(Arrays.asList(schemes));
- }
-
- /**
- * Bean property adder: <property>schemes</property>.
+ * Adds one or more values to the <property>schemes</property> property.
*
* <p>
* The transfer protocol for the operation.
- * Values MUST be from the list: <js>"http"</js>, <js>"https"</js>, <js>"ws"</js>, <js>"wss"</js>.
- * The value overrides the Swagger Object <code>schemes</code> definition.
+ * <br>The value overrides the Swagger Object <code>schemes</code> definition.
*
- * @param schemes The new values to add to the <property>schemes</property> property on this bean.
+ * @param value
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Operation addSchemes(Collection<String> schemes) {
- if (this.schemes == null)
- this.schemes = new LinkedList<>();
- this.schemes.addAll(schemes);
+ public Operation addSchemes(Collection<String> value) {
+ schemes = addToList(schemes, value);
return this;
}
/**
- * Synonym for {@link #addSchemes(String...)}.
+ * Same as {@link #addSchemes(Collection)}.
*
- * @param schemes The new values to add to the <property>schemes</property> property on this bean.
+ * @param values
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Collection<String></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<String></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * schemes(<js>"['scheme1','scheme2']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * schemes(<js>"scheme1</js>, <js>"scheme2"</js>);
+ * </p>
+ * </ul>
* @return This object (for method chaining).
*/
- public Operation schemes(String...schemes) {
- return addSchemes(schemes);
+ public Operation schemes(Object...values) {
+ schemes = addToList(schemes, values, String.class);
+ return this;
}
/**
@@ -764,10 +835,8 @@ public class Operation extends SwaggerElement {
*
* <p>
* Declares this operation to be deprecated.
- * Usage of the declared operation should be refrained.
- * Default value is <jk>false</jk>.
*
- * @return The value of the <property>deprecated</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getDeprecated() {
return deprecated;
@@ -778,25 +847,27 @@ public class Operation extends SwaggerElement {
*
* <p>
* Declares this operation to be deprecated.
- * Usage of the declared operation should be refrained.
- * Default value is <jk>false</jk>.
*
- * @param deprecated The new value for the <property>deprecated</property> property on this bean.
+ * @param value T
+ * The new value for this property.
* @return This object (for method chaining).
*/
- public Operation setDeprecated(Boolean deprecated) {
- this.deprecated = deprecated;
+ public Operation setDeprecated(Boolean value) {
+ deprecated = value;
return this;
}
/**
- * Synonym for {@link #setDeprecated(Boolean)}.
+ * Same as {@link #setDeprecated(Boolean)}.
*
- * @param deprecated The new value for the <property>deprecated</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Operation deprecated(Boolean deprecated) {
- return setDeprecated(deprecated);
+ public Operation deprecated(Object value) {
+ return setDeprecated(toBoolean(value));
}
/**
@@ -804,12 +875,14 @@ public class Operation extends SwaggerElement {
*
* <p>
* A declaration of which security schemes are applied for this operation.
- * The list of values describes alternative security schemes that can be used (that is, there is a logical OR
+ * <br>The list of values describes alternative security schemes that can be used (that is, there is a logical OR
* between the security requirements).
+ *
+ * <p>
* This definition overrides any declared top-level security.
- * To remove a top-level <code>security</code> declaration, an empty array can be used.
+ * <br>To remove a top-level <code>security</code> declaration, an empty array can be used.
*
- * @return The value of the <property>security</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<Map<String,List<String>>> getSecurity() {
return security;
@@ -820,43 +893,51 @@ public class Operation extends SwaggerElement {
*
* <p>
* A declaration of which security schemes are applied for this operation.
- * The list of values describes alternative security schemes that can be used (that is, there is a logical OR
+ * <br>The list of values describes alternative security schemes that can be used (that is, there is a logical OR
* between the security requirements).
+ *
+ * <p>
* This definition overrides any declared top-level security.
- * To remove a top-level <code>security</code> declaration, an empty array can be used.
+ * <br>To remove a top-level <code>security</code> declaration, an empty array can be used.
*
- * @param security The new value for the <property>security</property> property on this bean.
+ * @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 Operation setSecurity(List<Map<String,List<String>>> security) {
- this.security = security;
+ public Operation setSecurity(Collection<Map<String,List<String>>> value) {
+ security = newList(value);
return this;
}
/**
- * Bean property adder: <property>security</property>.
+ * Adds one or more values to the <property>security</property> property.
*
* <p>
* A declaration of which security schemes are applied for this operation.
- * The list of values describes alternative security schemes that can be used (that is, there is a logical OR
+ * <br>The list of values describes alternative security schemes that can be used (that is, there is a logical OR
* between the security requirements).
+ *
+ * <p>
* This definition overrides any declared top-level security.
- * To remove a top-level <code>security</code> declaration, an empty array can be used.
+ * <br>To remove a top-level <code>security</code> declaration, an empty array can be used.
*
- * @param security The new value to add to the <property>security</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
+ * The new value for this property.
* @return This object (for method chaining).
*/
- public Operation addSecurity(Map<String,List<String>> security) {
- if (this.security == null)
- this.security = new LinkedList<>();
- this.security.add(security);
+ public Operation addSecurity(Collection<Map<String,List<String>>> values) {
+ security = addToList(security, values);
return this;
}
/**
- * Synonym for {@link #addSecurity(Map)}.
+ * Same as {@link #addSecurity(Collection)}.
*
- * @param scheme The security scheme that applies to this operation
+ * @param scheme
+ * The scheme name.
* @param alternatives
* The list of values describes alternative security schemes that can be used (that is, there is a logical OR
* between the security requirements).
@@ -865,6 +946,72 @@ public class Operation extends SwaggerElement {
public Operation security(String scheme, String...alternatives) {
Map<String,List<String>> m = new LinkedHashMap<>();
m.put(scheme, Arrays.asList(alternatives));
- return addSecurity(m);
+ return addSecurity(Collections.singletonList(m));
+ }
+
+ /**
+ * Same as {@link #addSecurity(Collection)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,List<String>></code>
+ * <li><code>String</code> - JSON object representation of a <code>Map<String,List<String>></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * securities(<js>"{key:['val1','val2']}"</js>);
+ * </p>
+ * </ul>
+ * @return This object (for method chaining).
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public Operation securities(Object...value) {
+ security = addToList((List)security, value, Map.class, String.class, List.class, String.class);
+ return this;
+ }
+
+ @Override /* SwaggerElement */
+ public <T> T get(String property, Class<T> type) {
+ if (property == null)
+ return null;
+ switch (property) {
+ case "tags": return toType(getTags(), type);
+ case "summary": return toType(getSummary(), type);
+ case "description": return toType(getDescription(), type);
+ case "externalDocs": return toType(getExternalDocs(), type);
+ case "operationId": return toType(getOperationId(), type);
+ case "consumes": return toType(getConsumes(), type);
+ case "produces": return toType(getProduces(), type);
+ case "parameters": return toType(getParameters(), type);
+ case "responses": return toType(getResponses(), type);
+ case "schemes": return toType(getSchemes(), type);
+ case "deprecated": return toType(getDeprecated(), type);
+ case "security": return toType(getSecurity(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public Operation set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "tags": return setTags(null).tags(value);
+ case "summary": return summary(value);
+ case "description": return description(value);
+ case "externalDocs": return externalDocs(value);
+ case "operationId": return operationId(value);
+ case "consumes": return setConsumes(null).consumes(value);
+ case "produces": return setProduces(null).produces(value);
+ case "parameters": return setParameters(null).parameters(value);
+ case "responses": return setResponses(null).responses(value);
+ case "schemes": return setSchemes(null).schemes(value);
+ case "deprecated": return deprecated(value);
+ case "security": return setSecurity(null).securities(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
[07/10] juneau git commit: JUNEAU-78
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
index ee1c6bb..a782325 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import static org.apache.juneau.internal.ArrayUtils.*;
import java.util.*;
@@ -24,6 +25,17 @@ import org.apache.juneau.annotation.*;
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * HeaderInfo x = <jsm>headerInfo</jsm>(<js>"integer"</js>).description(<js>"The number of allowed requests in the current period"</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'>
+ * <jc>// Output</jc>
* {
* <js>"description"</js>: <js>"The number of allowed requests in the current period"</js>,
* <js>"type"</js>: <js>"integer"</js>
@@ -32,44 +44,38 @@ import org.apache.juneau.annotation.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="description,type,format,items,collectionFormat,default,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,enum,multipleOf")
+@Bean(properties="description,type,format,items,collectionFormat,default,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,enum,multipleOf,*")
@SuppressWarnings({"unchecked"})
public class HeaderInfo extends SwaggerElement {
private static final String[] VALID_TYPES = {"string", "number", "integer", "boolean", "array"};
private static final String[] VALID_COLLECTION_FORMATS = {"csv","ssv","tsv","pipes","multi"};
- private String description;
- private String type;
- private String format;
+ private String
+ description,
+ type,
+ format,
+ collectionFormat,
+ pattern;
+ private Number
+ maximum,
+ minimum,
+ multipleOf;
+ private Integer
+ maxLength,
+ minLength,
+ maxItems,
+ minItems;
+ private Boolean
+ exclusiveMaximum,
+ exclusiveMinimum,
+ uniqueItems;
private Items items;
- private String collectionFormat;
private Object _default;
- private Number maximum;
- private Boolean exclusiveMaximum;
- private Number minimum;
- private Boolean exclusiveMinimum;
- private Integer maxLength;
- private Integer minLength;
- private String pattern;
- private Integer maxItems;
- private Integer minItems;
- private Boolean uniqueItems;
private List<Object> _enum;
- private Number multipleOf;
@Override /* SwaggerElement */
protected HeaderInfo strict() {
@@ -83,8 +89,7 @@ public class HeaderInfo extends SwaggerElement {
* <p>
* A short description of the header.
*
- * @return
- * The value of the <property>description</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDescription() {
return description;
@@ -96,33 +101,36 @@ public class HeaderInfo extends SwaggerElement {
* <p>
* A short description of the header.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @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 HeaderInfo setDescription(String description) {
- this.description = description;
+ public HeaderInfo setDescription(String value) {
+ description = value;
return this;
}
/**
- * Synonym for {@link #description(String)}.
+ * Same as {@link #setDescription(String)}.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo description(String description) {
- return setDescription(description);
+ public HeaderInfo description(Object value) {
+ return setDescription(toStringVal(value));
}
/**
* Bean property getter: <property>type</property>.
*
* <p>
- * Required. The type of the object.
- * The value MUST be one of <js>"string"</js>, <js>"number"</js>, <js>"integer"</js>, <js>"boolean"</js>, or <
- * js>"array"</js>.
+ * The type of the object.
*
- * @return The value of the <property>type</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getType() {
return type;
@@ -132,31 +140,42 @@ public class HeaderInfo extends SwaggerElement {
* Bean property setter: <property>type</property>.
*
* <p>
- * Required. The type of the object.
- * The value MUST be one of <js>"string"</js>, <js>"number"</js>, <js>"integer"</js>, <js>"boolean"</js>, or
- * <js>"array"</js>.
+ * The type of the object.
*
- * @param type The new value for the <property>type</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"string"</js>
+ * <li><js>"number"</js>
+ * <li><js>"integer"</js>
+ * <li><js>"boolean"</js>
+ * <li><js>"array"</js>
+ * </ul>
* @return This object (for method chaining).
*/
- public HeaderInfo setType(String type) {
- if (isStrict() && ! contains(type, VALID_TYPES))
+ public HeaderInfo setType(String value) {
+ if (isStrict() && ! contains(value, VALID_TYPES))
throw new FormattedRuntimeException(
"Invalid value passed in to setType(String). Value=''{0}'', valid values={1}",
- type, VALID_TYPES
+ value, VALID_TYPES
);
- this.type = type;
+ type = value;
return this;
}
/**
- * Synonym for {@link #setType(String)}.
+ * Same as {@link #setType(String)}.
*
- * @param type The new value for the <property>type</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo type(String type) {
- return setType(type);
+ public HeaderInfo type(Object value) {
+ return setType(toStringVal(value));
}
/**
@@ -164,10 +183,13 @@ public class HeaderInfo extends SwaggerElement {
*
* <p>
* The extending format for the previously mentioned <code>type</code>.
- * See <a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a> for further
- * details.
*
- * @return The value of the <property>format</property> property on this bean, or <jk>null</jk> if it is not set.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a>
+ * </ul>
+ *
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getFormat() {
return format;
@@ -178,35 +200,42 @@ public class HeaderInfo extends SwaggerElement {
*
* <p>
* The extending format for the previously mentioned <code>type</code>.
- * See <a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a> for further
- * details.
*
- * @param format The new value for the <property>format</property> property on this bean.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://swagger.io/specification/#dataTypeFormat">Data Type Formats</a>
+ * </ul>
+ *
+ * @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 HeaderInfo setFormat(String format) {
- this.format = format;
+ public HeaderInfo setFormat(String value) {
+ format = value;
return this;
}
/**
- * Synonym for {@link #setFormat(String)}.
+ * Same as {@link #setFormat(String)}.
*
- * @param format The new value for the <property>format</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo format(String format) {
- return setFormat(format);
+ public HeaderInfo format(Object value) {
+ return setFormat(toStringVal(value));
}
/**
* Bean property getter: <property>items</property>.
*
* <p>
- * Required if <code>type</code> is <js>"array"</js>.
* Describes the type of items in the array.
*
- * @return The value of the <property>items</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Items getItems() {
return items;
@@ -216,25 +245,38 @@ public class HeaderInfo extends SwaggerElement {
* Bean property setter: <property>items</property>.
*
* <p>
- * Required if <code>type</code> is <js>"array"</js>.
* Describes the type of items in the array.
*
- * @param items The new value for the <property>items</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required if <code>type</code> is <js>"array"</js>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo setItems(Items items) {
- this.items = items;
+ public HeaderInfo setItems(Items value) {
+ items = value;
return this;
}
/**
- * Synonym for {@link #setItems(Items)}.
+ * Same as {@link #setItems(Items)}.
*
- * @param items The new value for the <property>items</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link Items}
+ * <li><code>String</code> - JSON object representation of {@link Items}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * items(<js>"{type:'type',format:'format',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo items(Items items) {
- return setItems(items);
+ public HeaderInfo items(Object value) {
+ return setItems(toType(value, Items.class));
}
/**
@@ -242,21 +284,8 @@ public class HeaderInfo extends SwaggerElement {
*
* <p>
* Determines the format of the array if type array is used.
- * <p>
- *
- * Possible values are:
- * <ul>
- * <li><code>csv</code> - comma separated values <code>foo,bar</code>.
- * <li><code>ssv</code> - space separated values <code>foo bar</code>.
- * <li><code>tsv</code> - tab separated values <code>foo\tbar</code>.
- * <li><code>pipes</code> - pipe separated values <code>foo|bar</code>.
- * </ul>
- *
- * <p>
- * Default value is <code>csv</code>.
*
- * @return
- * The value of the <property>collectionFormat</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getCollectionFormat() {
return collectionFormat;
@@ -268,39 +297,38 @@ public class HeaderInfo extends SwaggerElement {
* <p>
* Determines the format of the array if type array is used.
*
- * <p>
- * Possible values are:
- * <ul>
- * <li><code>csv</code> - comma separated values <code>foo,bar</code>.
- * <li><code>ssv</code> - space separated values <code>foo bar</code>.
- * <li><code>tsv</code> - tab separated values <code>foo\tbar</code>.
- * <li><code>pipes</code> - pipe separated values <code>foo|bar</code>.
- * </ul>
- *
- * <p>
- * Default value is <code>csv</code>.
- *
- * @param collectionFormat The new value for the <property>collectionFormat</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"csv"</js> (default) - comma separated values <code>foo,bar</code>.
+ * <li><js>"ssv"</js> - space separated values <code>foo bar</code>.
+ * <li><js>"tsv"</js> - tab separated values <code>foo\tbar</code>.
+ * <li><js>"pipes"</js> - pipe separated values <code>foo|bar</code>.
+ * </ul>
* @return This object (for method chaining).
*/
- public HeaderInfo setCollectionFormat(String collectionFormat) {
- if (isStrict() && ! contains(collectionFormat, VALID_COLLECTION_FORMATS))
+ public HeaderInfo setCollectionFormat(String value) {
+ if (isStrict() && ! contains(value, VALID_COLLECTION_FORMATS))
throw new FormattedRuntimeException(
"Invalid value passed in to setCollectionFormat(String). Value=''{0}'', valid values={1}",
- collectionFormat, VALID_COLLECTION_FORMATS
+ value, VALID_COLLECTION_FORMATS
);
- this.collectionFormat = collectionFormat;
+ collectionFormat = value;
return this;
}
/**
- * Synonym for {@link #setCollectionFormat(String)}.
+ * Same as {@link #setCollectionFormat(String)}.
*
- * @param collectionFormat The new value for the <property>collectionFormat</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo collectionFormat(String collectionFormat) {
- return setCollectionFormat(collectionFormat);
+ public HeaderInfo collectionFormat(Object value) {
+ return setCollectionFormat(toStringVal(value));
}
/**
@@ -308,12 +336,19 @@ public class HeaderInfo extends SwaggerElement {
*
* <p>
* Declares the value of the header that the server will use if none is provided.
- * (Note: <js>"default"</js> has no meaning for required items.)
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">
- * http://json-schema.org/latest/json-schema-validation.html#anchor101</a>.
- * Unlike JSON Schema this value MUST conform to the defined <code>type</code> for the header.
*
- * @return The value of the <property>_default</property> property on this bean, or <jk>null</jk> if it is not set.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li><js>"default"</js> has no meaning for required items.
+ * <li>Unlike JSON Schema this value MUST conform to the defined <code>type</code> for the header.
+ * </ul>
+ *
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">http://json-schema.org/latest/json-schema-validation.html#anchor101</a>
+ * </ul>
+ *
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Object getDefault() {
return _default;
@@ -324,37 +359,47 @@ public class HeaderInfo extends SwaggerElement {
*
* <p>
* Declares the value of the header that the server will use if none is provided.
- * (Note: <js>"default"</js> has no meaning for required items.)
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">
- * http://json-schema.org/latest/json-schema-validation.html#anchor101</a>.
- * Unlike JSON Schema this value MUST conform to the defined <code>type</code> for the header.
*
- * @param _default The new value for the <property>_default</property> property on this bean.
+ * <h5 class='section'>Notes:</h5>
+ * <ul>
+ * <li><js>"default"</js> has no meaning for required items.
+ * <li>Unlike JSON Schema this value MUST conform to the defined <code>type</code> for the header.
+ * </ul>
+ *
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor101">http://json-schema.org/latest/json-schema-validation.html#anchor101</a>
+ * </ul>
+ *
+ * @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 HeaderInfo setDefault(Object _default) {
- this._default = _default;
+ public HeaderInfo setDefault(Object value) {
+ _default = value;
return this;
}
/**
- * Synonym for {@link #setDefault(Object)}.
+ * Same as {@link #setDefault(Object)}.
*
- * @param _default The new value for the <property>_default</property> property on this bean.
+ * @param value The new value for this property.
* @return This object (for method chaining).
*/
- public HeaderInfo _default(Object _default) {
- return setDefault(_default);
+ public HeaderInfo _default(Object value) {
+ return setDefault(value);
}
/**
* Bean property getter: <property>maximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @return The value of the <property>maximum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMaximum() {
return maximum;
@@ -363,37 +408,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>maximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @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 HeaderInfo setMaximum(Number maximum) {
- this.maximum = maximum;
+ public HeaderInfo setMaximum(Number value) {
+ maximum = value;
return this;
}
/**
- * Synonym for {@link #setMaximum(Number)}.
+ * Same as {@link #setMaximum(Number)}.
*
- * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo maximum(Number maximum) {
- return setMaximum(maximum);
+ public HeaderInfo maximum(Object value) {
+ return setMaximum(toNumber(value));
}
/**
* Bean property getter: <property>exclusiveMaximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @return The value of the <property>exclusiveMaximum</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getExclusiveMaximum() {
return exclusiveMaximum;
@@ -402,36 +453,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>exclusiveMaximum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">
- * http://json-schema.org/latest/json-schema-validation.html#anchor17</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor17">http://json-schema.org/latest/json-schema-validation.html#anchor17</a>
+ * </ul>
*
- * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @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 HeaderInfo setExclusiveMaximum(Boolean exclusiveMaximum) {
- this.exclusiveMaximum = exclusiveMaximum;
+ public HeaderInfo setExclusiveMaximum(Boolean value) {
+ exclusiveMaximum = value;
return this;
}
/**
- * Synonym for {@link #setExclusiveMaximum(Boolean)}.
+ * Same as {@link #setExclusiveMaximum(Boolean)}.
*
- * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo exclusiveMaximum(Boolean exclusiveMaximum) {
- return setExclusiveMaximum(exclusiveMaximum);
+ public HeaderInfo exclusiveMaximum(Object value) {
+ return setExclusiveMaximum(toBoolean(value));
}
/**
* Bean property getter: <property>minimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @return The value of the <property>minimum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMinimum() {
return minimum;
@@ -440,37 +498,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>minimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @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 HeaderInfo setMinimum(Number minimum) {
- this.minimum = minimum;
+ public HeaderInfo setMinimum(Number value) {
+ minimum = value;
return this;
}
/**
- * Synonym for {@link #setMinimum(Number)}.
+ * Same as {@link #setMinimum(Number)}.
*
- * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo minimum(Number minimum) {
- return setMinimum(minimum);
+ public HeaderInfo minimum(Object value) {
+ return setMinimum(toNumber(value));
}
/**
* Bean property getter: <property>exclusiveMinimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @return The value of the <property>exclusiveMinimum</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getExclusiveMinimum() {
return exclusiveMinimum;
@@ -479,36 +543,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>exclusiveMinimum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">
- * http://json-schema.org/latest/json-schema-validation.html#anchor21</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor21">http://json-schema.org/latest/json-schema-validation.html#anchor21</a>
+ * </ul>
*
- * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @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 HeaderInfo setExclusiveMinimum(Boolean exclusiveMinimum) {
- this.exclusiveMinimum = exclusiveMinimum;
+ public HeaderInfo setExclusiveMinimum(Boolean value) {
+ exclusiveMinimum = value;
return this;
}
/**
- * Synonym for {@link #setExclusiveMinimum(Boolean)}.
+ * Same as {@link #setExclusiveMinimum(Boolean)}.
*
- * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo exclusiveMinimum(Boolean exclusiveMinimum) {
- return setExclusiveMinimum(exclusiveMinimum);
+ public HeaderInfo exclusiveMinimum(Object value) {
+ return setExclusiveMinimum(toBoolean(value));
}
/**
* Bean property getter: <property>maxLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">
- * http://json-schema.org/latest/json-schema-validation.html#anchor26</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">http://json-schema.org/latest/json-schema-validation.html#anchor26</a>
+ * </ul>
*
- * @return The value of the <property>maxLength</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMaxLength() {
return maxLength;
@@ -517,36 +588,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>maxLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">
- * http://json-schema.org/latest/json-schema-validation.html#anchor26</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor26">http://json-schema.org/latest/json-schema-validation.html#anchor26</a>
+ * </ul>
*
- * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @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 HeaderInfo setMaxLength(Integer maxLength) {
- this.maxLength = maxLength;
+ public HeaderInfo setMaxLength(Integer value) {
+ maxLength = value;
return this;
}
/**
- * Synonym for {@link #setMaxLength(Integer)}.
+ * Same as {@link #setMaxLength(Integer)}.
*
- * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo maxLength(Integer maxLength) {
- return setMaxLength(maxLength);
+ public HeaderInfo maxLength(Object value) {
+ return setMaxLength(toInteger(value));
}
/**
* Bean property getter: <property>minLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">
- * http://json-schema.org/latest/json-schema-validation.html#anchor29</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">http://json-schema.org/latest/json-schema-validation.html#anchor29</a>
+ * </ul>
*
- * @return The value of the <property>minLength</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMinLength() {
return minLength;
@@ -555,34 +633,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>minLength</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">
- * http://json-schema.org/latest/json-schema-validation.html#anchor29</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor29">http://json-schema.org/latest/json-schema-validation.html#anchor29</a>
+ * </ul>
*
- * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @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 HeaderInfo setMinLength(Integer minLength) {
- this.minLength = minLength;
+ public HeaderInfo setMinLength(Integer value) {
+ minLength = value;
return this;
}
/**
- * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * Same as {@link #setMinLength(Integer)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo minLength(Integer minLength) {
- return setMinLength(minLength);
+ public HeaderInfo minLength(Object value) {
+ return setMinLength(toInteger(value));
}
/**
* Bean property getter: <property>pattern</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">
- * http://json-schema.org/latest/json-schema-validation.html#anchor33</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">http://json-schema.org/latest/json-schema-validation.html#anchor33</a>
+ * </ul>
*
- * @return The value of the <property>pattern</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getPattern() {
return pattern;
@@ -591,36 +678,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>pattern</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">
- * http://json-schema.org/latest/json-schema-validation.html#anchor33</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor33">http://json-schema.org/latest/json-schema-validation.html#anchor33</a>
+ * </ul>
*
- * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @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 HeaderInfo setPattern(String pattern) {
- this.pattern = pattern;
+ public HeaderInfo setPattern(String value) {
+ pattern = value;
return this;
}
/**
- * Synonym for {@link #setPattern(String)}.
+ * Same as {@link #setPattern(String)}.
*
- * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo pattern(String pattern) {
- return setPattern(pattern);
+ public HeaderInfo pattern(Object value) {
+ return setPattern(toStringVal(value));
}
/**
* Bean property getter: <property>maxItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">
- * http://json-schema.org/latest/json-schema-validation.html#anchor42</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">http://json-schema.org/latest/json-schema-validation.html#anchor42</a>
+ * </ul>
*
- * @return The value of the <property>maxItems</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMaxItems() {
return maxItems;
@@ -629,36 +723,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>maxItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">
- * http://json-schema.org/latest/json-schema-validation.html#anchor42</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor42">http://json-schema.org/latest/json-schema-validation.html#anchor42</a>
+ * </ul>
*
- * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @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 HeaderInfo setMaxItems(Integer maxItems) {
- this.maxItems = maxItems;
+ public HeaderInfo setMaxItems(Integer value) {
+ maxItems = value;
return this;
}
/**
- * Synonym for {@link #setMaxItems(Integer)}.
+ * Same as {@link #setMaxItems(Integer)}.
*
- * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo maxItems(Integer maxItems) {
- return setMaxItems(maxItems);
+ public HeaderInfo maxItems(Object value) {
+ return setMaxItems(toInteger(value));
}
/**
* Bean property getter: <property>minItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">
- * http://json-schema.org/latest/json-schema-validation.html#anchor45</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">http://json-schema.org/latest/json-schema-validation.html#anchor45</a>
+ * </ul>
*
- * @return The value of the <property>minItems</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Integer getMinItems() {
return minItems;
@@ -667,36 +768,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>minItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">
- * http://json-schema.org/latest/json-schema-validation.html#anchor45</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor45">http://json-schema.org/latest/json-schema-validation.html#anchor45</a>
+ * </ul>
*
- * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @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 HeaderInfo setMinItems(Integer minItems) {
- this.minItems = minItems;
+ public HeaderInfo setMinItems(Integer value) {
+ minItems = value;
return this;
}
/**
- * Synonym for {@link #setMinItems(Integer)}.
+ * Same as {@link #setMinItems(Integer)}.
*
- * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Integer values will be converted to Integer using <code>Integer.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo minItems(Integer minItems) {
- return setMinItems(minItems);
+ public HeaderInfo minItems(Object value) {
+ return setMinItems(toInteger(value));
}
/**
* Bean property getter: <property>uniqueItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">
- * http://json-schema.org/latest/json-schema-validation.html#anchor49</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">http://json-schema.org/latest/json-schema-validation.html#anchor49</a>
+ * </ul>
*
- * @return The value of the <property>uniqueItems</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Boolean getUniqueItems() {
return uniqueItems;
@@ -705,36 +813,43 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>uniqueItems</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">
- * http://json-schema.org/latest/json-schema-validation.html#anchor49</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor49">http://json-schema.org/latest/json-schema-validation.html#anchor49</a>
+ * </ul>
*
- * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @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 HeaderInfo setUniqueItems(Boolean uniqueItems) {
- this.uniqueItems = uniqueItems;
+ public HeaderInfo setUniqueItems(Boolean value) {
+ uniqueItems = value;
return this;
}
/**
- * Synonym for {@link #setUniqueItems(Boolean)}.
+ * Same as {@link #setUniqueItems(Boolean)}.
*
- * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo uniqueItems(Boolean uniqueItems) {
- return setUniqueItems(uniqueItems);
+ public HeaderInfo uniqueItems(Object value) {
+ return setUniqueItems(toBoolean(value));
}
/**
* Bean property getter: <property>enum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">
- * http://json-schema.org/latest/json-schema-validation.html#anchor76</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">http://json-schema.org/latest/json-schema-validation.html#anchor76</a>
+ * </ul>
*
- * @return The value of the <property>enum</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<Object> getEnum() {
return _enum;
@@ -743,63 +858,71 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>enum</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">
- * http://json-schema.org/latest/json-schema-validation.html#anchor76</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">http://json-schema.org/latest/json-schema-validation.html#anchor76</a>
+ * </ul>
*
- * @param _enum The new value for the <property>enum</property> property on this bean.
+ * @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 HeaderInfo setEnum(List<Object> _enum) {
- this._enum = _enum;
- return this;
- }
-
- /**
- * Bean property adder: <property>enum</property>.
- *
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor76">
- * http://json-schema.org/latest/json-schema-validation.html#anchor76</a>.
- *
- * @param _enum
- * The new values to add to the <property>enum</property> property on this bean.
- * These can either be individual objects or {@link Collection Collections} of objects.
- * @return This object (for method chaining).
- */
- public HeaderInfo addEnum(Object..._enum) {
- for (Object o : _enum) {
- if (o != null) {
- if (o instanceof Collection)
- addEnum((Collection<Object>)o);
- else {
- if (this._enum == null)
- this._enum = new LinkedList<>();
- this._enum.add(o);
- }
- }
- }
+ public HeaderInfo setEnum(Collection<Object> value) {
+ _enum = newList(value);
return this;
}
/**
- * Synonym for {@link #addEnum(Object...)}.
+ * Adds one or more values to the <property>enum</property> property.
*
- * @param _enum The new value for the <property>enum</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public HeaderInfo _enum(Object..._enum) {
- return addEnum(_enum);
+ public HeaderInfo addEnum(Collection<Object> values) {
+ _enum = addToList(_enum, values);
+ return this;
}
-
+
+ /**
+ * Adds one or more values to the <property>enum</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Object</code>
+ * <li><code>Collection<Object></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<Object></code>.
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * _enum(<js>"['foo','bar']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values.
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * _enum(<js>"foo"</js>, <js>"bar"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo _enum(Object...values) {
+ _enum = addToList(_enum, values, Object.class);
+ return this;
+ }
+
/**
* Bean property getter: <property>multipleOf</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">
- * http://json-schema.org/latest/json-schema-validation.html#anchor14</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">http://json-schema.org/latest/json-schema-validation.html#anchor14</a>
+ * </ul>
*
- * @return The value of the <property>multipleOf</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Number getMultipleOf() {
return multipleOf;
@@ -808,25 +931,87 @@ public class HeaderInfo extends SwaggerElement {
/**
* Bean property setter: <property>multipleOf</property>.
*
- * <p>
- * See <a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">
- * http://json-schema.org/latest/json-schema-validation.html#anchor14</a>.
+ * <h5 class='section'>Additional Info:</h5>
+ * <ul>
+ * <li><a class="doclink" href="http://json-schema.org/latest/json-schema-validation.html#anchor14">http://json-schema.org/latest/json-schema-validation.html#anchor14</a>
+ * </ul>
*
- * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @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 HeaderInfo setMultipleOf(Number multipleOf) {
- this.multipleOf = multipleOf;
+ public HeaderInfo setMultipleOf(Number value) {
+ multipleOf = value;
return this;
}
/**
- * Synonym for {@link #setMultipleOf(Number)}.
+ * Same as {@link #setMultipleOf(Number)}.
*
- * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-Number values will be converted to Number using <code>toString()</code> then best number match.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public HeaderInfo multipleOf(Number multipleOf) {
- return setMultipleOf(multipleOf);
+ public HeaderInfo multipleOf(Object value) {
+ return setMultipleOf(toNumber(value));
+ }
+
+ @Override /* SwaggerElement */
+ public <T> T get(String property, Class<T> type) {
+ if (property == null)
+ return null;
+ switch (property) {
+ case "description": return (T)getDescription();
+ case "type": return toType(getType(), type);
+ case "format": return toType(getFormat(), type);
+ case "items": return toType(getItems(), type);
+ case "collectionFormat": return toType(getCollectionFormat(), type);
+ case "default": return toType(getDefault(), type);
+ case "maximum": return toType(getMaximum(), type);
+ case "exclusiveMaximum": return toType(getExclusiveMaximum(), type);
+ case "minimum": return toType(getMinimum(), type);
+ case "exclusiveMinimum": return toType(getExclusiveMinimum(), type);
+ case "maxLength": return toType(getMaxLength(), type);
+ case "minLength": return toType(getMinLength(), type);
+ case "pattern": return toType(getPattern(), type);
+ case "maxItems": return toType(getMaxItems(), type);
+ case "minItems": return toType(getMinItems(), type);
+ case "uniqueItems": return toType(getUniqueItems(), type);
+ case "enum": return toType(getEnum(), type);
+ case "multipleOf": return toType(getMultipleOf(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public HeaderInfo set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "description": return description(value);
+ case "type": return type(value);
+ case "format": return format(value);
+ case "items": return items(value);
+ case "collectionFormat": return collectionFormat(value);
+ case "default": return _default(value);
+ case "maximum": return maximum(value);
+ case "exclusiveMaximum": return exclusiveMaximum(value);
+ case "minimum": return minimum(value);
+ case "exclusiveMinimum": return exclusiveMinimum(value);
+ case "maxLength": return maxLength(value);
+ case "minLength": return minLength(value);
+ case "pattern": return pattern(value);
+ case "maxItems": return maxItems(value);
+ case "minItems": return minItems(value);
+ case "uniqueItems": return uniqueItems(value);
+ case "enum": return setEnum(null)._enum(value);
+ case "multipleOf": return multipleOf(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Info.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Info.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Info.java
index 35cfe6c..913dde2 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Info.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Info.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import org.apache.juneau.annotation.*;
/**
@@ -20,6 +21,25 @@ import org.apache.juneau.annotation.*;
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
+ * <jc>// Construct using SwaggerBuilder.</jc>
+ * Info x = <jsm>info</jsm>(<js>"Swagger Sample App"</js>, <js>"1.0.1"</js>)
+ * .description(<js>"This is a sample server Petstore server."</js>)
+ * .termsOfService(<js>"http://swagger.io/terms/"</js>)
+ * .contact(
+ * <jsm>contact</jsm>(<js>"API Support"</js>, <js>"http://www.swagger.io/support"</js>, <js>"support@swagger.io"</js>)
+ * )
+ * .license(
+ * <jsm>license</jsm>(<js>"Apache 2.0"</js>, <js>"http://www.apache.org/licenses/LICENSE-2.0.html"</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'>
+ * <jc>// Output</jc>
* {
* <js>"title"</js>: <js>"Swagger Sample App"</js>,
* <js>"description"</js>: <js>"This is a sample server Petstore server."</js>,
@@ -39,36 +59,27 @@ import org.apache.juneau.annotation.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="title,description,termsOfService,contact,license,version")
+@Bean(properties="title,description,termsOfService,contact,license,version,*")
public class Info extends SwaggerElement {
- private String title;
- private String description;
- private String termsOfService;
+ private String
+ title,
+ description,
+ termsOfService,
+ version;
private Contact contact;
private License license;
- private String version;
/**
* Bean property getter: <property>title</property>.
*
* <p>
- * Required. The title of the application.
+ * The title of the application.
*
- * @return The value of the <property>title</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getTitle() {
return title;
@@ -78,34 +89,38 @@ public class Info extends SwaggerElement {
* Bean property setter: <property>title</property>.
*
* <p>
- * Required. The title of the application.
+ * The title of the application.
*
- * @param title The new value for the <property>title</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public Info setTitle(String title) {
- this.title = title;
+ public Info setTitle(String value) {
+ title = value;
return this;
}
/**
- * Synonym for {@link #setTitle(String)}.
+ * Same as {@link #setTitle(String)}.
*
- * @param title The new value for the <property>title</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Info title(String title) {
- return setTitle(title);
+ public Info title(Object value) {
+ return setTitle(toStringVal(value));
}
/**
* Bean property getter: <property>description</property>.
*
* <p>
- * A short description of the application. GFM syntax can be used for rich text representation.
+ * A short description of the application.
*
- * @return
- * The value of the <property>description</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDescription() {
return description;
@@ -115,24 +130,31 @@ public class Info extends SwaggerElement {
* Bean property setter: <property>description</property>.
*
* <p>
- * A short description of the application. GFM syntax can be used for rich text representation.
+ * A short description of the application.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Info setDescription(String description) {
- this.description = description;
+ public Info setDescription(String value) {
+ description = value;
return this;
}
/**
- * Synonym for {@link #setDescription(String)}.
+ * Same as {@link #setDescription(String)}.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Info description(String description) {
- return setDescription(description);
+ public Info description(Object value) {
+ return setDescription(toStringVal(value));
}
/**
@@ -141,8 +163,7 @@ public class Info extends SwaggerElement {
* <p>
* The Terms of Service for the API.
*
- * @return The value of the <property>termsOfService</property> property on this bean, or <jk>null</jk> if it is not
- * set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getTermsOfService() {
return termsOfService;
@@ -154,22 +175,27 @@ public class Info extends SwaggerElement {
* <p>
* The Terms of Service for the API.
*
- * @param termsOfService The new value for the <property>termsOfService</property> property on this bean.
+ * @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 Info setTermsOfService(String termsOfService) {
- this.termsOfService = termsOfService;
+ public Info setTermsOfService(String value) {
+ termsOfService = value;
return this;
}
/**
- * Synonym for {@link #setTermsOfService(String)}.
+ * Same as {@link #setTermsOfService(String)}.
*
- * @param termsOfService The new value for the <property>termsOfService</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Info termsOfService(String termsOfService) {
- return setTermsOfService(termsOfService);
+ public Info termsOfService(Object value) {
+ return setTermsOfService(toStringVal(value));
}
/**
@@ -178,7 +204,7 @@ public class Info extends SwaggerElement {
* <p>
* The contact information for the exposed API.
*
- * @return The value of the <property>contact</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Contact getContact() {
return contact;
@@ -190,22 +216,35 @@ public class Info extends SwaggerElement {
* <p>
* The contact information for the exposed API.
*
- * @param contact The new value for the <property>contact</property> property on this bean.
+ * @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 Info setContact(Contact contact) {
- this.contact = contact;
+ public Info setContact(Contact value) {
+ contact = value;
return this;
}
/**
- * Synonym for {@link #setContact(Contact)}.
+ * Same as {@link #setContact(Contact)}.
*
- * @param contact The new value for the <property>contact</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link Contact}
+ * <li><code>String</code> - JSON object representation of {@link Contact}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * contact(<js>"{name:'name',url:'url',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Info contact(Contact contact) {
- return setContact(contact);
+ public Info contact(Object value) {
+ return setContact(toType(value, Contact.class));
}
/**
@@ -214,7 +253,7 @@ public class Info extends SwaggerElement {
* <p>
* The license information for the exposed API.
*
- * @return The value of the <property>license</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public License getLicense() {
return license;
@@ -226,31 +265,44 @@ public class Info extends SwaggerElement {
* <p>
* The license information for the exposed API.
*
- * @param license The new value for the <property>license</property> property on this bean.
+ * @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 Info setLicense(License license) {
- this.license = license;
+ public Info setLicense(License value) {
+ license = value;
return this;
}
/**
- * Synonym for {@link #setLicense(License)}.
+ * Same as {@link #setLicense(License)}.
*
- * @param license The new value for the <property>license</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link License}
+ * <li><code>String</code> - JSON object representation of {@link License}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * license(<js>"{name:'name',url:'url',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Info license(License license) {
- return setLicense(license);
+ public Info license(Object value) {
+ return setLicense(toType(value, License.class));
}
/**
* Bean property getter: <property>version</property>.
*
* <p>
- * Required. Provides the version of the application API (not to be confused with the specification version).
+ * Provides the version of the application API (not to be confused with the specification version).
*
- * @return The value of the <property>version</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getVersion() {
return version;
@@ -260,23 +312,60 @@ public class Info extends SwaggerElement {
* Bean property setter: <property>version</property>.
*
* <p>
- * Required. Provides the version of the application API (not to be confused with the specification version).
+ * Provides the version of the application API (not to be confused with the specification version).
*
- * @param version The new value for the <property>version</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public Info setVersion(String version) {
- this.version = version;
+ public Info setVersion(String value) {
+ version = value;
return this;
}
/**
- * Synonym for {@link #setVersion(String)}.
+ * Same as {@link #setVersion(String)}.
*
- * @param version The new value for the <property>version</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Info version(String version) {
- return setVersion(version);
+ public Info version(Object value) {
+ return setVersion(toStringVal(value));
+ }
+
+ @Override /* SwaggerElement */
+ public <T> T get(String property, Class<T> type) {
+ if (property == null)
+ return null;
+ switch (property) {
+ case "title": return toType(getTitle(), type);
+ case "description": return toType(getDescription(), type);
+ case "termsOfService": return toType(getTermsOfService(), type);
+ case "contact": return toType(getContact(), type);
+ case "license": return toType(getLicense(), type);
+ case "version": return toType(getVersion(), type);
+ default: return super.get(property, type);
+ }
+ }
+
+ @Override /* SwaggerElement */
+ public Info set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "title": return title(value);
+ case "description": return description(value);
+ case "termsOfService": return termsOfService(value);
+ case "contact": return contact(value);
+ case "license": return license(value);
+ case "version": return version(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
}
}
[02/10] juneau git commit: JUNEAU-78
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
index 9ec40da..dd66ecd 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
@@ -12,63 +12,55 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import java.util.*;
import org.apache.juneau.annotation.*;
import org.apache.juneau.http.*;
import org.apache.juneau.json.*;
-import org.apache.juneau.utils.*;
/**
* This is the root document object for the API specification.
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="swagger,info,tags,externalDocs,basePath,schemes,consumes,produces,paths,definitions,parameters,responses,securityDefinitions,security")
+@Bean(properties="swagger,info,tags,externalDocs,basePath,schemes,consumes,produces,paths,definitions,parameters,responses,securityDefinitions,security,*")
public class Swagger extends SwaggerElement {
/** Represents a null swagger */
public static final Swagger NULL = new Swagger();
- private String swagger = "2.0";
+ private String
+ swagger = "2.0",
+ host,
+ basePath;
private Info info;
- private String host, basePath;
+ private ExternalDocumentation externalDocs;
private List<String> schemes;
- private List<MediaType> consumes;
- private List<MediaType> produces;
- private Map<String,Map<String,Operation>> paths;
+ private List<MediaType>
+ consumes,
+ produces;
+ private List<Tag> tags;
+ private List<Map<String,List<String>>> security;
private Map<String,SchemaInfo> definitions;
private Map<String,ParameterInfo> parameters;
private Map<String,ResponseInfo> responses;
private Map<String,SecurityScheme> securityDefinitions;
- private List<Map<String,List<String>>> security;
- private List<Tag> tags;
- private ExternalDocumentation externalDocs;
+ private Map<String,Map<String,Operation>> paths;
/**
* Bean property getter: <property>swagger</property>.
*
* <p>
- * Required. Specifies the Swagger Specification version being used.
+ * Specifies the Swagger Specification version being used.
*
* <p>
* It can be used by the Swagger UI and other clients to interpret the API listing.
- * The value MUST be <js>"2.0"</js>.
*
- * @return The value of the <property>swagger</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getSwagger() {
return swagger;
@@ -78,40 +70,44 @@ public class Swagger extends SwaggerElement {
* Bean property setter: <property>swagger</property>.
*
* <p>
- * Required. Specifies the Swagger Specification version being used.
+ * Specifies the Swagger Specification version being used.
*
* <p>
* It can be used by the Swagger UI and other clients to interpret the API listing.
- * The value MUST be <js>"2.0"</js>.
*
- * @param swagger The new value for the <property>swagger</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public Swagger setSwagger(String swagger) {
- this.swagger = swagger;
+ public Swagger setSwagger(String value) {
+ swagger = value;
return this;
}
/**
- * Synonym for {@link #setSwagger(String)}.
+ * Same as {@link #setSwagger(String)}.
*
- * @param swagger The new value for the <property>swagger</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger swagger(String swagger) {
- return setSwagger(swagger);
+ public Swagger swagger(Object value) {
+ return setSwagger(toStringVal(value));
}
/**
* Bean property getter: <property>info</property>.
*
* <p>
- * Required. Provides metadata about the API.
+ * Provides metadata about the API.
*
* <p>
* The metadata can be used by the clients if needed.
*
- * @return The value of the <property>info</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Info getInfo() {
return info;
@@ -121,27 +117,40 @@ public class Swagger extends SwaggerElement {
* Bean property setter: <property>info</property>.
*
* <p>
- * Required. Provides metadata about the API.
+ * Provides metadata about the API.
*
* <p>
* The metadata can be used by the clients if needed.
*
- * @param info The new value for the <property>info</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public Swagger setInfo(Info info) {
- this.info = info;
+ public Swagger setInfo(Info value) {
+ info = value;
return this;
}
/**
- * Synonym for {@link #setInfo(Info)}.
- *
- * @param info The new value for the <property>info</property> property on this bean.
+ * Same as {@link #setInfo(Info)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link Info}
+ * <li><code>String</code> - JSON object representation of {@link Info}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * info(<js>"{title:'title',description:'description',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public Swagger info(Info info) {
- return setInfo(info);
+ public Swagger info(Object value) {
+ return setInfo(toType(value, Info.class));
}
/**
@@ -150,14 +159,7 @@ public class Swagger extends SwaggerElement {
* <p>
* The host (name or IP) serving the API.
*
- * <p>
- * This MUST be the host only and does not include the scheme nor sub-paths.
- * It MAY include a port.
- * If the host is not included, the host serving the documentation is to be used (including the port).
- * The host does not support <a class="doclink" href="http://swagger.io/specification/#pathTemplating">
- * path templating</a>.
- *
- * @return The value of the <property>host</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getHost() {
return host;
@@ -169,29 +171,36 @@ public class Swagger extends SwaggerElement {
* <p>
* The host (name or IP) serving the API.
*
- * <p>
- * This MUST be the host only and does not include the scheme nor sub-paths.
- * It MAY include a port.
- * If the host is not included, the host serving the documentation is to be used (including the port).
- * The host does not support <a class="doclink" href="http://swagger.io/specification/#pathTemplating">
- * path templating</a>.
- *
- * @param host The new value for the <property>host</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>This MUST be the host only and does not include the scheme nor sub-paths.
+ * <br>It MAY include a port.
+ * <br>If the host is not included, the host serving the documentation is to be used (including the port).
+ * <br>The host does not support <a class="doclink" href="http://swagger.io/specification/#pathTemplating">
+ * path templating</a>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger setHost(String host) {
- this.host = host;
+ public Swagger setHost(String value) {
+ host = value;
return this;
}
/**
- * Synonym for {@link #setHost(String)}.
- *
- * @param host The new value for the <property>host</property> property on this bean.
+ * Same as {@link #setHost(String)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>This MUST be the host only and does not include the scheme nor sub-paths.
+ * <br>It MAY include a port.
+ * <br>If the host is not included, the host serving the documentation is to be used (including the port).
+ * <br>The host does not support <a class="doclink" href="http://swagger.io/specification/#pathTemplating">path templating</a>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger host(String host) {
- return setHost(host);
+ public Swagger host(Object value) {
+ return setHost(toStringVal(value));
}
/**
@@ -200,13 +209,7 @@ public class Swagger extends SwaggerElement {
* <p>
* The base path on which the API is served, which is relative to the <code>host</code>.
*
- * <p>
- * If it is not included, the API is served directly under the <code>host</code>.
- * The value MUST start with a leading slash (/).
- * The <code>basePath</code> does not support <a class="doclink"
- * href="http://swagger.io/specification/#pathTemplating">path templating</a>.
- *
- * @return The value of the <property>basePath</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getBasePath() {
return basePath;
@@ -218,28 +221,33 @@ public class Swagger extends SwaggerElement {
* <p>
* The base path on which the API is served, which is relative to the <code>host</code>.
*
- * <p>
- * If it is not included, the API is served directly under the <code>host</code>.
- * The value MUST start with a leading slash (/).
- * The <code>basePath</code> does not support <a class="doclink"
- * href="http://swagger.io/specification/#pathTemplating">path templating</a>.
- *
- * @param basePath The new value for the <property>basePath</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>If it is not included, the API is served directly under the <code>host</code>.
+ * <br>The value MUST start with a leading slash (/).
+ * <br>The <code>basePath</code> does not support <a class="doclink" href="http://swagger.io/specification/#pathTemplating">path templating</a>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger setBasePath(String basePath) {
- this.basePath = basePath;
+ public Swagger setBasePath(String value) {
+ basePath = value;
return this;
}
/**
- * Synonym for {@link #setBasePath(String)}.
- *
- * @param basePath The new value for the <property>basePath</property> property on this bean.
+ * Same as {@link #setBasePath(String)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>If it is not included, the API is served directly under the <code>host</code>.
+ * <br>The value MUST start with a leading slash (/).
+ * <br>The <code>basePath</code> does not support <a class="doclink" href="http://swagger.io/specification/#pathTemplating">path templating</a>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger basePath(String basePath) {
- return setBasePath(basePath);
+ public Swagger basePath(Object value) {
+ return setBasePath(toStringVal(value));
}
/**
@@ -249,11 +257,10 @@ public class Swagger extends SwaggerElement {
* The transfer protocol of the API.
*
* <p>
- * Values MUST be from the list: <js>"http"</js>, <js>"https"</js>, <js>"ws"</js>, <js>"wss"</js>.
* If the <code>schemes</code> is not included, the default scheme to be used is the one used to access the Swagger
* definition itself.
*
- * @return The value of the <property>schemes</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<String> getSchemes() {
return schemes;
@@ -266,20 +273,28 @@ public class Swagger extends SwaggerElement {
* The transfer protocol of the API.
*
* <p>
- * Values MUST be from the list: <js>"http"</js>, <js>"https"</js>, <js>"ws"</js>, <js>"wss"</js>.
* If the <code>schemes</code> is not included, the default scheme to be used is the one used to access the Swagger
* definition itself.
*
- * @param schemes The new value for the <property>schemes</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"http"</js>
+ * <li><js>"https"</js>
+ * <li><js>"ws"</js>
+ * <li><js>"wss"</js>
+ * </ul>
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger setSchemes(List<String> schemes) {
- this.schemes = schemes;
+ public Swagger setSchemes(Collection<String> value) {
+ schemes = newList(value);
return this;
}
/**
- * Bean property adder: <property>schemes</property>.
+ * Adds one or more values to the <property>schemes</property> property.
*
* <p>
* The transfer protocol of the API.
@@ -289,44 +304,47 @@ public class Swagger extends SwaggerElement {
* If the <code>schemes</code> is not included, the default scheme to be used is the one used to access the Swagger
* definition itself.
*
- * @param schemes The values to add for the <property>schemes</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"http"</js>
+ * <li><js>"https"</js>
+ * <li><js>"ws"</js>
+ * <li><js>"wss"</js>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger addSchemes(String...schemes) {
- return addSchemes(Arrays.asList(schemes));
- }
-
- /**
- * Bean property adder: <property>schemes</property>.
- *
- * <p>
- * The transfer protocol of the API.
- *
- * <p>
- * Values MUST be from the list: <js>"http"</js>, <js>"https"</js>, <js>"ws"</js>, <js>"wss"</js>.
- * If the <code>schemes</code> is not included, the default scheme to be used is the one used to access the Swagger
- * definition itself.
- *
- * @param schemes The values to add for the <property>schemes</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Swagger addSchemes(Collection<String> schemes) {
- if (schemes != null) {
- if (this.schemes == null)
- this.schemes = new LinkedList<>();
- this.schemes.addAll(schemes);
- }
+ public Swagger addSchemes(Collection<String> values) {
+ schemes = addToList(schemes, values);
return this;
}
/**
- * Synonym for {@link #addSchemes(String...)}.
- *
- * @param schemes The values to add for the <property>schemes</property> property on this bean.
+ * Same as {@link #addSchemes(Collection)}.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Collection<String></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<String></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * schemes(<js>"['scheme1','scheme2']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * schemes(<js>"scheme1"</js>, <js>"scheme2"</js>);
+ * </p>
+ * </ul>
* @return This object (for method chaining).
*/
- public Swagger schemes(String...schemes) {
- return addSchemes(schemes);
+ public Swagger schemes(Object...values) {
+ schemes = addToList(schemes, values, String.class);
+ return this;
}
/**
@@ -337,10 +355,8 @@ public class Swagger extends SwaggerElement {
*
* <p>
* This is global to all APIs but can be overridden on specific API calls.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">
- * Mime Types</a>.
*
- * @return The value of the <property>consumes</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<MediaType> getConsumes() {
return consumes;
@@ -354,78 +370,66 @@ public class Swagger extends SwaggerElement {
*
* <p>
* This is global to all APIs but can be overridden on specific API calls.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">
- * Mime Types</a>.
*
- * @param consumes The new value for the <property>consumes</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger setConsumes(List<MediaType> consumes) {
- this.consumes = consumes;
+ public Swagger setConsumes(Collection<MediaType> value) {
+ consumes = newList(value);
return this;
}
/**
- * Bean property adder: <property>consumes</property>.
+ * Adds one or more values to the <property>consumes</property> property.
*
* <p>
- * A list of MIME types the APIs can consume.
- *
- * <p>
- * This is global to all APIs but can be overridden on specific API calls.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">
- * Mime Types</a>.
+ * A list of MIME types the operation can consume.
+ * This overrides the <code>consumes</code> definition at the Swagger Object.
+ * An empty value MAY be used to clear the global definition.
+ * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
*
- * @param consumes The values to add for the <property>consumes</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>Values MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger addConsumes(MediaType...consumes) {
- return addConsumes(Arrays.asList(consumes));
- }
-
- /**
- * Bean property adder: <property>consumes</property>.
- *
- * <p>
- * A list of MIME types the APIs can consume.
- *
- * <p>
- * This is global to all APIs but can be overridden on specific API calls.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">
- * Mime Types</a>.
- *
- * @param consumes The values to add for the <property>consumes</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Swagger addConsumes(Collection<MediaType> consumes) {
- if (consumes != null) {
- if (this.consumes == null)
- this.consumes = new LinkedList<>();
- this.consumes.addAll(consumes);
- }
+ public Swagger addConsumes(Collection<MediaType> values) {
+ consumes = addToList(consumes, values);
return this;
}
/**
- * Synonym for {@link #addConsumes(MediaType...)}.
- *
- * @param consumes The values to add for the <property>consumes</property> property on this bean.
+ * Adds one or more values to the <property>consumes</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link MediaType}
+ * <li><code>Collection<{@link MediaType}|String></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<{@link MediaType}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * consumes(<js>"['text/json']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * consumes(<js>"text/json"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger consumes(MediaType...consumes) {
- return addConsumes(consumes);
+ public Swagger consumes(Object...values) {
+ consumes = addToList(consumes, values, MediaType.class);
+ return this;
}
-
- /**
- * Synonym for {@link #addConsumes(Collection)}.
- *
- * @param consumes The values to add for the <property>consumes</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Swagger consumes(Collection<MediaType> consumes) {
- return addConsumes(consumes);
- }
-
+
/**
* Bean property getter: <property>produces</property>.
*
@@ -434,10 +438,8 @@ public class Swagger extends SwaggerElement {
*
* <p>
* This is global to all APIs but can be overridden on specific API calls.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">
- * Mime Types</a>.
*
- * @return The value of the <property>produces</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<MediaType> getProduces() {
return produces;
@@ -451,85 +453,73 @@ public class Swagger extends SwaggerElement {
*
* <p>
* This is global to all APIs but can be overridden on specific API calls.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">
- * Mime Types</a>.
*
- * @param produces The new value for the <property>produces</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger setProduces(List<MediaType> produces) {
- this.produces = produces;
+ public Swagger setProduces(Collection<MediaType> value) {
+ produces = newList(value);
return this;
}
/**
- * Bean property adder: <property>produces</property>.
- *
- * <p>
- * A list of MIME types the APIs can produce.
- *
- * <p>
- * This is global to all APIs but can be overridden on specific API calls.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">
- * Mime Types</a>.
- *
- * @param produces The values to add for the <property>produces</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Swagger addProduces(MediaType...produces) {
- return addProduces(Arrays.asList(produces));
- }
-
- /**
- * Bean property adder: <property>produces</property>.
+ * Adds one or more values to the <property>produces</property> property.
*
* <p>
* A list of MIME types the APIs can produce.
*
* <p>
* This is global to all APIs but can be overridden on specific API calls.
- * Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">
- * Mime Types</a>.
*
- * @param produces The values to add for the <property>produces</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>Value MUST be as described under <a class="doclink" href="http://swagger.io/specification/#mimeTypes">Mime Types</a>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger addProduces(Collection<MediaType> produces) {
- if (produces != null) {
- if (this.produces == null)
- this.produces = new LinkedList<>();
- this.produces.addAll(produces);
- }
+ public Swagger addProduces(Collection<MediaType> values) {
+ produces = addToList(produces, values);
return this;
}
/**
- * Synonym for {@link #addProduces(MediaType...)}.
- *
- * @param produces The values to add for the <property>produces</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Swagger produces(MediaType...produces) {
- return addProduces(produces);
- }
-
- /**
- * Synonym for {@link #addProduces(Collection)}.
- *
- * @param produces The values to add for the <property>produces</property> property on this bean.
+ * Adds one or more values to the <property>produces</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link MediaType}
+ * <li><code>Collection<{@link MediaType}|String></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<{@link MediaType}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * consumes(<js>"['text/json']"</js>);
+ * </p>
+ * <li><code>String</code> - Individual values
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * consumes(<js>"text/json"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger produces(Collection<MediaType> produces) {
- return addProduces(produces);
+ public Swagger produces(Object...values) {
+ produces = addToList(produces, values, MediaType.class);
+ return this;
}
/**
* Bean property getter: <property>paths</property>.
*
* <p>
- * Required. The available paths and operations for the API.
+ * The available paths and operations for the API.
*
- * @return The value of the <property>paths</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,Map<String,Operation>> getPaths() {
return paths;
@@ -539,33 +529,51 @@ public class Swagger extends SwaggerElement {
* Bean property setter: <property>paths</property>.
*
* <p>
- * Required. The available paths and operations for the API.
+ * The available paths and operations for the API.
*
- * @param paths The new value for the <property>paths</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public Swagger setPaths(Map<String,Map<String,Operation>> paths) {
- this.paths = paths;
+ public Swagger setPaths(Map<String,Map<String,Operation>> value) {
+ paths = newMap(value);
return this;
}
/**
- * Bean property adder: <property>paths</property>.
+ * Adds one or more values to the <property>produces</property> property.
+ *
+ * <p>
+ * A list of MIME types the APIs can produce.
*
* <p>
- * Required. The available paths and operations for the API.
+ * This is global to all APIs but can be overridden on specific API calls.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public Swagger addPaths(Map<String,Map<String,Operation>> values) {
+ paths = addToMap(paths, values);
+ return this;
+ }
+
+ /**
+ * Adds a single value to the <property>paths</property> property.
*
* @param path The path template.
* @param methodName The HTTP method name.
* @param operation The operation that describes the path.
* @return This object (for method chaining).
*/
- public Swagger addPath(String path, String methodName, Operation operation) {
+ public Swagger path(String path, String methodName, Operation operation) {
if (paths == null)
- paths = new TreeMap<>();
+ paths = new LinkedHashMap<>();
Map<String,Operation> p = paths.get(path);
if (p == null) {
- p = new TreeMap<>(new MethodSorter());
+ p = new LinkedHashMap<>();
paths.put(path, p);
}
p.put(methodName, operation);
@@ -573,25 +581,35 @@ public class Swagger extends SwaggerElement {
}
/**
- * Synonym for {@link #path(String,String,Operation)}.
- *
- * @param path The path template.
- * @param methodName The HTTP method name.
- * @param operation The operation that describes the path.
+ * Adds one or more values to the <property>paths</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,Map<String,{@link Operation}>|String></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,Map<String,{@link Operation}>></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * paths(<js>"{'foo':{'get':{operationId:'operationId',...}}}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger path(String path, String methodName, Operation operation) {
- return addPath(path, methodName, operation);
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public Swagger paths(Object...values) {
+ paths = addToMap((Map)paths, values, String.class, Map.class, String.class, Operation.class);
+ return this;
}
-
+
/**
* Bean property getter: <property>definitions</property>.
*
* <p>
* An object to hold data types produced and consumed by operations.
*
- * @return
- * The value of the <property>definitions</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,SchemaInfo> getDefinitions() {
return definitions;
@@ -603,40 +621,64 @@ public class Swagger extends SwaggerElement {
* <p>
* An object to hold data types produced and consumed by operations.
*
- * @param definitions The new value for the <property>definitions</property> property on this bean.
+ * @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 Swagger setDefinitions(Map<String,SchemaInfo> definitions) {
- this.definitions = definitions;
+ public Swagger setDefinitions(Map<String,SchemaInfo> value) {
+ definitions = newMap(value);
return this;
}
/**
- * Bean property adder: <property>definitions</property>.
+ * Adds one or more values to the <property>definitions</property> property.
*
* <p>
* An object to hold data types produced and consumed by operations.
*
- * @param name A definition name.
- * @param schema The schema that the name defines.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger addDefinition(String name, SchemaInfo schema) {
- if (definitions == null)
- definitions = new TreeMap<>();
- definitions.put(name, schema);
+ public Swagger addDefinitions(Map<String,SchemaInfo> values) {
+ definitions = addToMap(definitions, values);
return this;
}
/**
- * Synonym for {@link #addDefinition(String,SchemaInfo)}.
+ * Adds a single value to the <property>definitions</property> property.
*
* @param name A definition name.
* @param schema The schema that the name defines.
* @return This object (for method chaining).
*/
- public Swagger xxx(String name, SchemaInfo schema) {
- return addDefinition(name, schema);
+ public Swagger definition(String name, SchemaInfo schema) {
+ definitions = addToMap(definitions, name, schema);
+ return this;
+ }
+
+ /**
+ * Adds one or more values to the <property>definitions</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,Map<String,{@link SchemaInfo}>|String></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,Map<String,{@link SchemaInfo}>></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * definitions(<js>"{'foo':{'bar':{format:'format',...}}}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public Swagger definitions(Object...values) {
+ definitions = addToMap(definitions, values, String.class, SchemaInfo.class);
+ return this;
}
/**
@@ -648,7 +690,7 @@ public class Swagger extends SwaggerElement {
* <p>
* This property does not define global parameters for all operations.
*
- * @return The value of the <property>parameters</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,ParameterInfo> getParameters() {
return parameters;
@@ -663,16 +705,18 @@ public class Swagger extends SwaggerElement {
* <p>
* This property does not define global parameters for all operations.
*
- * @param parameters The new value for the <property>parameters</property> property on this bean.
+ * @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 Swagger setParameters(Map<String,ParameterInfo> parameters) {
- this.parameters = parameters;
+ public Swagger setParameters(Map<String,ParameterInfo> value) {
+ parameters = newMap(value);
return this;
}
/**
- * Bean property adder: <property>parameters</property>.
+ * Adds one or more values to the <property>parameters</property> property.
*
* <p>
* An object to hold parameters that can be used across operations.
@@ -680,26 +724,48 @@ public class Swagger extends SwaggerElement {
* <p>
* This property does not define global parameters for all operations.
*
- * @param name The parameter name.
- * @param parameter The parameter definition.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger addParameter(String name, ParameterInfo parameter) {
- if (parameters == null)
- parameters = new TreeMap<>();
- parameters.put(name, parameter);
+ public Swagger addParameters(Map<String,ParameterInfo> values) {
+ parameters = addToMap(parameters, values);
return this;
}
/**
- * Synonym for {@link #addParameter(String,ParameterInfo)}.
+ * Adds a single value to the <property>parameter</property> property.
*
* @param name The parameter name.
* @param parameter The parameter definition.
* @return This object (for method chaining).
*/
public Swagger parameter(String name, ParameterInfo parameter) {
- return addParameter(name, parameter);
+ parameters = addToMap(parameters, name, parameter);
+ return this;
+ }
+
+ /**
+ * Adds one or more values to the <property>properties</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,{@link ParameterInfo}|String></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,{@link ParameterInfo}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * parameters(<js>"{'foo':{name:'name',...}}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public Swagger parameters(Object...values) {
+ parameters = addToMap(parameters, values, String.class, ParameterInfo.class);
+ return this;
}
/**
@@ -711,7 +777,7 @@ public class Swagger extends SwaggerElement {
* <p>
* This property does not define global responses for all operations.
*
- * @return The value of the <property>responses</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,ResponseInfo> getResponses() {
return responses;
@@ -726,16 +792,18 @@ public class Swagger extends SwaggerElement {
* <p>
* This property does not define global responses for all operations.
*
- * @param responses The new value for the <property>responses</property> property on this bean.
+ * @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 Swagger setResponses(Map<String,ResponseInfo> responses) {
- this.responses = responses;
+ public Swagger setResponses(Map<String,ResponseInfo> value) {
+ responses = newMap(value);
return this;
}
/**
- * Bean property adder: <property>responses</property>.
+ * Adds one or more values to the <property>responses</property> property.
*
* <p>
* An object to hold responses that can be used across operations.
@@ -743,26 +811,48 @@ public class Swagger extends SwaggerElement {
* <p>
* This property does not define global responses for all operations.
*
- * @param name The response name.
- * @param response The response definition.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger addResponse(String name, ResponseInfo response) {
- if (responses == null)
- responses = new TreeMap<>();
- responses.put(name, response);
+ public Swagger addResponses(Map<String,ResponseInfo> values) {
+ responses = addToMap(responses, values);
return this;
}
/**
- * Synonym for {@link #addResponse(String,ResponseInfo)}.
+ * Adds a single value to the <property>responses</property> property.
*
* @param name The response name.
* @param response The response definition.
* @return This object (for method chaining).
*/
public Swagger response(String name, ResponseInfo response) {
- return addResponse(name, response);
+ responses = addToMap(responses, name, response);
+ return this;
+ }
+
+ /**
+ * Adds one or more values to the <property>properties</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,{@link ResponseInfo}|String></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,{@link ResponseInfo}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * responses(<js>"{'foo':{description:'description',...}}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public Swagger responses(Object...values) {
+ responses = addToMap(responses, values, String.class, ResponseInfo.class);
+ return this;
}
/**
@@ -771,9 +861,7 @@ public class Swagger extends SwaggerElement {
* <p>
* Security scheme definitions that can be used across the specification.
*
- * @return
- * The value of the <property>securityDefinitions</property> property on this bean, or <jk>null</jk> if it
- * is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public Map<String,SecurityScheme> getSecurityDefinitions() {
return securityDefinitions;
@@ -785,40 +873,64 @@ public class Swagger extends SwaggerElement {
* <p>
* Security scheme definitions that can be used across the specification.
*
- * @param securityDefinitions The new value for the <property>securityDefinitions</property> property on this bean.
+ * @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 Swagger setSecurityDefinitions(Map<String,SecurityScheme> securityDefinitions) {
- this.securityDefinitions = securityDefinitions;
+ public Swagger setSecurityDefinitions(Map<String,SecurityScheme> value) {
+ securityDefinitions = newMap(value);
return this;
}
/**
- * Bean property adder: <property>securityDefinitions</property>.
+ * Adds one or more values to the <property>securityDefinitions</property> property.
*
* <p>
* Security scheme definitions that can be used across the specification.
*
- * @param name A security name.
- * @param securityScheme A security schema.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger addSecurityDefinition(String name, SecurityScheme securityScheme) {
- if (securityDefinitions == null)
- securityDefinitions = new TreeMap<>();
- securityDefinitions.put(name, securityScheme);
+ public Swagger addSecurityDefinitions(Map<String,SecurityScheme> values) {
+ securityDefinitions = addToMap(securityDefinitions, values);
return this;
}
/**
- * Synonym for {@link #addSecurityDefinition(String,SecurityScheme)}.
+ * Adds a single value to the <property>securityDefinitions</property> property.
*
* @param name A security name.
* @param securityScheme A security schema.
* @return This object (for method chaining).
*/
public Swagger securityDefinition(String name, SecurityScheme securityScheme) {
- return addSecurityDefinition(name, securityScheme);
+ securityDefinitions = addToMap(securityDefinitions, name, securityScheme);
+ return this;
+ }
+
+ /**
+ * Adds one or more values to the <property>securityDefinitions</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Map<String,{@link SecurityScheme}|String></code>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,{@link SecurityScheme}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * securityDefinitions(<js>"{'foo':{name:'name',...}}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ public Swagger securityDefinitions(Object...values) {
+ securityDefinitions = addToMap(securityDefinitions, values, String.class, SecurityScheme.class);
+ return this;
}
/**
@@ -830,9 +942,9 @@ public class Swagger extends SwaggerElement {
* <p>
* The list of values describes alternative security schemes that can be used (that is, there is a logical OR
* between the security requirements).
- * Individual operations can override this definition.
+ * <br>Individual operations can override this definition.
*
- * @return The value of the <property>security</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<Map<String,List<String>>> getSecurity() {
return security;
@@ -847,18 +959,20 @@ public class Swagger extends SwaggerElement {
* <p>
* The list of values describes alternative security schemes that can be used (that is, there is a logical OR
* between the security requirements).
- * Individual operations can override this definition.
+ * <br>Individual operations can override this definition.
*
- * @param security The new value for the <property>security</property> property on this bean.
+ * @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 Swagger setSecurity(List<Map<String,List<String>>> security) {
- this.security = security;
+ public Swagger setSecurity(Collection<Map<String,List<String>>> value) {
+ security = newList(value);
return this;
}
/**
- * Bean property adder: <property>security</property>.
+ * Adds one or more values to the <property>security</property> property.
*
* <p>
* A declaration of which security schemes are applied for the API as a whole.
@@ -866,30 +980,59 @@ public class Swagger extends SwaggerElement {
* <p>
* The list of values describes alternative security schemes that can be used (that is, there is a logical OR
* between the security requirements).
- * Individual operations can override this definition.
+ * <br>Individual operations can override this definition.
*
- * @param security The value to add for the <property>security</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger addSecurity(Map<String,List<String>> security) {
- if (this.security == null)
- this.security = new LinkedList<>();
- this.security.add(security);
+ public Swagger addSecurity(Collection<Map<String,List<String>>> values) {
+ security = addToList(security, values);
return this;
}
+
/**
- * Synonym for {@link #addSecurity(Map)}.
+ * Adds a single value to the <property>securityDefinitions</property> property.
*
* @param scheme The security scheme that applies to this operation
- * @param alternatives The list of values describes alternative security schemes that can be used (that is, there
- * is a logical OR between the security requirements).
+ * @param alternatives
+ * The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements).
* @return This object (for method chaining).
*/
public Swagger security(String scheme, String...alternatives) {
Map<String,List<String>> m = new LinkedHashMap<>();
m.put(scheme, Arrays.asList(alternatives));
- return addSecurity(m);
+ return addSecurity(Collections.singleton(m));
+ }
+
+ /**
+ * Adds one or more values to the <property>securityDefinitions</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li><code>Collection<Map<String,List<String>>></code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<Map<String,List<String>>></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * securities(<js>"[{...}]"</js>);
+ * </p>
+ * <li><code>String</code> - JSON object representation of <code>Map<String,List<String>></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * securities(<js>"{...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
+ * @return This object (for method chaining).
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public Swagger securities(Object...values) {
+ security = addToList((List)security, values, Map.class, String.class, List.class, String.class);
+ return this;
}
/**
@@ -898,14 +1041,7 @@ public class Swagger extends SwaggerElement {
* <p>
* A list of tags used by the specification with additional metadata.
*
- * <p>
- * The order of the tags can be used to reflect on their order by the parsing tools.
- * Not all tags that are used by the <a class="doclink" href="http://swagger.io/specification/#operationObject">
- * Operation Object</a> must be declared.
- * The tags that are not declared may be organized randomly or based on the tools' logic.
- * Each tag name in the list MUST be unique.
- *
- * @return The value of the <property>tags</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public List<Tag> getTags() {
return tags;
@@ -917,62 +1053,68 @@ public class Swagger extends SwaggerElement {
* <p>
* A list of tags used by the specification with additional metadata.
*
- * <p>
- * The order of the tags can be used to reflect on their order by the parsing tools.
- * Not all tags that are used by the <a class="doclink" href="http://swagger.io/specification/#operationObject">
- * Operation Object</a> must be declared.
- * The tags that are not declared may be organized randomly or based on the tools' logic.
- * Each tag name in the list MUST be unique.
- *
- * @param tags The new value for the <property>tags</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>The order of the tags can be used to reflect on their order by the parsing tools.
+ * <br>Not all tags that are used by the <a class="doclink" href="http://swagger.io/specification/#operationObject">Operation Object</a> must be declared.
+ * <br>The tags that are not declared may be organized randomly or based on the tools' logic.
+ * <br>Each tag name in the list MUST be unique.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Swagger setTags(List<Tag> tags) {
- this.tags = tags;
+ public Swagger setTags(Collection<Tag> value) {
+ tags = newList(value);
return this;
}
/**
- * Bean property adder: <property>tags</property>.
+ * Adds one or more values to the <property>security</property> property.
*
* <p>
* A list of tags used by the specification with additional metadata.
*
- * <p>
- * The order of the tags can be used to reflect on their order by the parsing tools.
- * Not all tags that are used by the <a class="doclink" href="http://swagger.io/specification/#operationObject">
- * Operation Object</a> must be declared.
- * The tags that are not declared may be organized randomly or based on the tools' logic.
- * Each tag name in the list MUST be unique.
- *
- * @param tags The values to add for the <property>tags</property> property on this bean.
+ * @param values
+ * The values to add to this property.
+ * <br>The order of the tags can be used to reflect on their order by the parsing tools.
+ * <br>Not all tags that are used by the <a class="doclink" href="http://swagger.io/specification/#operationObject">Operation Object</a> must be declared.
+ * <br>The tags that are not declared may be organized randomly or based on the tools' logic.
+ * <br>Each tag name in the list MUST be unique.
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger addTags(Tag...tags) {
- if (this.tags == null)
- this.tags = new LinkedList<>();
- this.tags.addAll(Arrays.asList(tags));
+ public Swagger addTags(Collection<Tag> values) {
+ tags = addToList(tags, values);
return this;
}
- /**
- * Synonym for {@link #addTags(Tag...)}.
- *
- * @param tags The values to add for the <property>tags</property> property on this bean.
- * @return This object (for method chaining).
- */
- public Swagger tags(Tag...tags) {
- return addTags(tags);
- }
/**
- * Synonym for {@link #setTags(List)}.
- *
- * @param tags The values to add for the <property>tags</property> property on this bean.
+ * Adds one or more values to the <property>tags</property> property.
+ *
+ * @param values
+ * The values to add to this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link Tag}
+ * <li><code>Collection<{@link Tag}|String></code>
+ * <li><code>{@link Tag}[]</code>
+ * <li><code>String</code> - JSON array representation of <code>Collection<{@link Tag}></code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * tags(<js>"[{name:'name',description:'description',...}]"</js>);
+ * </p>
+ * <li><code>String</code> - JSON object representation of <code>{@link Tag}</code>
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * tags(<js>"{name:'name',description:'description',...}"</js>);
+ * </p>
+ * </ul>
+ * <br>Ignored if <jk>null</jk>.
* @return This object (for method chaining).
*/
- public Swagger tags(List<Tag> tags) {
- return setTags(tags);
+ public Swagger tags(Object...values) {
+ tags = addToList(tags, values, Tag.class);
+ return this;
}
/**
@@ -981,9 +1123,7 @@ public class Swagger extends SwaggerElement {
* <p>
* Additional external documentation.
*
- * @return
- * The value of the <property>externalDocs</property> property on this bean, or <jk>null</jk> if it is
- * not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public ExternalDocumentation getExternalDocs() {
return externalDocs;
@@ -995,46 +1135,109 @@ public class Swagger extends SwaggerElement {
* <p>
* Additional external documentation.
*
- * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @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 Swagger setExternalDocs(ExternalDocumentation externalDocs) {
- this.externalDocs = externalDocs;
+ public Swagger setExternalDocs(ExternalDocumentation value) {
+ externalDocs = value;
return this;
}
/**
- * Synonym for {@link #setExternalDocs(ExternalDocumentation)}.
- *
- * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * Same as {@link #setExternalDocs(ExternalDocumentation)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link ExternalDocumentation}
+ * <li><code>String</code> - JSON object representation of {@link ExternalDocumentation}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * 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 Swagger externalDocs(ExternalDocumentation externalDocs) {
- return setExternalDocs(externalDocs);
- }
-
- static final class MethodSorter implements Comparator<String> {
- private final Map<String,Integer> methods = new AMap<String,Integer>()
- .append("get",7)
- .append("put",6)
- .append("post",5)
- .append("delete",4)
- .append("options",3)
- .append("head",2)
- .append("patch",1);
-
- @Override
- public int compare(String o1, String o2) {
- Integer i1 = methods.get(o1);
- Integer i2 = methods.get(o2);
- if (i1 == null)
- i1 = 0;
- if (i2 == null)
- i2 = 0;
- return i2.compareTo(i1);
+ public Swagger 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 "swagger": return toType(getSwagger(), type);
+ case "info": return toType(getInfo(), type);
+ case "host": return toType(getHost(), type);
+ case "basePath": return toType(getBasePath(), type);
+ case "schemes": return toType(getSchemes(), type);
+ case "consumes": return toType(getConsumes(), type);
+ case "produces": return toType(getProduces(), type);
+ case "paths": return toType(getPaths(), type);
+ case "definitions": return toType(getDefinitions(), type);
+ case "parameters": return toType(getParameters(), type);
+ case "responses": return toType(getResponses(), type);
+ case "securityDefinitions": return toType(getSecurityDefinitions(), type);
+ case "security": return toType(getSecurity(), type);
+ case "tags": return toType(getTags(), type);
+ case "externalDocs": return toType(getExternalDocs(), type);
+ default: return super.get(property, type);
}
}
+ @Override /* SwaggerElement */
+ public Swagger set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "swagger": return swagger(value);
+ case "info": return info(value);
+ case "host": return host(value);
+ case "basePath": return basePath(value);
+ case "schemes": return setSchemes(null).schemes(value);
+ case "consumes": return setConsumes(null).consumes(value);
+ case "produces": return setProduces(null).produces(value);
+ case "paths": return setPaths(null).paths(value);
+ case "definitions": return setDefinitions(null).definitions(value);
+ case "parameters": return setParameters(null).parameters(value);
+ case "responses": return setResponses(null).responses(value);
+ case "securityDefinitions": return setSecurityDefinitions(null).securityDefinitions(value);
+ case "security": return setSecurity(null).securities(value);
+ case "tags": return setTags(null).tags(value);
+ case "externalDocs": return externalDocs(value);
+ default:
+ super.set(property, value);
+ return this;
+ }
+ }
+
+// static final class MethodSorter implements Comparator<String> {
+// private final Map<String,Integer> methods = new AMap<String,Integer>()
+// .append("get",7)
+// .append("put",6)
+// .append("post",5)
+// .append("delete",4)
+// .append("options",3)
+// .append("head",2)
+// .append("patch",1);
+//
+// @Override
+// public int compare(String o1, String o2) {
+// Integer i1 = methods.get(o1);
+// Integer i2 = methods.get(o2);
+// if (i1 == null)
+// i1 = 0;
+// if (i2 == null)
+// i2 = 0;
+// return i2.compareTo(i1);
+// }
+// }
+
@Override /* Object */
public String toString() {
return JsonSerializer.DEFAULT.toString(this);
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerBuilder.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerBuilder.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerBuilder.java
index 2791c09..36c4fdb 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerBuilder.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerBuilder.java
@@ -21,17 +21,7 @@ import org.apache.juneau.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
public class SwaggerBuilder {
@@ -46,9 +36,9 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link Contact} element with the specified {@link Contact#name(String)} attribute.
+ * Creates an {@link Contact} element with the specified {@link Contact#setName(String) name} attribute.
*
- * @param name The {@link Contact#name(String)} attribute.
+ * @param name The {@link Contact#setName(String) name} attribute.
* @return The new element.
*/
public static final Contact contact(String name) {
@@ -56,16 +46,16 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link Contact} element with the specified {@link Contact#name(String)}, {@link Contact#url(Object)},
- * and {@link Contact#email(String)}, attributes.
+ * Creates an {@link Contact} element with the specified {@link Contact#setName(String) name}, {@link Contact#setUrl(URI) url},
+ * and {@link Contact#setEmail(String) email} attributes.
*
- * @param name The {@link Contact#name(String)} attribute.
+ * @param name The {@link Contact#setName(String) name} attribute.
* @param url
- * The {@link Contact#url(Object)} attribute.
- * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
+ * The {@link Contact#setUrl(URI) url} attribute.
+ * <br>The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
* <br>Strings must be valid URIs.
* <br>URIs defined by {@link UriResolver} can be used for values.
- * @param email The {@link Contact#email(String)} attribute.
+ * @param email The {@link Contact#setEmail(String) email} attribute.
* @return The new element.
*/
public static final Contact contact(String name, Object url, String email) {
@@ -82,12 +72,12 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link ExternalDocumentation} element with the specified {@link ExternalDocumentation#url(Object)}
+ * Creates an {@link ExternalDocumentation} element with the specified {@link ExternalDocumentation#setUrl(URI) url}
* attribute.
*
* @param url
- * The {@link ExternalDocumentation#url(Object)} attribute.
- * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
+ * The {@link ExternalDocumentation#setUrl(URI) url} attribute.
+ * <br>The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
* <br>Strings must be valid URIs.
* <br>URIs defined by {@link UriResolver} can be used for values.
* @return The new element.
@@ -97,15 +87,15 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link ExternalDocumentation} element with the specified {@link ExternalDocumentation#url(Object)}
- * and {@link ExternalDocumentation#description(String)} attributes.
+ * Creates an {@link ExternalDocumentation} element with the specified {@link ExternalDocumentation#setUrl(URI) url}
+ * and {@link ExternalDocumentation#setDescription(String) description} attributes.
*
* @param url
- * The {@link ExternalDocumentation#url(Object)} attribute.
- * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
+ * The {@link ExternalDocumentation#setUrl(URI) url} attribute.
+ * <br>The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
* <br>Strings must be valid URIs.
* <br>URIs defined by {@link UriResolver} can be used for values.
- * @param description The {@link ExternalDocumentation#description(String)} attribute.
+ * @param description The {@link ExternalDocumentation#setDescription(String) description} attribute.
* @return The new element.
*/
public static final ExternalDocumentation externalDocumentation(Object url, String description) {
@@ -122,9 +112,9 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link HeaderInfo} element with the specified {@link HeaderInfo#type(String)} attribute.
+ * Creates an {@link HeaderInfo} element with the specified {@link HeaderInfo#setType(String) type} attribute.
*
- * @param type The {@link HeaderInfo#type(String)} attribute.
+ * @param type The {@link HeaderInfo#setType(String) type} attribute.
* @return The new element.
*/
public static final HeaderInfo headerInfo(String type) {
@@ -132,9 +122,21 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link HeaderInfo} element with the specified {@link HeaderInfo#type(String)} attribute.
+ * Creates an {@link HeaderInfo} element with the specified {@link HeaderInfo#setType(String) type} attribute.
*
- * @param type The {@link HeaderInfo#type(String)} attribute.
+ * <p>
+ * Throws a runtime exception if the type is not valid.
+ *
+ * @param type
+ * The {@link HeaderInfo#setType(String) type} attribute.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"string"</js>
+ * <li><js>"number"</js>
+ * <li><js>"integer"</js>
+ * <li><js>"boolean"</js>
+ * <li><js>"array"</js>
+ * </ul>
* @return The new element.
*/
public static final HeaderInfo headerInfoStrict(String type) {
@@ -151,11 +153,11 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link Info} element with the specified {@link Info#title(String)} and {@link Info#version(String)}
+ * Creates an {@link Info} element with the specified {@link Info#setTitle(String) title} and {@link Info#setVersion(String) version}
* attributes.
*
- * @param title The {@link Info#title(String)} attribute.
- * @param version The {@link Info#version(String)} attribute.
+ * @param title The {@link Info#setTitle(String) title} attribute.
+ * @param version The {@link Info#setVersion(String) version} attribute.
* @return The new element.
*/
public static final Info info(String title, String version) {
@@ -172,9 +174,9 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link Items} element with the specified {@link Items#type(String)} attribute.
+ * Creates an {@link Items} element with the specified {@link Items#setType(String) type} attribute.
*
- * @param type The {@link Items#type(String)} attribute.
+ * @param type The {@link Items#setType(String) type} attribute.
* @return The new element.
*/
public static final Items items(String type) {
@@ -182,9 +184,21 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link Items} element with the specified {@link Items#type(String)} attribute.
+ * Creates an {@link Items} element with the specified {@link Items#setType(String) type} attribute.
+ *
+ * <p>
+ * Throws a runtime exception if the type is not valid.
*
- * @param type The {@link Items#type(String)} attribute.
+ * @param type
+ * The {@link Items#setType(String) type} attribute.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"string"</js>
+ * <li><js>"number"</js>
+ * <li><js>"integer"</js>
+ * <li><js>"boolean"</js>
+ * <li><js>"array"</js>
+ * </ul>
* @return The new element.
*/
public static final Items itemsStrict(String type) {
@@ -201,9 +215,9 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link License} element with the specified {@link License#name(String)} attribute.
+ * Creates an {@link License} element with the specified {@link License#setName(String) name} attribute.
*
- * @param name The {@link License#name(String)} attribute.
+ * @param name The {@link License#setName(String) name} attribute.
* @return The new element.
*/
public static final License license(String name) {
@@ -211,6 +225,17 @@ public class SwaggerBuilder {
}
/**
+ * Creates an {@link License} element with the specified {@link License#setName(String) name} and {@link License#setUrl(URI) url} attributes.
+ *
+ * @param name The {@link License#setName(String) name} attribute.
+ * @param url The {@link License#setUrl(URI) url} attribute.
+ * @return The new element.
+ */
+ public static final License license(String name, URI url) {
+ return license().name(name).url(url);
+ }
+
+ /**
* Creates an empty {@link Operation} element.
*
* @return The new element.
@@ -229,11 +254,11 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link ParameterInfo} element with the specified {@link ParameterInfo#in(String)} and
- * {@link ParameterInfo#name(String)} attributes.
+ * Creates an {@link ParameterInfo} element with the specified {@link ParameterInfo#setIn(String) in} and
+ * {@link ParameterInfo#setName(String) name} attributes.
*
- * @param in The {@link ParameterInfo#in(String)} attribute.
- * @param name The {@link ParameterInfo#name(String)} attribute.
+ * @param in The {@link ParameterInfo#setIn(String) in} attribute.
+ * @param name The {@link ParameterInfo#setName(String) name} attribute.
* @return The new element.
*/
public static final ParameterInfo parameterInfo(String in, String name) {
@@ -241,11 +266,23 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link ParameterInfo} element with the specified {@link ParameterInfo#in(String)} and
- * {@link ParameterInfo#name(String)} attributes.
+ * Creates an {@link ParameterInfo} element with the specified {@link ParameterInfo#setIn(String) in} and
+ * {@link ParameterInfo#setName(String) name} attributes.
*
- * @param in The {@link ParameterInfo#in(String)} attribute.
- * @param name The {@link ParameterInfo#name(String)} attribute.
+ * <p>
+ * Throws a runtime exception if the type is not valid.
+ *
+ * @param in
+ * The {@link ParameterInfo#setIn(String) in} attribute.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"query"</js>
+ * <li><js>"header"</js>
+ * <li><js>"path"</js>
+ * <li><js>"formData"</js>
+ * <li><js>"body"</js>
+ * </ul>
+ * @param name The {@link ParameterInfo#setName(String) name} attribute.
* @return The new element.
*/
public static final ParameterInfo parameterInfoStrict(String in, String name) {
@@ -262,9 +299,9 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link ResponseInfo} element with the specified {@link ResponseInfo#description(String)} attribute.
+ * Creates an {@link ResponseInfo} element with the specified {@link ResponseInfo#setDescription(String) description} attribute.
*
- * @param description The {@link ResponseInfo#description(String)} attribute.
+ * @param description The {@link ResponseInfo#setDescription(String) description} attribute.
* @return The new element.
*/
public static final ResponseInfo responseInfo(String description) {
@@ -290,9 +327,9 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link SecurityScheme} element with the specified {@link SecurityScheme#type(String)} attribute.
+ * Creates an {@link SecurityScheme} element with the specified {@link SecurityScheme#setType(String) type} attribute.
*
- * @param type The {@link SecurityScheme#type(String)} attribute.
+ * @param type The {@link SecurityScheme#setType(String) type} attribute.
* @return The new element.
*/
public static final SecurityScheme securityScheme(String type) {
@@ -300,9 +337,19 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link SecurityScheme} element with the specified {@link SecurityScheme#type(String)} attribute.
+ * Creates an {@link SecurityScheme} element with the specified {@link SecurityScheme#setType(String) type} attribute.
+ *
+ * <p>
+ * Throws a runtime exception if the type is not valid.
*
- * @param type The {@link SecurityScheme#type(String)} attribute.
+ * @param type
+ * The {@link SecurityScheme#setType(String) type} attribute.
+ * <br>Valid values:
+ * <ul>
+ * <li><js>"basic"</js>
+ * <li><js>"apiKey"</js>
+ * <li><js>"oauth2"</js>
+ * </ul>
* @return The new element.
*/
public static final SecurityScheme securitySchemeStrict(String type) {
@@ -319,9 +366,9 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link Swagger} element with the specified {@link Swagger#info(Info)} attribute.
+ * Creates an {@link Swagger} element with the specified {@link Swagger#setInfo(Info) info} attribute.
*
- * @param info The {@link Swagger#info(Info)} attribute.
+ * @param info The {@link Swagger#setInfo(Info) info} attribute.
* @return The new element.
*/
public static final Swagger swagger(Info info) {
@@ -338,9 +385,9 @@ public class SwaggerBuilder {
}
/**
- * Creates an {@link Tag} element with the specified {@link Tag#name(String)} attribute.
+ * Creates an {@link Tag} element with the specified {@link Tag#setName(String) name} attribute.
*
- * @param name The {@link Tag#name(String)} attribute.
+ * @param name The {@link Tag#setName(String) name} attribute.
* @return The new element.
*/
public static final Tag tag(String name) {
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
index 9738a38..52031a7 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
@@ -12,27 +12,25 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
+
+import java.util.*;
+
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.json.*;
+
/**
* Root class for all Swagger beans.
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-public class SwaggerElement {
+public abstract class SwaggerElement {
private boolean strict;
+ private Map<String,Object> extra;
/**
* Returns <jk>true</jk> if contents should be validated per the Swagger spec.
@@ -49,7 +47,88 @@ public class SwaggerElement {
* @return This object (for method chaining).
*/
protected SwaggerElement strict() {
- this.strict = true;
+ strict = true;
+ return this;
+ }
+
+ /**
+ * Sets strict mode on this bean.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Non-boolean values will be converted to boolean using <code>Boolean.<jsm>valueOf</jsm>(value.toString())</code>.
+ * <br>Can be <jk>null</jk> (interpreted as <jk>false</jk>).
+ * @return This object (for method chaining).
+ */
+ protected SwaggerElement strict(Object value) {
+ strict = value == null ? false : toBoolean(value);
return this;
}
+
+ /**
+ * The map used to store 'extra' properties on the swagger element.
+ *
+ * <p>
+ * For example, the <js>"$ref"</js> field is not a part of the Swagger doc, but is often
+ * found since it is a part of the JSON-Schema spec.
+ * <br>This map allows you to store such properties.
+ *
+ * <p>
+ * This map is lazy-created once this method is called.
+ *
+ * @return
+ * The extra properties map.
+ * <br>It's an instance of {@link LinkedHashMap}.
+ */
+ @BeanProperty("*")
+ public Map<String,Object> getExtraProperties() {
+ if (extra == null)
+ extra = new LinkedHashMap<>();
+ return extra;
+ }
+
+ /**
+ * Generic property getter.
+ *
+ * <p>
+ * Can be used to retrieve non-standard Swagger fields such as <js>"$ref"</js>.
+ *
+ * @param property The property name to retrieve.
+ * @param type The datatype to cast the value to.
+ * @return The property value, or <jk>null</jk> if the property does not exist or is not set.
+ */
+ public <T> T get(String property, Class<T> type) {
+ if (property == null)
+ return null;
+ switch (property) {
+ case "strict": return toType(isStrict(), type);
+ default: return toType(getExtraProperties().get(property), type);
+ }
+ };
+
+ /**
+ * Generic property setter.
+ *
+ * <p>
+ * Can be used to set non-standard Swagger fields such as <js>"$ref"</js>.
+ *
+ * @param property The property name to set.
+ * @param value The new value for the property.
+ * @return This object (for method chaining).
+ */
+ public SwaggerElement set(String property, Object value) {
+ if (property == null)
+ return this;
+ switch (property) {
+ case "strict": return strict(value);
+ default:
+ getExtraProperties().put(property, value);
+ return this;
+ }
+ }
+
+ @Override /* Object */
+ public String toString() {
+ return JsonSerializer.DEFAULT.toString(this);
+ }
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Tag.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Tag.java b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Tag.java
index e1dc5c5..e0d072d 100644
--- a/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Tag.java
+++ b/juneau-core/juneau-dto/src/main/java/org/apache/juneau/dto/swagger/Tag.java
@@ -12,6 +12,7 @@
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
+import static org.apache.juneau.internal.BeanPropertyUtils.*;
import org.apache.juneau.annotation.*;
/**
@@ -22,6 +23,19 @@ import org.apache.juneau.annotation.*;
*
* <h5 class='section'>Example:</h5>
* <p class='bcode'>
+ * <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'>
+ * <jc>// Output</jc>
* {
* <js>"name"</js>: <js>"pet"</js>,
* <js>"description"</js>: <js>"Pets operations"</js>
@@ -30,33 +44,24 @@ import org.apache.juneau.annotation.*;
*
* <h6 class='topic'>Additional Information</h6>
* <ul class='doctree'>
- * <li class='link'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs'>Juneau Data Transfer Objects
- * (org.apache.juneau.dto)</a>
- * <ul>
- * <li class='sublink'>
- * <a class='doclink' href='../../../../../overview-summary.html#DTOs.Swagger'>Swagger</a>
- * </ul>
- * </li>
- * <li class='jp'>
- * <a class='doclink' href='package-summary.html#TOC'>org.apache.juneau.dto.swagger</a>
- * </li>
+ * <li class='link'><a class='doclink' href='../../../../../overview-summary.html#juneau-dto.Swagger'>Overview > juneau-dto > Swagger</a>
* </ul>
*/
-@Bean(properties="name,description,externalDocs")
+@Bean(properties="name,description,externalDocs,*")
public class Tag extends SwaggerElement {
- private String name;
- private String description;
+ private String
+ name,
+ description;
private ExternalDocumentation externalDocs;
/**
* Bean property getter: <property>name</property>.
*
* <p>
- * Required. The name of the tag.
+ * The name of the tag.
*
- * @return The value of the <property>name</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getName() {
return name;
@@ -66,24 +71,29 @@ public class Tag extends SwaggerElement {
* Bean property setter: <property>name</property>.
*
* <p>
- * Required. The name of the tag.
+ * The name of the tag.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Property value is required.
* @return This object (for method chaining).
*/
- public Tag setName(String name) {
- this.name = name;
+ public Tag setName(String value) {
+ name = value;
return this;
}
/**
- * Synonym for {@link #setName(String)}.
+ * Same as {@link #setName(String)}.
*
- * @param name The new value for the <property>name</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Tag name(String name) {
- return setName(name);
+ public Tag name(Object value) {
+ return setName(toStringVal(value));
}
/**
@@ -92,12 +102,7 @@ public class Tag extends SwaggerElement {
* <p>
* A short description for the tag.
*
- * <p>
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used
- * for rich text representation.
- *
- * @return
- * The value of the <property>description</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public String getDescription() {
return description;
@@ -109,26 +114,28 @@ public class Tag extends SwaggerElement {
* <p>
* A short description for the tag.
*
- * <p>
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used
- * for rich text representation.
- *
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br><a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> 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 description) {
- this.description = description;
+ public Tag setDescription(String value) {
+ description = value;
return this;
}
/**
- * Synonym for {@link #setDescription(String)}.
+ * Same as {@link #setDescription(String)}.
*
- * @param description The new value for the <property>description</property> property on this bean.
+ * @param value
+ * The new value for this property.
+ * <br>Non-String values will be converted to String using <code>toString()</code>.
+ * <br>Can be <jk>null</jk> to unset the property.
* @return This object (for method chaining).
*/
- public Tag description(String description) {
- return setDescription(description);
+ public Tag description(Object value) {
+ return setDescription(toStringVal(value));
}
/**
@@ -137,8 +144,7 @@ public class Tag extends SwaggerElement {
* <p>
* Additional external documentation for this tag.
*
- * @return
- * The value of the <property>externalDocs</property> property on this bean, or <jk>null</jk> if it is not set.
+ * @return The property value, or <jk>null</jk> if it is not set.
*/
public ExternalDocumentation getExternalDocs() {
return externalDocs;
@@ -150,21 +156,60 @@ public class Tag extends SwaggerElement {
* <p>
* Additional external documentation for this tag.
*
- * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @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 externalDocs) {
- this.externalDocs = externalDocs;
+ public Tag setExternalDocs(ExternalDocumentation value) {
+ externalDocs = value;
return this;
}
/**
- * Synonym for {@link #setExternalDocs(ExternalDocumentation)}.
- *
- * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * Same as {@link #setExternalDocs(ExternalDocumentation)}.
+ *
+ * @param value
+ * The new value for this property.
+ * <br>Valid types:
+ * <ul>
+ * <li>{@link ExternalDocumentation}
+ * <li><code>String</code> - JSON object representation of {@link ExternalDocumentation}
+ * <h6 class='figure'>Example:</h6>
+ * <p class='bcode'>
+ * 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(ExternalDocumentation externalDocs) {
- return setExternalDocs(externalDocs);
+ 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;
+ }
}
}
[09/10] juneau git commit: JUNEAU-78
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ParameterInfoTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ParameterInfoTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ParameterInfoTest.java
new file mode 100644
index 0000000..6aa8ce1
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ParameterInfoTest.java
@@ -0,0 +1,729 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.*;
+
+import org.apache.juneau.json.*;
+import org.apache.juneau.utils.*;
+
+import org.junit.*;
+
+/**
+ * Testcase for {@link ParameterInfo}.
+ */
+public class ParameterInfoTest {
+
+ /**
+ * Test method for {@link ParameterInfo#name(java.lang.Object)}.
+ */
+ @Test
+ public void testName() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.name("foo");
+ assertEquals("foo", t.getName());
+
+ t.name(new StringBuilder("foo"));
+ assertEquals("foo", t.getName());
+ assertType(String.class, t.getName());
+
+ t.name(null);
+ assertNull(t.getName());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#in(java.lang.Object)}.
+ */
+ @Test
+ public void testIn() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.in("foo");
+ assertEquals("foo", t.getIn());
+
+ t.in(new StringBuilder("foo"));
+ assertEquals("foo", t.getIn());
+ assertType(String.class, t.getIn());
+
+ t.in(null);
+ assertNull(t.getIn());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#description(java.lang.Object)}.
+ */
+ @Test
+ public void testDescription() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.description("foo");
+ assertEquals("foo", t.getDescription());
+
+ t.description(new StringBuilder("foo"));
+ assertEquals("foo", t.getDescription());
+ assertType(String.class, t.getDescription());
+
+ t.description(null);
+ assertNull(t.getDescription());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#required(java.lang.Object)}.
+ */
+ @Test
+ public void testRequired() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.required(true);
+ assertEquals(true, t.getRequired());
+ assertType(Boolean.class, t.getRequired());
+
+ t.required("true");
+ assertEquals(true, t.getRequired());
+ assertType(Boolean.class, t.getRequired());
+
+ t.required(new StringBuilder("true"));
+ assertEquals(true, t.getRequired());
+ assertType(Boolean.class, t.getRequired());
+
+ t.required(null);
+ assertNull(t.getRequired());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#schema(java.lang.Object)}.
+ */
+ @Test
+ public void testSchema() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.schema(schemaInfo().title("foo"));
+ assertObjectEquals("{title:'foo'}", t.getSchema());
+
+ t.schema("{title:'foo'}");
+ assertObjectEquals("{title:'foo'}", t.getSchema());
+ assertType(SchemaInfo.class, t.getSchema());
+
+ t.schema(null);
+ assertNull(t.getSchema());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#type(java.lang.Object)}.
+ */
+ @Test
+ public void testType() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.type("foo");
+ assertEquals("foo", t.getType());
+
+ t.type(new StringBuilder("foo"));
+ assertEquals("foo", t.getType());
+ assertType(String.class, t.getType());
+
+ t.type(null);
+ assertNull(t.getType());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#format(java.lang.Object)}.
+ */
+ @Test
+ public void testFormat() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.format("foo");
+ assertEquals("foo", t.getFormat());
+
+ t.format(new StringBuilder("foo"));
+ assertEquals("foo", t.getFormat());
+ assertType(String.class, t.getFormat());
+
+ t.format(null);
+ assertNull(t.getFormat());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#allowEmptyValue(java.lang.Object)}.
+ */
+ @Test
+ public void testAllowEmptyValue() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.allowEmptyValue(true);
+ assertEquals(true, t.getAllowEmptyValue());
+ assertType(Boolean.class, t.getAllowEmptyValue());
+
+ t.allowEmptyValue("true");
+ assertEquals(true, t.getAllowEmptyValue());
+ assertType(Boolean.class, t.getAllowEmptyValue());
+
+ t.allowEmptyValue(new StringBuilder("true"));
+ assertEquals(true, t.getAllowEmptyValue());
+ assertType(Boolean.class, t.getAllowEmptyValue());
+
+ t.allowEmptyValue(null);
+ assertNull(t.getAllowEmptyValue());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#items(java.lang.Object)}.
+ */
+ @Test
+ public void testItems() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.items(items("foo"));
+ assertObjectEquals("{type:'foo'}", t.getItems());
+
+ t.items("{type:'foo'}");
+ assertObjectEquals("{type:'foo'}", t.getItems());
+ assertType(Items.class, t.getItems());
+
+ t.items(null);
+ assertNull(t.getItems());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#collectionFormat(java.lang.Object)}.
+ */
+ @Test
+ public void testCollectionFormat() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.collectionFormat("foo");
+ assertEquals("foo", t.getCollectionFormat());
+
+ t.collectionFormat(new StringBuilder("foo"));
+ assertEquals("foo", t.getCollectionFormat());
+ assertType(String.class, t.getCollectionFormat());
+
+ t.collectionFormat(null);
+ assertNull(t.getCollectionFormat());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#_default(java.lang.Object)}.
+ */
+ @Test
+ public void test_default() {
+ ParameterInfo t = new ParameterInfo();
+
+ t._default("foo");
+ assertEquals("foo", t.getDefault());
+
+ t._default(new StringBuilder("foo"));
+ assertEquals("foo", t.getDefault().toString());
+ assertType(StringBuilder.class, t.getDefault());
+
+ t._default(null);
+ assertNull(t.getDefault());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#maximum(java.lang.Object)}.
+ */
+ @Test
+ public void testMaximum() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.maximum(123);
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(123f);
+ assertEquals(123f, t.getMaximum());
+ assertType(Float.class, t.getMaximum());
+
+ t.maximum("123");
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(new StringBuilder("123"));
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(null);
+ assertNull(t.getMaximum());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#exclusiveMaximum(java.lang.Object)}.
+ */
+ @Test
+ public void testExclusiveMaximum() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.exclusiveMaximum(true);
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum("true");
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum(new StringBuilder("true"));
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum(null);
+ assertNull(t.getExclusiveMaximum());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#minimum(java.lang.Object)}.
+ */
+ @Test
+ public void testMinimum() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.minimum(123);
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(123f);
+ assertEquals(123f, t.getMinimum());
+ assertType(Float.class, t.getMinimum());
+
+ t.minimum("123");
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(new StringBuilder("123"));
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(null);
+ assertNull(t.getMinimum());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#exclusiveMinimum(java.lang.Object)}.
+ */
+ @Test
+ public void testExclusiveMinimum() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.exclusiveMinimum(true);
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum("true");
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum(new StringBuilder("true"));
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum(null);
+ assertNull(t.getExclusiveMinimum());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#maxLength(java.lang.Object)}.
+ */
+ @Test
+ public void testMaxLength() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.maxLength(123);
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(123f);
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength("123");
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(new StringBuilder("123"));
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(null);
+ assertNull(t.getMaxLength());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#minLength(java.lang.Object)}.
+ */
+ @Test
+ public void testMinLength() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.minLength(123);
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(123f);
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength("123");
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(new StringBuilder("123"));
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(null);
+ assertNull(t.getMinLength());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#pattern(java.lang.Object)}.
+ */
+ @Test
+ public void testPattern() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.pattern("foo");
+ assertEquals("foo", t.getPattern());
+
+ t.pattern(new StringBuilder("foo"));
+ assertEquals("foo", t.getPattern());
+ assertType(String.class, t.getPattern());
+
+ t.pattern(null);
+ assertNull(t.getPattern());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#maxItems(java.lang.Object)}.
+ */
+ @Test
+ public void testMaxItems() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.maxItems(123);
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(123f);
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems("123");
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(new StringBuilder("123"));
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(null);
+ assertNull(t.getMaxItems());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#minItems(java.lang.Object)}.
+ */
+ @Test
+ public void testMinItems() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.minItems(123);
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(123f);
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems("123");
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(new StringBuilder("123"));
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(null);
+ assertNull(t.getMinItems());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#uniqueItems(java.lang.Object)}.
+ */
+ @Test
+ public void testUniqueItems() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.uniqueItems(true);
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems("true");
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems(new StringBuilder("true"));
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems(null);
+ assertNull(t.getUniqueItems());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#setEnum(java.util.Collection)}.
+ */
+ @Test
+ public void testSetEnum() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.setEnum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(new ASet<Object>());
+ assertObjectEquals("[]", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(null);
+ assertNull(t.getEnum());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#addEnum(java.util.Collection)}.
+ */
+ @Test
+ public void testAddEnum() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.addEnum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.addEnum(new ASet<Object>().appendAll("baz"));
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.addEnum(null);
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#_enum(java.lang.Object[])}.
+ */
+ @Test
+ public void test_enum() {
+ ParameterInfo t = new ParameterInfo();
+
+ t._enum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t._enum(new ASet<Object>().appendAll("baz"));
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t._enum((Object[])null);
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(null);
+ t._enum("foo")._enum(new StringBuilder("bar"))._enum("['baz','qux']")._enum((Object)new String[]{"quux"});
+ assertObjectEquals("['foo','bar','baz','qux','quux']", t.getEnum());
+ assertType(List.class, t.getEnum());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#multipleOf(java.lang.Object)}.
+ */
+ @Test
+ public void testMultipleOf() {
+ ParameterInfo t = new ParameterInfo();
+
+ t.multipleOf(123);
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(123f);
+ assertEquals(123f, t.getMultipleOf());
+ assertType(Float.class, t.getMultipleOf());
+
+ t.multipleOf("123");
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(new StringBuilder("123"));
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(null);
+ assertNull(t.getMultipleOf());
+ }
+
+ /**
+ * Test method for {@link ParameterInfo#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ ParameterInfo t = new ParameterInfo();
+
+ t
+ .set("default", "a")
+ .set("enum", new ASet<Object>().appendAll("b"))
+ .set("allowEmptyValue", true)
+ .set("collectionFormat", "c")
+ .set("description", "d")
+ .set("exclusiveMaximum", true)
+ .set("exclusiveMinimum", true)
+ .set("format", "e")
+ .set("in", "f")
+ .set("items", items("g"))
+ .set("maximum", 123f)
+ .set("maxItems", 123)
+ .set("maxLength", 123)
+ .set("minimum", 123f)
+ .set("minItems", 123)
+ .set("minLength", 123)
+ .set("multipleOf", 123f)
+ .set("name", "h")
+ .set("pattern", "i")
+ .set("required", true)
+ .set("schema", schemaInfo().title("j"))
+ .set("type", "k")
+ .set("uniqueItems", true)
+ .set("$ref", "ref");
+
+ assertObjectEquals("{'in':'f',name:'h',type:'k',description:'d',required:true,schema:{title:'j'},format:'e',allowEmptyValue:true,items:{type:'g'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}", t);
+
+ t
+ .set("default", "a")
+ .set("enum", "['b']")
+ .set("allowEmptyValue", "true")
+ .set("collectionFormat", "c")
+ .set("description", "d")
+ .set("exclusiveMaximum", "true")
+ .set("exclusiveMinimum", "true")
+ .set("format", "e")
+ .set("in", "f")
+ .set("items", "{type:'g'}")
+ .set("maximum", "123.0")
+ .set("maxItems", "123")
+ .set("maxLength", "123")
+ .set("minimum", "123.0")
+ .set("minItems", "123")
+ .set("minLength", "123")
+ .set("multipleOf", "123.0")
+ .set("name", "h")
+ .set("pattern", "i")
+ .set("required", "true")
+ .set("schema", "{title:'j'}")
+ .set("type", "k")
+ .set("uniqueItems", "true")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{'in':'f',name:'h',type:'k',description:'d',required:true,schema:{title:'j'},format:'e',allowEmptyValue:true,items:{type:'g'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}", t);
+
+ t
+ .set("default", new StringBuilder("a"))
+ .set("enum", new StringBuilder("['b']"))
+ .set("allowEmptyValue", new StringBuilder("true"))
+ .set("collectionFormat", new StringBuilder("c"))
+ .set("description", new StringBuilder("d"))
+ .set("exclusiveMaximum", new StringBuilder("true"))
+ .set("exclusiveMinimum", new StringBuilder("true"))
+ .set("format", new StringBuilder("e"))
+ .set("in", new StringBuilder("f"))
+ .set("items", new StringBuilder("{type:'g'}"))
+ .set("maximum", new StringBuilder("123.0"))
+ .set("maxItems", new StringBuilder("123"))
+ .set("maxLength", new StringBuilder("123"))
+ .set("minimum", new StringBuilder("123.0"))
+ .set("minItems", new StringBuilder("123"))
+ .set("minLength", new StringBuilder("123"))
+ .set("multipleOf", new StringBuilder("123.0"))
+ .set("name", new StringBuilder("h"))
+ .set("pattern", new StringBuilder("i"))
+ .set("required", new StringBuilder("true"))
+ .set("schema", new StringBuilder("{title:'j'}"))
+ .set("type", new StringBuilder("k"))
+ .set("uniqueItems", new StringBuilder("true"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{'in':'f',name:'h',type:'k',description:'d',required:true,schema:{title:'j'},format:'e',allowEmptyValue:true,items:{type:'g'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}", t);
+
+ assertEquals("a", t.get("default", String.class));
+ assertEquals("['b']", t.get("enum", String.class));
+ assertEquals("true", t.get("allowEmptyValue", String.class));
+ assertEquals("c", t.get("collectionFormat", String.class));
+ assertEquals("d", t.get("description", String.class));
+ assertEquals("true", t.get("exclusiveMaximum", String.class));
+ assertEquals("true", t.get("exclusiveMinimum", String.class));
+ assertEquals("e", t.get("format", String.class));
+ assertEquals("f", t.get("in", String.class));
+ assertEquals("{type:'g'}", t.get("items", String.class));
+ assertEquals("123.0", t.get("maximum", String.class));
+ assertEquals("123", t.get("maxItems", String.class));
+ assertEquals("123", t.get("maxLength", String.class));
+ assertEquals("123.0", t.get("minimum", String.class));
+ assertEquals("123", t.get("minItems", String.class));
+ assertEquals("123", t.get("minLength", String.class));
+ assertEquals("123.0", t.get("multipleOf", String.class));
+ assertEquals("h", t.get("name", String.class));
+ assertEquals("i", t.get("pattern", String.class));
+ assertEquals("true", t.get("required", String.class));
+ assertEquals("{title:'j'}", t.get("schema", String.class));
+ assertEquals("k", t.get("type", String.class));
+ assertEquals("true", t.get("uniqueItems", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(StringBuilder.class, t.get("default", Object.class));
+ assertType(List.class, t.get("enum", Object.class));
+ assertType(Boolean.class, t.get("allowEmptyValue", Object.class));
+ assertType(String.class, t.get("collectionFormat", Object.class));
+ assertType(String.class, t.get("description", Object.class));
+ assertType(Boolean.class, t.get("exclusiveMaximum", Object.class));
+ assertType(Boolean.class, t.get("exclusiveMinimum", Object.class));
+ assertType(String.class, t.get("format", Object.class));
+ assertType(String.class, t.get("in", Object.class));
+ assertType(Items.class, t.get("items", Object.class));
+ assertType(Float.class, t.get("maximum", Object.class));
+ assertType(Integer.class, t.get("maxItems", Object.class));
+ assertType(Integer.class, t.get("maxLength", Object.class));
+ assertType(Float.class, t.get("minimum", Object.class));
+ assertType(Integer.class, t.get("minItems", Object.class));
+ assertType(Integer.class, t.get("minLength", Object.class));
+ assertType(Float.class, t.get("multipleOf", Object.class));
+ assertType(String.class, t.get("name", Object.class));
+ assertType(String.class, t.get("pattern", Object.class));
+ assertType(Boolean.class, t.get("required", Object.class));
+ assertType(SchemaInfo.class, t.get("schema", Object.class));
+ assertType(String.class, t.get("type", Object.class));
+ assertType(Boolean.class, t.get("uniqueItems", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{'in':'f',name:'h',type:'k',description:'d',required:true,schema:{title:'j'},format:'e',allowEmptyValue:true,items:{type:'g'},collectionFormat:'c','default':'a',maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'i',maxItems:123,minItems:123,uniqueItems:true,'enum':['b'],multipleOf:123.0,'$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, ParameterInfo.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ResponseInfoTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ResponseInfoTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ResponseInfoTest.java
new file mode 100644
index 0000000..06eb4f8
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/ResponseInfoTest.java
@@ -0,0 +1,265 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.*;
+
+import org.apache.juneau.json.*;
+import org.apache.juneau.utils.*;
+
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+
+import org.junit.*;
+
+/**
+ * Testcase for {@link ResponseInfo}.
+ */
+public class ResponseInfoTest {
+
+ /**
+ * Test method for {@link ResponseInfo#description(java.lang.Object)}.
+ */
+ @Test
+ public void testDescription() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.description("foo");
+ assertEquals("foo", t.getDescription());
+
+ t.description(new StringBuilder("foo"));
+ assertEquals("foo", t.getDescription());
+ assertType(String.class, t.getDescription());
+
+ t.description(null);
+ assertNull(t.getDescription());
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#schema(java.lang.Object)}.
+ */
+ @Test
+ public void testSchema() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.schema(schemaInfo().title("foo"));
+ assertObjectEquals("{title:'foo'}", t.getSchema());
+
+ t.schema("{title:'foo'}");
+ assertObjectEquals("{title:'foo'}", t.getSchema());
+ assertType(SchemaInfo.class, t.getSchema());
+
+ t.schema(null);
+ assertNull(t.getSchema());
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#setHeaders(java.util.Map)}.
+ */
+ @Test
+ public void testSetHeaders() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.setHeaders(new AMap<String,HeaderInfo>().append("foo",headerInfo("bar")));
+ assertObjectEquals("{foo:{type:'bar'}}", t.getHeaders());
+ assertType(Map.class, t.getHeaders());
+ assertType(HeaderInfo.class, t.getHeaders().get("foo"));
+
+ t.setHeaders(new AMap<String,HeaderInfo>());
+ assertObjectEquals("{}", t.getHeaders());
+ assertType(Map.class, t.getHeaders());
+
+ t.setHeaders(null);
+ assertNull(t.getExamples());
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#addHeaders(java.util.Map)}.
+ */
+ @Test
+ public void testAddHeaders() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.addHeaders(new AMap<String,HeaderInfo>().append("foo",headerInfo("bar")));
+ assertObjectEquals("{foo:{type:'bar'}}", t.getHeaders());
+ assertType(Map.class, t.getHeaders());
+ assertType(HeaderInfo.class, t.getHeaders().get("foo"));
+
+ t.addHeaders(new AMap<String,HeaderInfo>());
+ assertObjectEquals("{foo:{type:'bar'}}", t.getHeaders());
+ assertType(Map.class, t.getHeaders());
+ assertType(HeaderInfo.class, t.getHeaders().get("foo"));
+
+ t.addHeaders(null);
+ assertObjectEquals("{foo:{type:'bar'}}", t.getHeaders());
+ assertType(Map.class, t.getHeaders());
+ assertType(HeaderInfo.class, t.getHeaders().get("foo"));
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#header(java.lang.String, org.apache.juneau.dto.swagger.HeaderInfo)}.
+ */
+ @Test
+ public void testHeader() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.header("a", headerInfo("a1"));
+ t.header("b", null);
+ t.header(null, headerInfo("c1"));
+
+ assertObjectEquals("{a:{type:'a1'},b:null,null:{type:'c1'}}", t.getHeaders());
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#headers(java.lang.Object[])}.
+ */
+ @Test
+ public void testHeaders() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.headers(new AMap<String,HeaderInfo>().append("a", headerInfo("a1")));
+ t.headers(new AMap<String,String>().append("b", "{type:'b1'}"));
+ t.headers("{c:{type:'c1'}}");
+ t.headers("{}");
+ t.headers((Object[])null);
+
+ assertObjectEquals("{a:{type:'a1'},b:{type:'b1'},c:{type:'c1'}}", t.getHeaders());
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#setExamples(java.util.Map)}.
+ */
+ @Test
+ public void testSetExamples() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.setExamples(new AMap<String,Object>().append("foo","bar").append("baz",new AList<String>().append("qux")));
+ assertObjectEquals("{foo:'bar',baz:['qux']}", t.getExamples());
+ assertType(Map.class, t.getExamples());
+
+ t.setExamples(new AMap<String,Object>());
+ assertObjectEquals("{}", t.getExamples());
+ assertType(Map.class, t.getExamples());
+
+ t.setExamples(null);
+ assertNull(t.getExamples());
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#addExamples(java.util.Map)}.
+ */
+ @Test
+ public void testAddExamples() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.addExamples(new AMap<String,Object>().append("foo","bar").append("baz",new AList<String>().append("qux")));
+ assertObjectEquals("{foo:'bar',baz:['qux']}", t.getExamples());
+ assertType(Map.class, t.getExamples());
+
+ t.addExamples(new AMap<String,Object>());
+ assertObjectEquals("{foo:'bar',baz:['qux']}", t.getExamples());
+ assertType(Map.class, t.getExamples());
+
+ t.addExamples(null);
+ assertObjectEquals("{foo:'bar',baz:['qux']}", t.getExamples());
+ assertType(Map.class, t.getExamples());
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#example(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testExample() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.example("text/a", "a");
+ t.example("text/b", null);
+ t.example(null, "c");
+
+ assertObjectEquals("{'text/a':'a','text/b':null,null:'c'}", t.getExamples());
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#examples(java.lang.Object[])}.
+ */
+ @Test
+ public void testExamples() {
+ ResponseInfo t = new ResponseInfo();
+
+ t.examples(new AMap<String,Object>().append("1",new AList<String>().append("a")));
+ t.examples("{2:{c1:'c2'}}");
+ t.examples("{}");
+ t.examples((Object)null);
+
+ assertObjectEquals("{'1':['a'],'2':{c1:'c2'}}", t.getExamples());
+ }
+
+ /**
+ * Test method for {@link ResponseInfo#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ ResponseInfo t = new ResponseInfo();
+
+ t
+ .set("description", "a")
+ .set("examples", new AMap<String,Object>().append("foo","bar").append("baz",new AList<String>().append("qux")))
+ .set("headers", new AMap<String,HeaderInfo>().append("a", headerInfo("a1")))
+ .set("schema", schemaInfo().type("d"))
+ .set("$ref", "ref");
+
+ assertObjectEquals("{description:'a',schema:{type:'d'},headers:{a:{type:'a1'}},examples:{foo:'bar',baz:['qux']},'$ref':'ref'}", t);
+
+ t
+ .set("description", "a")
+ .set("examples", "{foo:'bar',baz:['qux']}")
+ .set("headers", "{a:{type:'a1'}}")
+ .set("schema", "{type:'d'}")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{description:'a',schema:{type:'d'},headers:{a:{type:'a1'}},examples:{foo:'bar',baz:['qux']},'$ref':'ref'}", t);
+
+ t
+ .set("description", new StringBuilder("a"))
+ .set("examples", new StringBuilder("{foo:'bar',baz:['qux']}"))
+ .set("headers", new StringBuilder("{a:{type:'a1'}}"))
+ .set("schema", new StringBuilder("{type:'d'}"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{description:'a',schema:{type:'d'},headers:{a:{type:'a1'}},examples:{foo:'bar',baz:['qux']},'$ref':'ref'}", t);
+
+ assertEquals("a", t.get("description", String.class));
+ assertEquals("{foo:'bar',baz:['qux']}", t.get("examples", String.class));
+ assertEquals("{a:{type:'a1'}}", t.get("headers", String.class));
+ assertEquals("{type:'d'}", t.get("schema", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(String.class, t.get("description", Object.class));
+ assertType(Map.class, t.get("examples", Object.class));
+ assertType(Map.class, t.get("headers", Object.class));
+ assertType(HeaderInfo.class, t.get("headers", Map.class).values().iterator().next());
+ assertType(SchemaInfo.class, t.get("schema", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{description:'a',schema:{type:'d'},headers:{a:{type:'a1'}},examples:{foo:'bar',baz:['qux']},'$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, ResponseInfo.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SchemaInfoTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SchemaInfoTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SchemaInfoTest.java
new file mode 100644
index 0000000..4aac32a
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SchemaInfoTest.java
@@ -0,0 +1,1011 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.*;
+
+import org.apache.juneau.json.*;
+import org.apache.juneau.utils.*;
+
+import org.junit.*;
+
+/**
+ * Testcase for {@link SchemaInfo}.
+ */
+public class SchemaInfoTest {
+
+ /**
+ * Test method for {@link SchemaInfo#format(java.lang.Object)}.
+ */
+ @Test
+ public void testFormat() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.format("foo");
+ assertEquals("foo", t.getFormat());
+
+ t.format(new StringBuilder("foo"));
+ assertEquals("foo", t.getFormat());
+ assertType(String.class, t.getFormat());
+
+ t.format(null);
+ assertNull(t.getFormat());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#title(java.lang.Object)}.
+ */
+ @Test
+ public void testTitle() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.title("foo");
+ assertEquals("foo", t.getTitle());
+
+ t.title(new StringBuilder("foo"));
+ assertEquals("foo", t.getTitle());
+ assertType(String.class, t.getTitle());
+
+ t.title(null);
+ assertNull(t.getTitle());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#description(java.lang.Object)}.
+ */
+ @Test
+ public void testDescription() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.description("foo");
+ assertEquals("foo", t.getDescription());
+
+ t.description(new StringBuilder("foo"));
+ assertEquals("foo", t.getDescription());
+ assertType(String.class, t.getDescription());
+
+ t.description(null);
+ assertNull(t.getDescription());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#_default(java.lang.Object)}.
+ */
+ @Test
+ public void test_default() {
+ SchemaInfo t = new SchemaInfo();
+
+ t._default("foo");
+ assertEquals("foo", t.getDefault());
+
+ t._default(new StringBuilder("foo"));
+ assertEquals("foo", t.getDefault().toString());
+ assertType(StringBuilder.class, t.getDefault());
+
+ t._default(null);
+ assertNull(t.getDefault());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#multipleOf(java.lang.Object)}.
+ */
+ @Test
+ public void testMultipleOf() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.multipleOf(123);
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(123f);
+ assertEquals(123f, t.getMultipleOf());
+ assertType(Float.class, t.getMultipleOf());
+
+ t.multipleOf("123");
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(new StringBuilder("123"));
+ assertEquals(123, t.getMultipleOf());
+ assertType(Integer.class, t.getMultipleOf());
+
+ t.multipleOf(null);
+ assertNull(t.getMultipleOf());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#maximum(java.lang.Object)}.
+ */
+ @Test
+ public void testMaximum() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.maximum(123);
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(123f);
+ assertEquals(123f, t.getMaximum());
+ assertType(Float.class, t.getMaximum());
+
+ t.maximum("123");
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(new StringBuilder("123"));
+ assertEquals(123, t.getMaximum());
+ assertType(Integer.class, t.getMaximum());
+
+ t.maximum(null);
+ assertNull(t.getMaximum());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#exclusiveMaximum(java.lang.Object)}.
+ */
+ @Test
+ public void testExclusiveMaximum() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.exclusiveMaximum(true);
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum("true");
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum(new StringBuilder("true"));
+ assertEquals(true, t.getExclusiveMaximum());
+ assertType(Boolean.class, t.getExclusiveMaximum());
+
+ t.exclusiveMaximum(null);
+ assertNull(t.getExclusiveMaximum());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#minimum(java.lang.Object)}.
+ */
+ @Test
+ public void testMinimum() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.minimum(123);
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(123f);
+ assertEquals(123f, t.getMinimum());
+ assertType(Float.class, t.getMinimum());
+
+ t.minimum("123");
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(new StringBuilder("123"));
+ assertEquals(123, t.getMinimum());
+ assertType(Integer.class, t.getMinimum());
+
+ t.minimum(null);
+ assertNull(t.getMinimum());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#exclusiveMinimum(java.lang.Object)}.
+ */
+ @Test
+ public void testExclusiveMinimum() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.exclusiveMinimum(true);
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum("true");
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum(new StringBuilder("true"));
+ assertEquals(true, t.getExclusiveMinimum());
+ assertType(Boolean.class, t.getExclusiveMinimum());
+
+ t.exclusiveMinimum(null);
+ assertNull(t.getExclusiveMinimum());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#maxLength(java.lang.Object)}.
+ */
+ @Test
+ public void testMaxLength() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.maxLength(123);
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(123f);
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength("123");
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(new StringBuilder("123"));
+ assertEquals(123, t.getMaxLength().intValue());
+ assertType(Integer.class, t.getMaxLength());
+
+ t.maxLength(null);
+ assertNull(t.getMaxLength());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#minLength(java.lang.Object)}.
+ */
+ @Test
+ public void testMinLength() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.minLength(123);
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(123f);
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength("123");
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(new StringBuilder("123"));
+ assertEquals(123, t.getMinLength().intValue());
+ assertType(Integer.class, t.getMinLength());
+
+ t.minLength(null);
+ assertNull(t.getMinLength());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#pattern(java.lang.Object)}.
+ */
+ @Test
+ public void testPattern() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.pattern("foo");
+ assertEquals("foo", t.getPattern());
+
+ t.pattern(new StringBuilder("foo"));
+ assertEquals("foo", t.getPattern());
+ assertType(String.class, t.getPattern());
+
+ t.pattern(null);
+ assertNull(t.getPattern());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#maxItems(java.lang.Object)}.
+ */
+ @Test
+ public void testMaxItems() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.maxItems(123);
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(123f);
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems("123");
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(new StringBuilder("123"));
+ assertEquals(123, t.getMaxItems().intValue());
+ assertType(Integer.class, t.getMaxItems());
+
+ t.maxItems(null);
+ assertNull(t.getMaxItems());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#minItems(java.lang.Object)}.
+ */
+ @Test
+ public void testMinItems() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.minItems(123);
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(123f);
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems("123");
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(new StringBuilder("123"));
+ assertEquals(123, t.getMinItems().intValue());
+ assertType(Integer.class, t.getMinItems());
+
+ t.minItems(null);
+ assertNull(t.getMinItems());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#uniqueItems(java.lang.Object)}.
+ */
+ @Test
+ public void testUniqueItems() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.uniqueItems(true);
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems("true");
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems(new StringBuilder("true"));
+ assertEquals(true, t.getUniqueItems());
+ assertType(Boolean.class, t.getUniqueItems());
+
+ t.uniqueItems(null);
+ assertNull(t.getUniqueItems());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#maxProperties(java.lang.Object)}.
+ */
+ @Test
+ public void testMaxProperties() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.maxProperties(123);
+ assertEquals(123, t.getMaxProperties().intValue());
+ assertType(Integer.class, t.getMaxProperties());
+
+ t.maxProperties(123f);
+ assertEquals(123, t.getMaxProperties().intValue());
+ assertType(Integer.class, t.getMaxProperties());
+
+ t.maxProperties("123");
+ assertEquals(123, t.getMaxProperties().intValue());
+ assertType(Integer.class, t.getMaxProperties());
+
+ t.maxProperties(new StringBuilder("123"));
+ assertEquals(123, t.getMaxProperties().intValue());
+ assertType(Integer.class, t.getMaxProperties());
+
+ t.maxProperties(null);
+ assertNull(t.getMaxProperties());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#minProperties(java.lang.Object)}.
+ */
+ @Test
+ public void testMinProperties() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.minProperties(123);
+ assertEquals(123, t.getMinProperties().intValue());
+ assertType(Integer.class, t.getMinProperties());
+
+ t.minProperties(123f);
+ assertEquals(123, t.getMinProperties().intValue());
+ assertType(Integer.class, t.getMinProperties());
+
+ t.minProperties("123");
+ assertEquals(123, t.getMinProperties().intValue());
+ assertType(Integer.class, t.getMinProperties());
+
+ t.minProperties(new StringBuilder("123"));
+ assertEquals(123, t.getMinProperties().intValue());
+ assertType(Integer.class, t.getMinProperties());
+
+ t.minProperties(null);
+ assertNull(t.getMinProperties());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#required(java.lang.Object)}.
+ */
+ @Test
+ public void testRequired() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.required(true);
+ assertEquals(true, t.getRequired());
+ assertType(Boolean.class, t.getRequired());
+
+ t.required("true");
+ assertEquals(true, t.getRequired());
+ assertType(Boolean.class, t.getRequired());
+
+ t.required(new StringBuilder("true"));
+ assertEquals(true, t.getRequired());
+ assertType(Boolean.class, t.getRequired());
+
+ t.required(null);
+ assertNull(t.getRequired());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#setEnum(java.util.Collection)}.
+ */
+ @Test
+ public void testSetEnum() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.setEnum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(new ASet<Object>());
+ assertObjectEquals("[]", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(null);
+ assertNull(t.getEnum());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#addEnum(java.util.Collection)}.
+ */
+ @Test
+ public void testAddEnum() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.addEnum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.addEnum(new ASet<Object>().appendAll("baz"));
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.addEnum(null);
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#_enum(java.lang.Object[])}.
+ */
+ @Test
+ public void test_enum() {
+ SchemaInfo t = new SchemaInfo();
+
+ t._enum(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t._enum(new ASet<Object>().appendAll("baz"));
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t._enum((Object[])null);
+ assertObjectEquals("['foo','bar','baz']", t.getEnum());
+ assertType(List.class, t.getEnum());
+
+ t.setEnum(null);
+ t._enum("foo")._enum(new StringBuilder("bar"))._enum("['baz','qux']")._enum((Object)new String[]{"quux"});
+ assertObjectEquals("['foo','bar','baz','qux','quux']", t.getEnum());
+ assertType(List.class, t.getEnum());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#type(java.lang.Object)}.
+ */
+ @Test
+ public void testType() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.type("foo");
+ assertEquals("foo", t.getType());
+
+ t.type(new StringBuilder("foo"));
+ assertEquals("foo", t.getType());
+ assertType(String.class, t.getType());
+
+ t.type(null);
+ assertNull(t.getType());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#items(java.lang.Object)}.
+ */
+ @Test
+ public void testItems() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.items(items("foo"));
+ assertObjectEquals("{type:'foo'}", t.getItems());
+
+ t.items("{type:'foo'}");
+ assertObjectEquals("{type:'foo'}", t.getItems());
+ assertType(Items.class, t.getItems());
+
+ t.items(null);
+ assertNull(t.getItems());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#setAllOf(java.util.Collection)}.
+ */
+ @Test
+ public void testSetAllOf() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.setAllOf(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getAllOf());
+ assertType(List.class, t.getAllOf());
+
+ t.setAllOf(new ASet<Object>());
+ assertObjectEquals("[]", t.getAllOf());
+ assertType(List.class, t.getAllOf());
+
+ t.setAllOf(null);
+ assertNull(t.getAllOf());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#addAllOf(java.util.Collection)}.
+ */
+ @Test
+ public void testAddAllOf() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.addAllOf(new ASet<Object>().appendAll("foo","bar"));
+ assertObjectEquals("['foo','bar']", t.getAllOf());
+ assertType(List.class, t.getAllOf());
+
+ t.addAllOf(new ASet<Object>());
+ assertObjectEquals("['foo','bar']", t.getAllOf());
+ assertType(List.class, t.getAllOf());
+
+ t.addAllOf(null);
+ assertObjectEquals("['foo','bar']", t.getAllOf());
+ assertType(List.class, t.getAllOf());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#allOf(java.lang.Object[])}.
+ */
+ @Test
+ public void testAllOf() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.allOf(new ASet<String>().appendAll("a"));
+ t.allOf(new ASet<Object>().appendAll(new StringBuilder("b")));
+ t.allOf((Object)new String[] {"c"});
+ t.allOf((Object)new Object[] {new StringBuilder("d")});
+ t.allOf("e");
+ t.allOf("['f']");
+ t.allOf("[]");
+ t.allOf((Object)null);
+ assertObjectEquals("['a','b','c','d','e','f']", t.getAllOf());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#setProperties(java.util.Map)}.
+ */
+ @Test
+ public void testSetProperties() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.setProperties(new AMap<String,Map<String,Object>>().append("foo",new AMap<String,Object>().append("bar",new AList<Number>().append(123))));
+ assertObjectEquals("{foo:{bar:[123]}}", t.getProperties());
+ assertType(Map.class, t.getProperties());
+
+ t.setProperties(new AMap<String,Map<String,Object>>());
+ assertObjectEquals("{}", t.getProperties());
+ assertType(Map.class, t.getProperties());
+
+ t.setProperties(null);
+ assertNull(t.getProperties());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#addProperties(java.util.Map)}.
+ */
+ @Test
+ public void testAddProperties() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.addProperties(new AMap<String,Map<String,Object>>().append("foo",new AMap<String,Object>().append("bar",new AList<Number>().append(123))));
+ assertObjectEquals("{foo:{bar:[123]}}", t.getProperties());
+ assertType(Map.class, t.getProperties());
+
+ t.addProperties(new AMap<String,Map<String,Object>>());
+ assertObjectEquals("{foo:{bar:[123]}}", t.getProperties());
+ assertType(Map.class, t.getProperties());
+
+ t.addProperties(null);
+ assertObjectEquals("{foo:{bar:[123]}}", t.getProperties());
+ assertType(Map.class, t.getProperties());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#properties(java.lang.Object[])}.
+ */
+ @Test
+ public void testProperties() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.properties(new AMap<String,Map<String,Object>>().append("a", new AMap<String,Object>().append("a1", 1)));
+ t.properties(new AMap<String,String>().append("b", "{b1:2}"));
+ t.properties("{c:{c1:'c2'}}");
+ t.properties("{}");
+ t.properties((Object[])null);
+
+ assertObjectEquals("{a:{a1:1},b:{b1:2},c:{c1:'c2'}}", t.getProperties());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#setAdditionalProperties(java.util.Map)}.
+ */
+ @Test
+ public void testSetAdditionalProperties() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.setAdditionalProperties(new AMap<String,Object>().append("foo",new AList<String>().append("bar")));
+ assertObjectEquals("{foo:['bar']}", t.getAdditionalProperties());
+ assertType(Map.class, t.getAdditionalProperties());
+
+ t.setAdditionalProperties(new AMap<String,Object>());
+ assertObjectEquals("{}", t.getAdditionalProperties());
+ assertType(Map.class, t.getAdditionalProperties());
+
+ t.setAdditionalProperties(null);
+ assertNull(t.getAdditionalProperties());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#addAdditionalProperties(java.util.Map)}.
+ */
+ @Test
+ public void testAddAdditionalProperties() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.addAdditionalProperties(new AMap<String,Object>().append("foo",new AList<String>().append("bar")));
+ assertObjectEquals("{foo:['bar']}", t.getAdditionalProperties());
+ assertType(Map.class, t.getAdditionalProperties());
+
+ t.addAdditionalProperties(new AMap<String,Object>());
+ assertObjectEquals("{foo:['bar']}", t.getAdditionalProperties());
+ assertType(Map.class, t.getAdditionalProperties());
+
+ t.addAdditionalProperties(null);
+ assertObjectEquals("{foo:['bar']}", t.getAdditionalProperties());
+ assertType(Map.class, t.getAdditionalProperties());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#additionalProperty(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testAdditionalProperty() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.additionalProperty("a", "a1");
+ t.additionalProperty(null, "b1");
+ t.additionalProperty("c", null);
+
+ assertObjectEquals("{a:'a1',null:'b1',c:null}", t.getAdditionalProperties());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#additionalProperties(java.lang.Object[])}.
+ */
+ @Test
+ public void testAdditionalProperties() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.additionalProperties(new AMap<String,Object>().append("a",new AList<String>().append("a1")));
+ t.additionalProperties(new AMap<String,Object>().append("b","b1"));
+ t.additionalProperties("{c:['c1']}");
+ t.additionalProperties("{}");
+ t.additionalProperties((Object)null);
+
+ assertObjectEquals("{a:['a1'],b:'b1',c:['c1']}", t.getAdditionalProperties());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#discriminator(java.lang.Object)}.
+ */
+ @Test
+ public void testDiscriminator() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.discriminator("foo");
+ assertEquals("foo", t.getDiscriminator());
+
+ t.discriminator(new StringBuilder("foo"));
+ assertEquals("foo", t.getDiscriminator());
+ assertType(String.class, t.getDiscriminator());
+
+ t.discriminator(null);
+ assertNull(t.getDiscriminator());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#readOnly(java.lang.Object)}.
+ */
+ @Test
+ public void testReadOnly() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.readOnly(true);
+ assertEquals(true, t.getReadOnly());
+ assertType(Boolean.class, t.getReadOnly());
+
+ t.readOnly("true");
+ assertEquals(true, t.getReadOnly());
+ assertType(Boolean.class, t.getReadOnly());
+
+ t.readOnly(new StringBuilder("true"));
+ assertEquals(true, t.getReadOnly());
+ assertType(Boolean.class, t.getReadOnly());
+
+ t.readOnly(null);
+ assertNull(t.getReadOnly());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#xml(java.lang.Object)}.
+ */
+ @Test
+ public void testXml() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.xml(xml().name("foo"));
+ assertObjectEquals("{name:'foo'}", t.getXml());
+
+ t.xml("{name:'foo'}");
+ assertObjectEquals("{name:'foo'}", t.getXml());
+ assertType(Xml.class, t.getXml());
+
+ t.xml(null);
+ assertNull(t.getXml());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#externalDocs(java.lang.Object)}.
+ */
+ @Test
+ public void testExternalDocs() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.externalDocs(externalDocumentation("foo"));
+ assertObjectEquals("{url:'foo'}", t.getExternalDocs());
+
+ t.externalDocs("{url:'foo'}");
+ assertObjectEquals("{url:'foo'}", t.getExternalDocs());
+ assertType(ExternalDocumentation.class, t.getExternalDocs());
+
+ t.externalDocs(null);
+ assertNull(t.getExternalDocs());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#example(java.lang.Object)}.
+ */
+ @Test
+ public void testExample() {
+ SchemaInfo t = new SchemaInfo();
+
+ t.example("foo");
+ assertEquals("foo", t.getExample());
+
+ t.example(123);
+ assertEquals(123, t.getExample());
+
+ t.example(null);
+ assertNull(t.getExample());
+ }
+
+ /**
+ * Test method for {@link SchemaInfo#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ SchemaInfo t = new SchemaInfo();
+
+ t
+ .set("default", "a")
+ .set("enum", new ASet<Object>().appendAll("b"))
+ .set("additionalProperties", new AMap<String,Object>().append("c",new AList<String>().append("c1")))
+ .set("allOf", new ASet<String>().appendAll("d"))
+ .set("description", "e")
+ .set("discriminator", "f")
+ .set("example", "g")
+ .set("exclusiveMaximum", true)
+ .set("exclusiveMinimum", true)
+ .set("externalDocs", externalDocumentation("h"))
+ .set("format", "i")
+ .set("items", items("j"))
+ .set("maximum", 123f)
+ .set("maxItems", 123)
+ .set("maxLength", 123)
+ .set("maxProperties", 123)
+ .set("minimum", 123f)
+ .set("minItems", 123)
+ .set("minLength", 123)
+ .set("minProperties", 123)
+ .set("multipleOf", 123f)
+ .set("pattern", "k")
+ .set("properties", new AMap<String,Map<String,Object>>().append("l", new AMap<String,Object>().append("l1", 1)))
+ .set("readOnly", true)
+ .set("required", true)
+ .set("title", "m")
+ .set("type", "n")
+ .set("uniqueItems", true)
+ .set("xml", xml().name("o"))
+ .set("$ref", "ref");
+
+ assertObjectEquals("{format:'i',title:'m',description:'e','default':'a',multipleOf:123.0,maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'k',maxItems:123,minItems:123,uniqueItems:true,maxProperties:123,minProperties:123,required:true,'enum':['b'],type:'n',items:{type:'j'},allOf:['d'],properties:{l:{l1:1}},additionalProperties:{c:['c1']},discriminator:'f',readOnly:true,xml:{name:'o'},externalDocs:{url:'h'},example:'g','$ref':'ref'}", t);
+
+ t
+ .set("default", "a")
+ .set("enum", "['b']")
+ .set("additionalProperties", "{c:['c1']}")
+ .set("allOf", "['d']")
+ .set("description", "e")
+ .set("discriminator", "f")
+ .set("example", "g")
+ .set("exclusiveMaximum", "true")
+ .set("exclusiveMinimum", "true")
+ .set("externalDocs", "{url:'h'}")
+ .set("format", "i")
+ .set("items", "{type:'j'}")
+ .set("maximum", "123.0")
+ .set("maxItems", "123")
+ .set("maxLength", "123")
+ .set("maxProperties", "123")
+ .set("minimum", "123.0")
+ .set("minItems", "123")
+ .set("minLength", "123")
+ .set("minProperties", "123")
+ .set("multipleOf", "123.0")
+ .set("pattern", "k")
+ .set("properties", "{l:{l1:1}}")
+ .set("readOnly", "true")
+ .set("required", "true")
+ .set("title", "m")
+ .set("type", "n")
+ .set("uniqueItems", "true")
+ .set("xml", "{name:'o'}")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{format:'i',title:'m',description:'e','default':'a',multipleOf:123.0,maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'k',maxItems:123,minItems:123,uniqueItems:true,maxProperties:123,minProperties:123,required:true,'enum':['b'],type:'n',items:{type:'j'},allOf:['d'],properties:{l:{l1:1}},additionalProperties:{c:['c1']},discriminator:'f',readOnly:true,xml:{name:'o'},externalDocs:{url:'h'},example:'g','$ref':'ref'}", t);
+
+ t
+ .set("default", new StringBuilder("a"))
+ .set("enum", new StringBuilder("['b']"))
+ .set("additionalProperties", new StringBuilder("{c:['c1']}"))
+ .set("allOf", new StringBuilder("['d']"))
+ .set("description", new StringBuilder("e"))
+ .set("discriminator", new StringBuilder("f"))
+ .set("example", new StringBuilder("g"))
+ .set("exclusiveMaximum", new StringBuilder("true"))
+ .set("exclusiveMinimum", new StringBuilder("true"))
+ .set("externalDocs", new StringBuilder("{url:'h'}"))
+ .set("format", new StringBuilder("i"))
+ .set("items", new StringBuilder("{type:'j'}"))
+ .set("maximum", new StringBuilder("123.0"))
+ .set("maxItems", new StringBuilder("123"))
+ .set("maxLength", new StringBuilder("123"))
+ .set("maxProperties", new StringBuilder("123"))
+ .set("minimum", new StringBuilder("123.0"))
+ .set("minItems", new StringBuilder("123"))
+ .set("minLength", new StringBuilder("123"))
+ .set("minProperties", new StringBuilder("123"))
+ .set("multipleOf", new StringBuilder("123.0"))
+ .set("pattern", new StringBuilder("k"))
+ .set("properties", new StringBuilder("{l:{l1:1}}"))
+ .set("readOnly", new StringBuilder("true"))
+ .set("required", new StringBuilder("true"))
+ .set("title", new StringBuilder("m"))
+ .set("type", new StringBuilder("n"))
+ .set("uniqueItems", new StringBuilder("true"))
+ .set("xml", new StringBuilder("{name:'o'}"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{format:'i',title:'m',description:'e','default':'a',multipleOf:123.0,maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'k',maxItems:123,minItems:123,uniqueItems:true,maxProperties:123,minProperties:123,required:true,'enum':['b'],type:'n',items:{type:'j'},allOf:['d'],properties:{l:{l1:1}},additionalProperties:{c:['c1']},discriminator:'f',readOnly:true,xml:{name:'o'},externalDocs:{url:'h'},example:'g','$ref':'ref'}", t);
+
+ assertEquals("a", t.get("default", String.class));
+ assertEquals("['b']", t.get("enum", String.class));
+ assertEquals("{c:['c1']}", t.get("additionalProperties", String.class));
+ assertEquals("['d']", t.get("allOf", String.class));
+ assertEquals("e", t.get("description", String.class));
+ assertEquals("f", t.get("discriminator", String.class));
+ assertEquals("g", t.get("example", String.class));
+ assertEquals("true", t.get("exclusiveMaximum", String.class));
+ assertEquals("true", t.get("exclusiveMinimum", String.class));
+ assertEquals("{url:'h'}", t.get("externalDocs", String.class));
+ assertEquals("i", t.get("format", String.class));
+ assertEquals("{type:'j'}", t.get("items", String.class));
+ assertEquals("123.0", t.get("maximum", String.class));
+ assertEquals("123", t.get("maxItems", String.class));
+ assertEquals("123", t.get("maxLength", String.class));
+ assertEquals("123", t.get("maxProperties", String.class));
+ assertEquals("123.0", t.get("minimum", String.class));
+ assertEquals("123", t.get("minItems", String.class));
+ assertEquals("123", t.get("minLength", String.class));
+ assertEquals("123", t.get("minProperties", String.class));
+ assertEquals("123.0", t.get("multipleOf", String.class));
+ assertEquals("k", t.get("pattern", String.class));
+ assertEquals("{l:{l1:1}}", t.get("properties", String.class));
+ assertEquals("true", t.get("readOnly", String.class));
+ assertEquals("true", t.get("required", String.class));
+ assertEquals("m", t.get("title", String.class));
+ assertEquals("n", t.get("type", String.class));
+ assertEquals("true", t.get("uniqueItems", String.class));
+ assertEquals("{name:'o'}", t.get("xml", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(StringBuilder.class, t.get("default", Object.class));
+ assertType(List.class, t.get("enum", Object.class));
+ assertType(Map.class, t.get("additionalProperties", Object.class));
+ assertType(List.class, t.get("allOf", Object.class));
+ assertType(String.class, t.get("description", Object.class));
+ assertType(String.class, t.get("discriminator", Object.class));
+ assertType(StringBuilder.class, t.get("example", Object.class));
+ assertType(Boolean.class, t.get("exclusiveMaximum", Object.class));
+ assertType(Boolean.class, t.get("exclusiveMinimum", Object.class));
+ assertType(ExternalDocumentation.class, t.get("externalDocs", Object.class));
+ assertType(String.class, t.get("format", Object.class));
+ assertType(Items.class, t.get("items", Object.class));
+ assertType(Float.class, t.get("maximum", Object.class));
+ assertType(Integer.class, t.get("maxItems", Object.class));
+ assertType(Integer.class, t.get("maxLength", Object.class));
+ assertType(Integer.class, t.get("maxProperties", Object.class));
+ assertType(Float.class, t.get("minimum", Object.class));
+ assertType(Integer.class, t.get("minItems", Object.class));
+ assertType(Integer.class, t.get("minLength", Object.class));
+ assertType(Integer.class, t.get("minProperties", Object.class));
+ assertType(Float.class, t.get("multipleOf", Object.class));
+ assertType(String.class, t.get("pattern", Object.class));
+ assertType(Map.class, t.get("properties", Object.class));
+ assertType(Boolean.class, t.get("readOnly", Object.class));
+ assertType(Boolean.class, t.get("required", Object.class));
+ assertType(String.class, t.get("title", Object.class));
+ assertType(String.class, t.get("type", Object.class));
+ assertType(Boolean.class, t.get("uniqueItems", Object.class));
+ assertType(Xml.class, t.get("xml", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{format:'i',title:'m',description:'e','default':'a',multipleOf:123.0,maximum:123.0,exclusiveMaximum:true,minimum:123.0,exclusiveMinimum:true,maxLength:123,minLength:123,pattern:'k',maxItems:123,minItems:123,uniqueItems:true,maxProperties:123,minProperties:123,required:true,'enum':['b'],type:'n',items:{type:'j'},allOf:['d'],properties:{l:{l1:1}},additionalProperties:{c:['c1']},discriminator:'f',readOnly:true,xml:{name:'o'},externalDocs:{url:'h'},example:'g','$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, SchemaInfo.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SecuritySchemeTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SecuritySchemeTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SecuritySchemeTest.java
new file mode 100644
index 0000000..d878c31
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SecuritySchemeTest.java
@@ -0,0 +1,284 @@
+// ***************************************************************************************************************************
+// * 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.TestUtils.*;
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.*;
+
+import org.apache.juneau.json.*;
+import org.apache.juneau.utils.*;
+import org.junit.*;
+
+/**
+ * Testcase for {@link SecurityScheme}.
+ */
+public class SecuritySchemeTest {
+
+ /**
+ * Test method for {@link SecurityScheme#type(java.lang.Object)}.
+ */
+ @Test
+ public void testType() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.type("foo");
+ assertEquals("foo", t.getType());
+
+ t.type(new StringBuilder("foo"));
+ assertEquals("foo", t.getType());
+ assertType(String.class, t.getType());
+
+ t.type(null);
+ assertNull(t.getType());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#description(java.lang.Object)}.
+ */
+ @Test
+ public void testDescription() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.description("foo");
+ assertEquals("foo", t.getDescription());
+
+ t.description(new StringBuilder("foo"));
+ assertEquals("foo", t.getDescription());
+ assertType(String.class, t.getDescription());
+
+ t.description(null);
+ assertNull(t.getDescription());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#name(java.lang.Object)}.
+ */
+ @Test
+ public void testName() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.name("foo");
+ assertEquals("foo", t.getName());
+
+ t.name(new StringBuilder("foo"));
+ assertEquals("foo", t.getName());
+ assertType(String.class, t.getName());
+
+ t.name(null);
+ assertNull(t.getName());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#in(java.lang.Object)}.
+ */
+ @Test
+ public void testIn() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.in("foo");
+ assertEquals("foo", t.getIn());
+
+ t.in(new StringBuilder("foo"));
+ assertEquals("foo", t.getIn());
+ assertType(String.class, t.getIn());
+
+ t.in(null);
+ assertNull(t.getIn());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#flow(java.lang.Object)}.
+ */
+ @Test
+ public void testFlow() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.flow("foo");
+ assertEquals("foo", t.getFlow());
+
+ t.flow(new StringBuilder("foo"));
+ assertEquals("foo", t.getFlow());
+ assertType(String.class, t.getFlow());
+
+ t.flow(null);
+ assertNull(t.getFlow());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#authorizationUrl(java.lang.Object)}.
+ */
+ @Test
+ public void testAuthorizationUrl() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.authorizationUrl("foo");
+ assertEquals("foo", t.getAuthorizationUrl());
+
+ t.authorizationUrl(new StringBuilder("foo"));
+ assertEquals("foo", t.getAuthorizationUrl());
+ assertType(String.class, t.getAuthorizationUrl());
+
+ t.authorizationUrl(null);
+ assertNull(t.getAuthorizationUrl());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#tokenUrl(java.lang.Object)}.
+ */
+ @Test
+ public void testTokenUrl() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.tokenUrl("foo");
+ assertEquals("foo", t.getTokenUrl());
+
+ t.tokenUrl(new StringBuilder("foo"));
+ assertEquals("foo", t.getTokenUrl());
+ assertType(String.class, t.getTokenUrl());
+
+ t.tokenUrl(null);
+ assertNull(t.getTokenUrl());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#setScopes(java.util.Map)}.
+ */
+ @Test
+ public void testSetScopes() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.setScopes(new AMap<String,String>().append("foo","bar"));
+ assertObjectEquals("{foo:'bar'}", t.getScopes());
+ assertType(Map.class, t.getScopes());
+
+ t.setScopes(new AMap<String,String>());
+ assertObjectEquals("{}", t.getScopes());
+ assertType(Map.class, t.getScopes());
+
+ t.setScopes(null);
+ assertNull(t.getScopes());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#addScopes(java.util.Map)}.
+ */
+ @Test
+ public void testAddScopes() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.addScopes(new AMap<String,String>().append("foo","bar"));
+ assertObjectEquals("{foo:'bar'}", t.getScopes());
+ assertType(Map.class, t.getScopes());
+
+ t.addScopes(new AMap<String,String>());
+ assertObjectEquals("{foo:'bar'}", t.getScopes());
+ assertType(Map.class, t.getScopes());
+
+ t.addScopes(null);
+ assertObjectEquals("{foo:'bar'}", t.getScopes());
+ assertType(Map.class, t.getScopes());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#scopes(java.lang.Object[])}.
+ */
+ @Test
+ public void testScopes() {
+ SecurityScheme t = new SecurityScheme();
+
+ t.scopes(new AMap<String,String>().append("a", "a1"));
+ t.scopes("{b:'b1'}");
+ t.scopes("{}");
+ t.scopes((Object[])null);
+
+ assertObjectEquals("{a:'a1',b:'b1'}", t.getScopes());
+ }
+
+ /**
+ * Test method for {@link SecurityScheme#set(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSet() throws Exception {
+ SecurityScheme t = new SecurityScheme();
+
+ t
+ .set("authorizationUrl", "a")
+ .set("description", "b")
+ .set("flow", "c")
+ .set("in", "d")
+ .set("name", "e")
+ .set("scopes", new AMap<String,String>().append("foo","bar"))
+ .set("tokenUrl", "f")
+ .set("type", "g")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{type:'g',description:'b',name:'e','in':'d',flow:'c',authorizationUrl:'a',tokenUrl:'f',scopes:{foo:'bar'},'$ref':'ref'}", t);
+
+ t
+ .set("authorizationUrl", "a")
+ .set("description", "b")
+ .set("flow", "c")
+ .set("in", "d")
+ .set("name", "e")
+ .set("scopes", "{foo:'bar'}")
+ .set("tokenUrl", "f")
+ .set("type", "g")
+ .set("$ref", "ref");
+
+ assertObjectEquals("{type:'g',description:'b',name:'e','in':'d',flow:'c',authorizationUrl:'a',tokenUrl:'f',scopes:{foo:'bar'},'$ref':'ref'}", t);
+
+ t
+ .set("authorizationUrl", new StringBuilder("a"))
+ .set("description", new StringBuilder("b"))
+ .set("flow", new StringBuilder("c"))
+ .set("in", new StringBuilder("d"))
+ .set("name", new StringBuilder("e"))
+ .set("scopes", new StringBuilder("{foo:'bar'}"))
+ .set("tokenUrl", new StringBuilder("f"))
+ .set("type", new StringBuilder("g"))
+ .set("$ref", new StringBuilder("ref"));
+
+ assertObjectEquals("{type:'g',description:'b',name:'e','in':'d',flow:'c',authorizationUrl:'a',tokenUrl:'f',scopes:{foo:'bar'},'$ref':'ref'}", t);
+
+ assertEquals("a", t.get("authorizationUrl", String.class));
+ assertEquals("b", t.get("description", String.class));
+ assertEquals("c", t.get("flow", String.class));
+ assertEquals("d", t.get("in", String.class));
+ assertEquals("e", t.get("name", String.class));
+ assertEquals("{foo:'bar'}", t.get("scopes", String.class));
+ assertEquals("f", t.get("tokenUrl", String.class));
+ assertEquals("g", t.get("type", String.class));
+ assertEquals("ref", t.get("$ref", String.class));
+
+ assertType(String.class, t.get("authorizationUrl", Object.class));
+ assertType(String.class, t.get("description", Object.class));
+ assertType(String.class, t.get("flow", Object.class));
+ assertType(String.class, t.get("in", Object.class));
+ assertType(String.class, t.get("name", Object.class));
+ assertType(Map.class, t.get("scopes", Object.class));
+ assertType(String.class, t.get("tokenUrl", Object.class));
+ assertType(String.class, t.get("type", Object.class));
+ assertType(StringBuilder.class, t.get("$ref", Object.class));
+
+ t.set("null", null).set(null, "null");
+ assertNull(t.get("null", Object.class));
+ assertNull(t.get(null, Object.class));
+ assertNull(t.get("foo", Object.class));
+
+ String s = "{type:'g',description:'b',name:'e','in':'d',flow:'c',authorizationUrl:'a',tokenUrl:'f',scopes:{foo:'bar'},'$ref':'ref'}";
+ assertObjectEquals(s, JsonParser.DEFAULT.parse(s, SecurityScheme.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/8df34f56/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SwaggerBuilderTest.java
----------------------------------------------------------------------
diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SwaggerBuilderTest.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SwaggerBuilderTest.java
new file mode 100644
index 0000000..d34eb3f
--- /dev/null
+++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/dto/swagger/SwaggerBuilderTest.java
@@ -0,0 +1,322 @@
+// ***************************************************************************************************************************
+// * 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.junit.Assert.*;
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+import static org.apache.juneau.TestUtils.*;
+
+import org.junit.*;
+
+/**
+ * Testcase for {@link SwaggerBuilder}.
+ */
+public class SwaggerBuilderTest {
+
+ /**
+ * Test method for {@link SwaggerBuilder#contact()}.
+ */
+ @Test
+ public void testContact() {
+ Contact t = contact();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#contact(java.lang.String)}.
+ */
+ @Test
+ public void testContactString() {
+ Contact t = contact("foo");
+ assertObjectEquals("{name:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#contact(java.lang.String, java.lang.Object, java.lang.String)}.
+ */
+ @Test
+ public void testContactStringObjectString() {
+ Contact t = contact("foo", "bar", "baz");
+ assertObjectEquals("{name:'foo',url:'bar',email:'baz'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#externalDocumentation()}.
+ */
+ @Test
+ public void testExternalDocumentation() {
+ ExternalDocumentation t = externalDocumentation();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#externalDocumentation(java.lang.Object)}.
+ */
+ @Test
+ public void testExternalDocumentationObject() {
+ ExternalDocumentation t = externalDocumentation("foo");
+ assertObjectEquals("{url:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#externalDocumentation(java.lang.Object, java.lang.String)}.
+ */
+ @Test
+ public void testExternalDocumentationObjectString() {
+ ExternalDocumentation t = externalDocumentation("foo", "bar");
+ assertObjectEquals("{description:'bar',url:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#headerInfo()}.
+ */
+ @Test
+ public void testHeaderInfo() {
+ HeaderInfo t = headerInfo();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#headerInfo(java.lang.String)}.
+ */
+ @Test
+ public void testHeaderInfoString() {
+ HeaderInfo t = headerInfo("foo");
+ assertObjectEquals("{type:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#headerInfoStrict(java.lang.String)}.
+ */
+ @Test
+ public void testHeaderInfoStrict() {
+ HeaderInfo t = headerInfoStrict("string");
+ assertObjectEquals("{type:'string'}", t);
+
+ try {
+ headerInfoStrict("foo");
+ } catch (Exception e) {
+ assertEquals("Invalid value passed in to setType(String). Value='foo', valid values=['string','number','integer','boolean','array']", e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#info()}.
+ */
+ @Test
+ public void testInfo() {
+ Info t = info();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#info(java.lang.String, java.lang.String)}.
+ */
+ @Test
+ public void testInfoStringString() {
+ Info t = info("foo", "bar");
+ assertObjectEquals("{title:'foo',version:'bar'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#items()}.
+ */
+ @Test
+ public void testItems() {
+ Items t = items();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#items(java.lang.String)}.
+ */
+ @Test
+ public void testItemsString() {
+ Items t = items("foo");
+ assertObjectEquals("{type:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#itemsStrict(java.lang.String)}.
+ */
+ @Test
+ public void testItemsStrict() {
+ Items t = itemsStrict("string");
+ assertObjectEquals("{type:'string'}", t);
+
+ try {
+ itemsStrict("foo");
+ } catch (Exception e) {
+ assertEquals("Invalid value passed in to setType(String). Value='foo', valid values=['string','number','integer','boolean','array']", e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#license()}.
+ */
+ @Test
+ public void testLicense() {
+ License t = license();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#license(java.lang.String)}.
+ */
+ @Test
+ public void testLicenseString() {
+ License t = license("foo");
+ assertObjectEquals("{name:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#operation()}.
+ */
+ @Test
+ public void testOperation() {
+ Operation t = operation();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#parameterInfo()}.
+ */
+ @Test
+ public void testParameterInfo() {
+ ParameterInfo t = parameterInfo();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#parameterInfo(java.lang.String, java.lang.String)}.
+ */
+ @Test
+ public void testParameterInfoStringString() {
+ ParameterInfo t = parameterInfo("foo", "bar");
+ assertObjectEquals("{'in':'foo',name:'bar'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#parameterInfoStrict(java.lang.String, java.lang.String)}.
+ */
+ @Test
+ public void testParameterInfoStrict() {
+ ParameterInfo t = parameterInfoStrict("query", "bar");
+ assertObjectEquals("{'in':'query',name:'bar'}", t);
+
+ try {
+ parameterInfoStrict("foo", "bar");
+ } catch (Exception e) {
+ assertEquals("Invalid value passed in to setIn(String). Value='foo', valid values=['query','header','path','formData','body']", e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#responseInfo()}.
+ */
+ @Test
+ public void testResponseInfo() {
+ ResponseInfo t = responseInfo();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#responseInfo(java.lang.String)}.
+ */
+ @Test
+ public void testResponseInfoString() {
+ ResponseInfo t = responseInfo("foo");
+ assertObjectEquals("{description:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#schemaInfo()}.
+ */
+ @Test
+ public void testSchemaInfo() {
+ SchemaInfo t = schemaInfo();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#securityScheme()}.
+ */
+ @Test
+ public void testSecurityScheme() {
+ SecurityScheme t = securityScheme();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#securityScheme(java.lang.String)}.
+ */
+ @Test
+ public void testSecuritySchemeString() {
+ SecurityScheme t = securityScheme("foo");
+ assertObjectEquals("{type:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#securitySchemeStrict(java.lang.String)}.
+ */
+ @Test
+ public void testSecuritySchemeStrict() {
+ SecurityScheme t = securityScheme("foo");
+ assertObjectEquals("{type:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#swagger()}.
+ */
+ @Test
+ public void testSwagger() {
+ Swagger t = swagger();
+ assertObjectEquals("{swagger:'2.0'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#swagger(org.apache.juneau.dto.swagger.Info)}.
+ */
+ @Test
+ public void testSwaggerInfo() {
+ Swagger t = swagger(info());
+ assertObjectEquals("{swagger:'2.0',info:{}}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#tag()}.
+ */
+ @Test
+ public void testTag() {
+ Tag t = tag();
+ assertObjectEquals("{}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#tag(java.lang.String)}.
+ */
+ @Test
+ public void testTagString() {
+ Tag t = tag("foo");
+ assertObjectEquals("{name:'foo'}", t);
+ }
+
+ /**
+ * Test method for {@link SwaggerBuilder#xml()}.
+ */
+ @Test
+ public void testXml() {
+ Xml t = xml();
+ assertObjectEquals("{}", t);
+ }
+}