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 2017/02/17 02:35:51 UTC
[1/2] incubator-juneau git commit: Improvements to Swagger support.
Repository: incubator-juneau
Updated Branches:
refs/heads/master 949921157 -> 108b5db3f
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
index 8d9e54f..74b7741 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SchemaInfo.java
@@ -27,7 +27,8 @@ import org.apache.juneau.annotation.*;
* Unless stated otherwise, the property definitions follow the JSON Schema specification as referenced here.
*/
@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 {
+@SuppressWarnings({ "hiding", "unchecked" })
+public class SchemaInfo extends SwaggerElement {
private String format;
private String title;
@@ -84,6 +85,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setFormat(String)}.
+ *
+ * @param format The new value for the <property>format</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo format(String format) {
+ return setFormat(format);
+ }
+
+ /**
* 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.
@@ -104,6 +115,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setTitle(String)}.
+ *
+ * @param title The new value for the <property>title</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo title(String title) {
+ return setTitle(title);
+ }
+
+ /**
* 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.
@@ -128,6 +149,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setDescription(String)}.
+ *
+ * @param description The new value for the <property>description</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo description(String description) {
+ return setDescription(description);
+ }
+
+ /**
* Bean property getter: <property>default</property>.
* <p>
* Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object.
@@ -152,6 +183,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setDefault(Object)}.
+ *
+ * @param _default The new value for the <property>default</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo _default(Object _default) {
+ return setDefault(_default);
+ }
+
+ /**
* 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.
@@ -172,6 +213,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setMultipleOf(Number)}.
+ *
+ * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo multipleOf(Number multipleOf) {
+ return setMultipleOf(multipleOf);
+ }
+
+ /**
* 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.
@@ -192,6 +243,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setMaximum(Number)}.
+ *
+ * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo maximum(Number maximum) {
+ return setMaximum(maximum);
+ }
+
+ /**
* 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.
@@ -212,6 +273,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setExclusiveMaximum(Boolean)}.
+ *
+ * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo exclusiveMaximum(Boolean exclusiveMaximum) {
+ return setExclusiveMaximum(exclusiveMaximum);
+ }
+
+ /**
* 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.
@@ -232,6 +303,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setMinimum(Number)}.
+ *
+ * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo minimum(Number minimum) {
+ return setMinimum(minimum);
+ }
+
+ /**
* 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.
@@ -252,6 +333,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setExclusiveMinimum(Boolean)}.
+ *
+ * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo exclusiveMinimum(Boolean exclusiveMinimum) {
+ return setExclusiveMinimum(exclusiveMinimum);
+ }
+
+ /**
* 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.
@@ -272,6 +363,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setMaxLength(Integer)}.
+ *
+ * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo maxLength(Integer maxLength) {
+ return setMaxLength(maxLength);
+ }
+
+ /**
* 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.
@@ -292,6 +393,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setMinLength(Integer)}.
+ *
+ * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo minLength(Integer minLength) {
+ return setMinLength(minLength);
+ }
+
+ /**
* 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.
@@ -312,6 +423,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setPattern(String)}.
+ *
+ * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo pattern(String pattern) {
+ return setPattern(pattern);
+ }
+
+ /**
* 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.
@@ -332,6 +453,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setMaxItems(Integer)}.
+ *
+ * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo maxItems(Integer maxItems) {
+ return setMaxItems(maxItems);
+ }
+
+ /**
* 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.
@@ -352,6 +483,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setMinItems(Integer)}.
+ *
+ * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo minItems(Integer minItems) {
+ return setMinItems(minItems);
+ }
+
+ /**
* 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.
@@ -371,6 +512,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setUniqueItems(Boolean)}.
+ *
+ * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo uniqueItems(Boolean uniqueItems) {
+ return setUniqueItems(uniqueItems);
+ }
+
+ /**
* 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.
@@ -391,6 +542,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setMaxProperties(Integer)}.
+ *
+ * @param maxProperties The new value for the <property>maxProperties</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo maxProperties(Integer maxProperties) {
+ return setMaxProperties(maxProperties);
+ }
+
+ /**
* 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.
@@ -411,6 +572,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setMinProperties(Integer)}.
+ *
+ * @param minProperties The new value for the <property>minProperties</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo minProperties(Integer minProperties) {
+ return setMinProperties(minProperties);
+ }
+
+ /**
* 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.
@@ -431,6 +602,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setRequired(Boolean)}.
+ *
+ * @param required The new value for the <property>required</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo required(Boolean required) {
+ return setRequired(required);
+ }
+
+ /**
* 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.
@@ -454,25 +635,33 @@ public class SchemaInfo {
* Bean property adder: <property>enum</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.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public SchemaInfo addEnum(Object..._enum) {
- return addEnum(Arrays.asList(_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<Object>();
+ this._enum.add(o);
+ }
+ }
+ }
+ return this;
}
/**
- * Bean property adder: <property>enum</property>.
+ * 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.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
- public SchemaInfo addEnum(Collection<Object> _enum) {
- if (this._enum == null)
- this._enum = new LinkedList<Object>();
- this._enum.addAll(_enum);
- return this;
+ public SchemaInfo _enum(Object..._enum) {
+ return addEnum(_enum);
}
/**
@@ -496,6 +685,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setType(String)}.
+ *
+ * @param type The new value for the <property>type</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo type(String type) {
+ return setType(type);
+ }
+
+ /**
* 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.
@@ -516,6 +715,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setItems(Items)}.
+ *
+ * @param items The new value for the <property>items</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo items(Items items) {
+ return setItems(items);
+ }
+
+ /**
* 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.
@@ -536,28 +745,36 @@ public class SchemaInfo {
}
/**
- * Bean property adder: <property>allOf</property>.
+ * Bean property adder: <property>enum</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.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public SchemaInfo addAllOf(Object...allOf) {
- return addAllOf(Arrays.asList(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<Object>();
+ this.allOf.add(o);
+ }
+ }
+ }
+ return this;
}
/**
- * Bean property adder: <property>allOf</property>.
+ * 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.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
- public SchemaInfo addAllOf(Collection<Object> allOf) {
- if (this.allOf == null)
- this.allOf = new LinkedList<Object>();
- this.allOf.addAll(allOf);
- return this;
+ public SchemaInfo allOf(Object...allOf) {
+ return addAllOf(allOf);
}
/**
@@ -595,6 +812,22 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #addProperty(String,Map)}.
+ *
+ * @param name The property name.
+ * @param propertyProperties The properties of the property.
+ * @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<String,Object>();
+ for (int i = 0; i < propertyProperties.length; i += 2)
+ m.put(String.valueOf(propertyProperties[i]), propertyProperties[i+1]);
+ return addProperty(name, m);
+ }
+
+ /**
* 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.
@@ -615,6 +848,21 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setAdditionalProperties(Map)}.
+ *
+ * @param additionalProperties The new value for the <property>additionalProperties</property> property on this bean.
+ * @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<String,Object>();
+ for (int i = 0; i < additionalProperties.length; i += 2)
+ m.put(String.valueOf(additionalProperties[i]), additionalProperties[i+1]);
+ return setAdditionalProperties(m);
+ }
+
+ /**
* 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.
@@ -635,6 +883,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setDiscriminator(String)}.
+ *
+ * @param discriminator The new value for the <property>discriminator</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo discriminator(String discriminator) {
+ return setDiscriminator(discriminator);
+ }
+
+ /**
* 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.
@@ -655,6 +913,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setReadOnly(Boolean)}.
+ *
+ * @param readOnly The new value for the <property>readOnly</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo readOnly(Boolean readOnly) {
+ return setReadOnly(readOnly);
+ }
+
+ /**
* 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.
@@ -675,6 +943,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setXml(Xml)}.
+ *
+ * @param xml The new value for the <property>xml</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo xml(Xml xml) {
+ return setXml(xml);
+ }
+
+ /**
* 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.
@@ -695,6 +973,16 @@ public class SchemaInfo {
}
/**
+ * Synonym for {@link #setExternalDocs(ExternalDocumentation)}.
+ *
+ * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo externalDocs(ExternalDocumentation externalDocs) {
+ return setExternalDocs(externalDocs);
+ }
+
+ /**
* 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.
@@ -713,4 +1001,14 @@ public class SchemaInfo {
this.example = example;
return this;
}
+
+ /**
+ * Synonym for {@link #setExample(Object)}.
+ *
+ * @param example The new value for the <property>example</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SchemaInfo example(Object example) {
+ return setExample(example);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java
index d3d8c36..97d449a 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SecurityScheme.java
@@ -50,7 +50,8 @@ import org.apache.juneau.json.*;
* </p>
*/
@Bean(properties="type,description,name,in,flow,authorizationUrl,tokenUrl,scopes")
-public class SecurityScheme {
+@SuppressWarnings("hiding")
+public class SecurityScheme extends SwaggerElement {
private static final String[] VALID_TYPES = {"basic", "apiKey", "oauth2"};
@@ -62,33 +63,10 @@ public class SecurityScheme {
private String authorizationUrl;
private String tokenUrl;
private Map<String,String> scopes;
- private boolean strict;
- /**
- * Convenience method for creating a new SecurityScheme object.
- *
- * @param type Required. The type of the security scheme.
- * Valid values are <js>"basic"</js>, <js>"apiKey"</js> or <js>"oauth2"</js>.
- * @return A new SecurityScheme object.
- */
- public static SecurityScheme create(String type) {
- return new SecurityScheme().setType(type);
- }
-
- /**
- * Same as {@link #create(String)} except methods will throw runtime exceptions if you attempt
- * to pass in invalid values per the Swagger spec.
- *
- * @param type Required. The type of the security scheme.
- * Valid values are <js>"basic"</js>, <js>"apiKey"</js> or <js>"oauth2"</js>.
- * @return A new SecurityScheme object.
- */
- public static SecurityScheme createStrict(String type) {
- return new SecurityScheme().setStrict().setType(type);
- }
-
- private SecurityScheme setStrict() {
- this.strict = true;
+ @Override /* SwaggerElement */
+ protected SecurityScheme strict() {
+ super.strict();
return this;
}
@@ -114,13 +92,23 @@ public class SecurityScheme {
* @return This object (for method chaining).
*/
public SecurityScheme setType(String type) {
- if (strict && ! ArrayUtils.contains(type, VALID_TYPES))
+ if (isStrict() && ! ArrayUtils.contains(type, VALID_TYPES))
throw new RuntimeException("Invalid value passed in to setType(String). Value='"+type+"', valid values=" + JsonSerializer.DEFAULT_LAX.toString(VALID_TYPES));
this.type = type;
return this;
}
/**
+ * Synonym for {@link #setType(String)}.
+ *
+ * @param type The new value for the <property>type</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SecurityScheme type(String type) {
+ return setType(type);
+ }
+
+ /**
* Bean property getter: <property>description</property>.
* <p>
* A short description for security scheme.
@@ -145,6 +133,16 @@ public class SecurityScheme {
}
/**
+ * Synonym for {@link #setDescription(String)}.
+ *
+ * @param description The new value for the <property>description</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SecurityScheme description(String description) {
+ return setDescription(description);
+ }
+
+ /**
* Bean property getter: <property>name</property>.
* <p>
* The name of the header or query parameter to be used.
@@ -169,6 +167,16 @@ public class SecurityScheme {
}
/**
+ * Synonym for {@link #setName(String)}.
+ *
+ * @param name The new value for the <property>name</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SecurityScheme name(String name) {
+ return setName(name);
+ }
+
+ /**
* Bean property getter: <property>in</property>.
* <p>
* The location of the API key. Valid values are <js>"query"</js> or <js>"header"</js>.
@@ -193,6 +201,16 @@ public class SecurityScheme {
}
/**
+ * Synonym for {@link #setIn(String)}.
+ *
+ * @param in The new value for the <property>in</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SecurityScheme in(String in) {
+ return setIn(in);
+ }
+
+ /**
* Bean property getter: <property>flow</property>.
* <p>
* The flow used by the OAuth2 security scheme.
@@ -219,6 +237,16 @@ public class SecurityScheme {
}
/**
+ * Synonym for {@link #setFlow(String)}.
+ *
+ * @param flow The new value for the <property>flow</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SecurityScheme flow(String flow) {
+ return setFlow(flow);
+ }
+
+ /**
* Bean property getter: <property>authorizationUrl</property>.
* <p>
* The authorization URL to be used for this flow.
@@ -245,6 +273,16 @@ public class SecurityScheme {
}
/**
+ * Synonym for {@link #setAuthorizationUrl(String)}.
+ *
+ * @param authorizationUrl The new value for the <property>authorizationUrl</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SecurityScheme authorizationUrl(String authorizationUrl) {
+ return setAuthorizationUrl(authorizationUrl);
+ }
+
+ /**
* Bean property getter: <property>tokenUrl</property>.
* <p>
* The token URL to be used for this flow.
@@ -271,6 +309,16 @@ public class SecurityScheme {
}
/**
+ * Synonym for {@link #setTokenUrl(String)}.
+ *
+ * @param tokenUrl The new value for the <property>tokenUrl</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public SecurityScheme tokenUrl(String tokenUrl) {
+ return setTokenUrl(tokenUrl);
+ }
+
+ /**
* Bean property getter: <property>scopes</property>.
* <p>
* The available scopes for the OAuth2 security scheme.
@@ -303,11 +351,21 @@ public class SecurityScheme {
* @param description A short description of the scope.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public SecurityScheme addScope(String name, String description) {
if (scopes == null)
scopes = new TreeMap<String,String>();
scopes.put(name, description);
return this;
}
+
+ /**
+ * Synonym for {@link #addScope(String,String)}.
+ *
+ * @param name The name of the scope.
+ * @param description A short description of the scope.
+ * @return This object (for method chaining).
+ */
+ public SecurityScheme scope(String name, String description) {
+ return addScope(name, description);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Swagger.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
index 71e8bc7..1065a0a 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Swagger.java
@@ -21,7 +21,8 @@ import org.apache.juneau.annotation.*;
* This is the root document object for the API specification.
*/
@Bean(properties="swagger,info,tags,externalDocs,basePath,schemes,consumes,produces,paths,definitions,parameters,responses,securityDefinitions,security")
-public class Swagger {
+@SuppressWarnings("hiding")
+public class Swagger extends SwaggerElement {
/** Represents a null swagger */
public static final Swagger NULL = new Swagger();
@@ -42,17 +43,6 @@ public class Swagger {
private ExternalDocumentation externalDocs;
/**
- * Convenience method for creating a new Swagger object.
- *
- * @param info Required. Provides metadata about the API.
- * The metadata can be used by the clients if needed.
- * @return A new Swagger object.
- */
- public static Swagger create(Info info) {
- return new Swagger().setInfo(info);
- }
-
- /**
* Bean property getter: <property>swagger</property>.
* <p>
* Required. Specifies the Swagger Specification version being used.
@@ -81,6 +71,16 @@ public class Swagger {
}
/**
+ * Synonym for {@link #setSwagger(String)}.
+ *
+ * @param swagger The new value for the <property>swagger</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Swagger swagger(String swagger) {
+ return setSwagger(swagger);
+ }
+
+ /**
* Bean property getter: <property>info</property>.
* <p>
* Required. Provides metadata about the API.
@@ -107,6 +107,16 @@ public class Swagger {
}
/**
+ * Synonym for {@link #setInfo(Info)}.
+ *
+ * @param info The new value for the <property>info</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Swagger info(Info info) {
+ return setInfo(info);
+ }
+
+ /**
* Bean property getter: <property>host</property>.
* <p>
* The host (name or ip) serving the API.
@@ -139,6 +149,16 @@ public class Swagger {
}
/**
+ * Synonym for {@link #setHost(String)}.
+ *
+ * @param host The new value for the <property>host</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Swagger host(String host) {
+ return setHost(host);
+ }
+
+ /**
* Bean property getter: <property>basePath</property>.
* <p>
* The base path on which the API is served, which is relative to the <code>host</code>.
@@ -169,6 +189,16 @@ public class Swagger {
}
/**
+ * Synonym for {@link #setBasePath(String)}.
+ *
+ * @param basePath The new value for the <property>basePath</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Swagger basePath(String basePath) {
+ return setBasePath(basePath);
+ }
+
+ /**
* Bean property getter: <property>schemes</property>.
* <p>
* The transfer protocol of the API.
@@ -206,7 +236,6 @@ public class Swagger {
* @param schemes The values to add for the <property>schemes</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Swagger addSchemes(String...schemes) {
return addSchemes(Arrays.asList(schemes));
}
@@ -221,15 +250,26 @@ public class Swagger {
* @param schemes The values to add for the <property>schemes</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Swagger addSchemes(Collection<String> schemes) {
- if (this.schemes == null)
- this.schemes = new LinkedList<String>();
- this.schemes.addAll(schemes);
+ if (schemes != null) {
+ if (this.schemes == null)
+ this.schemes = new LinkedList<String>();
+ this.schemes.addAll(schemes);
+ }
return this;
}
/**
+ * Synonym for {@link #addSchemes(String...)}.
+ *
+ * @param schemes The values to add for the <property>schemes</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Swagger schemes(String...schemes) {
+ return addSchemes(schemes);
+ }
+
+ /**
* Bean property getter: <property>consumes</property>.
* <p>
* A list of MIME types the APIs can consume.
@@ -267,7 +307,6 @@ public class Swagger {
* @param consumes The values to add for the <property>consumes</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Swagger addConsumes(MediaType...consumes) {
return addConsumes(Arrays.asList(consumes));
}
@@ -282,15 +321,36 @@ public class Swagger {
* @param consumes The values to add for the <property>consumes</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Swagger addConsumes(Collection<MediaType> consumes) {
- if (this.consumes == null)
- this.consumes = new LinkedList<MediaType>();
- this.consumes.addAll(consumes);
+ if (consumes != null) {
+ if (this.consumes == null)
+ this.consumes = new LinkedList<MediaType>();
+ this.consumes.addAll(consumes);
+ }
return this;
}
/**
+ * Synonym for {@link #addConsumes(MediaType...)}.
+ *
+ * @param consumes The values to add for the <property>consumes</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Swagger consumes(MediaType...consumes) {
+ return addConsumes(consumes);
+ }
+
+ /**
+ * 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>.
* <p>
* A list of MIME types the APIs can produce.
@@ -328,7 +388,6 @@ public class Swagger {
* @param produces The values to add for the <property>produces</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Swagger addProduces(MediaType...produces) {
return addProduces(Arrays.asList(produces));
}
@@ -343,15 +402,36 @@ public class Swagger {
* @param produces The values to add for the <property>produces</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Swagger addProduces(Collection<MediaType> produces) {
- if (this.produces == null)
- this.produces = new LinkedList<MediaType>();
- this.produces.addAll(produces);
+ if (produces != null) {
+ if (this.produces == null)
+ this.produces = new LinkedList<MediaType>();
+ this.produces.addAll(produces);
+ }
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.
+ * @return This object (for method chaining).
+ */
+ public Swagger produces(Collection<MediaType> produces) {
+ return addProduces(produces);
+ }
+
+ /**
* Bean property getter: <property>paths</property>.
* <p>
* Required. The available paths and operations for the API.
@@ -398,6 +478,18 @@ public class Swagger {
}
/**
+ * 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.
+ * @return This object (for method chaining).
+ */
+ public Swagger path(String path, String methodName, Operation operation) {
+ return addPath(path, methodName, operation);
+ }
+
+ /**
* Bean property getter: <property>definitions</property>.
* <p>
* An object to hold data types produced and consumed by operations.
@@ -438,6 +530,17 @@ public class Swagger {
}
/**
+ * Synonym for {@link #addDefinition(String,SchemaInfo)}.
+ *
+ * @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);
+ }
+
+ /**
* Bean property getter: <property>parameters</property>.
* <p>
* An object to hold parameters that can be used across operations.
@@ -481,6 +584,17 @@ public class Swagger {
}
/**
+ * Synonym for {@link #addParameter(String,ParameterInfo)}.
+ *
+ * @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);
+ }
+
+ /**
* Bean property getter: <property>responses</property>.
* <p>
* An object to hold responses that can be used across operations.
@@ -524,6 +638,17 @@ public class Swagger {
}
/**
+ * Synonym for {@link #addResponse(String,ResponseInfo)}.
+ *
+ * @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);
+ }
+
+ /**
* Bean property getter: <property>securityDefinitions</property>.
* <p>
* Security scheme definitions that can be used across the specification.
@@ -564,6 +689,17 @@ public class Swagger {
}
/**
+ * Synonym for {@link #addSecurityDefinition(String,SecurityScheme)}.
+ *
+ * @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);
+ }
+
+ /**
* Bean property getter: <property>security</property>.
* <p>
* A declaration of which security schemes are applied for the API as a whole.
@@ -601,7 +737,6 @@ public class Swagger {
* @param security The value to add for the <property>security</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Swagger addSecurity(Map<String,List<String>> security) {
if (this.security == null)
this.security = new LinkedList<Map<String,List<String>>>();
@@ -610,6 +745,19 @@ public class Swagger {
}
/**
+ * Synonym for {@link #addSecurity(Map)}.
+ *
+ * @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).
+ * @return This object (for method chaining).
+ */
+ public Swagger security(String scheme, String...alternatives) {
+ Map<String,List<String>> m = new LinkedHashMap<String,List<String>>();
+ m.put(scheme, Arrays.asList(alternatives));
+ return addSecurity(m);
+ }
+
+ /**
* Bean property getter: <property>tags</property>.
* <p>
* A list of tags used by the specification with additional metadata.
@@ -653,7 +801,6 @@ public class Swagger {
* @param tags The values to add for the <property>tags</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Swagger addTags(Tag...tags) {
if (this.tags == null)
this.tags = new LinkedList<Tag>();
@@ -662,6 +809,26 @@ public class Swagger {
}
/**
+ * 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.
+ * @return This object (for method chaining).
+ */
+ public Swagger tags(List<Tag> tags) {
+ return setTags(tags);
+ }
+
+ /**
* Bean property getter: <property>externalDocs</property>.
* <p>
* Additional external documentation.
@@ -685,6 +852,16 @@ public class Swagger {
return this;
}
+ /**
+ * Synonym for {@link #setExternalDocs(ExternalDocumentation)}.
+ *
+ * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Swagger externalDocs(ExternalDocumentation externalDocs) {
+ return setExternalDocs(externalDocs);
+ }
+
private static class MethodSorter implements Comparator<String> {
@SuppressWarnings("serial")
private final Map<String,Integer> methods = new HashMap<String,Integer>(){{
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SwaggerBuilder.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SwaggerBuilder.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SwaggerBuilder.java
new file mode 100644
index 0000000..b45f740
--- /dev/null
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SwaggerBuilder.java
@@ -0,0 +1,292 @@
+// ***************************************************************************************************************************
+// * 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;
+
+/**
+ * Various useful static methods for creating Swagger elements.
+ * <p>
+ * See {@link org.apache.juneau.dto.swagger} for documentation.
+ */
+public class SwaggerBuilder {
+
+ /**
+ * Creates an empty {@link Contact} element.
+ * @return The new element.
+ */
+ public static final Contact contact() {
+ return new Contact();
+ }
+
+ /**
+ * Creates an {@link Contact} element with the specified {@link Contact#name(String)} attribute.
+ * @param name The {@link Contact#name(String)} attribute.
+ * @return The new element.
+ */
+ public static final Contact contact(String name) {
+ return contact().name(name);
+ }
+
+ /**
+ * Creates an {@link Contact} element with the specified {@link Contact#name(String)}, {@link Contact#url(String)}, and {@link Contact#email(String)}, attributes.
+ * @param name The {@link Contact#name(String)} attribute.
+ * @param url The {@link Contact#url(String)} attribute.
+ * @param email The {@link Contact#email(String)} attribute.
+ * @return The new element.
+ */
+ public static final Contact contact(String name, String url, String email) {
+ return contact().name(name).url(url).email(email);
+ }
+
+ /**
+ * Creates an empty {@link ExternalDocumentation} element.
+ * @return The new element.
+ */
+ public static final ExternalDocumentation externalDocumentation() {
+ return new ExternalDocumentation();
+ }
+
+ /**
+ * Creates an {@link ExternalDocumentation} element with the specified {@link ExternalDocumentation#url(String)} attribute.
+ * @param url The {@link ExternalDocumentation#url(String)} attribute.
+ * @return The new element.
+ */
+ public static final ExternalDocumentation externalDocumentation(String url) {
+ return externalDocumentation().url(url);
+ }
+
+ /**
+ * Creates an {@link ExternalDocumentation} element with the specified {@link ExternalDocumentation#url(String)} and {@link ExternalDocumentation#description(String)} attributes.
+ * @param url The {@link ExternalDocumentation#url(String)} attribute.
+ * @param description The {@link ExternalDocumentation#description(String)} attribute.
+ * @return The new element.
+ */
+ public static final ExternalDocumentation externalDocumentation(String url, String description) {
+ return externalDocumentation().url(url).description(description);
+ }
+
+ /**
+ * Creates an empty {@link HeaderInfo} element.
+ * @return The new element.
+ */
+ public static final HeaderInfo headerInfo() {
+ return new HeaderInfo();
+ }
+
+ /**
+ * Creates an {@link HeaderInfo} element with the specified {@link HeaderInfo#type(String)} attribute.
+ * @param type The {@link HeaderInfo#type(String)} attribute.
+ * @return The new element.
+ */
+ public static final HeaderInfo headerInfo(String type) {
+ return headerInfo().type(type);
+ }
+
+ /**
+ * Creates an {@link HeaderInfo} element with the specified {@link HeaderInfo#type(String)} attribute.
+ * @param type The {@link HeaderInfo#type(String)} attribute.
+ * @return The new element.
+ */
+ public static final HeaderInfo headerInfoStrict(String type) {
+ return headerInfo().strict().type(type);
+ }
+
+ /**
+ * Creates an empty {@link Info} element.
+ * @return The new element.
+ */
+ public static final Info info() {
+ return new Info();
+ }
+
+ /**
+ * Creates an {@link Info} element with the specified {@link Info#title(String)} and {@link Info#version(String)} attributes.
+ * @param title The {@link Info#title(String)} attribute.
+ * @param version The {@link Info#version(String)} attribute.
+ * @return The new element.
+ */
+ public static final Info info(String title, String version) {
+ return info().title(title).version(version);
+ }
+
+ /**
+ * Creates an empty {@link Items} element.
+ * @return The new element.
+ */
+ public static final Items items() {
+ return new Items();
+ }
+
+ /**
+ * Creates an {@link Items} element with the specified {@link Items#type(String)} attribute.
+ * @param type The {@link Items#type(String)} attribute.
+ * @return The new element.
+ */
+ public static final Items items(String type) {
+ return items().type(type);
+ }
+
+ /**
+ * Creates an {@link Items} element with the specified {@link Items#type(String)} attribute.
+ * @param type The {@link Items#type(String)} attribute.
+ * @return The new element.
+ */
+ public static final Items itemsStrict(String type) {
+ return items().strict().type(type);
+ }
+
+ /**
+ * Creates an empty {@link License} element.
+ * @return The new element.
+ */
+ public static final License license() {
+ return new License();
+ }
+
+ /**
+ * Creates an {@link License} element with the specified {@link License#name(String)} attribute.
+ * @param name The {@link License#name(String)} attribute.
+ * @return The new element.
+ */
+ public static final License license(String name) {
+ return license().name(name);
+ }
+
+ /**
+ * Creates an empty {@link Operation} element.
+ * @return The new element.
+ */
+ public static final Operation operation() {
+ return new Operation();
+ }
+
+ /**
+ * Creates an empty {@link ParameterInfo} element.
+ * @return The new element.
+ */
+ public static final ParameterInfo parameterInfo() {
+ return new ParameterInfo();
+ }
+
+ /**
+ * Creates an {@link ParameterInfo} element with the specified {@link ParameterInfo#in(String)} and {@link ParameterInfo#name(String)} attributes.
+ * @param in The {@link ParameterInfo#in(String)} attribute.
+ * @param name The {@link ParameterInfo#name(String)} attribute.
+ * @return The new element.
+ */
+ public static final ParameterInfo parameterInfo(String in, String name) {
+ return parameterInfo().in(in).name(name);
+ }
+
+ /**
+ * Creates an {@link ParameterInfo} element with the specified {@link ParameterInfo#in(String)} and {@link ParameterInfo#name(String)} attributes.
+ * @param in The {@link ParameterInfo#in(String)} attribute.
+ * @param name The {@link ParameterInfo#name(String)} attribute.
+ * @return The new element.
+ */
+ public static final ParameterInfo parameterInfoStrict(String in, String name) {
+ return parameterInfo().strict().in(in).name(name);
+ }
+
+ /**
+ * Creates an empty {@link ResponseInfo} element.
+ * @return The new element.
+ */
+ public static final ResponseInfo responseInfo() {
+ return new ResponseInfo();
+ }
+
+ /**
+ * Creates an {@link ResponseInfo} element with the specified {@link ResponseInfo#description(String)} attribute.
+ * @param description The {@link ResponseInfo#description(String)} attribute.
+ * @return The new element.
+ */
+ public static final ResponseInfo responseInfo(String description) {
+ return responseInfo().description(description);
+ }
+
+ /**
+ * Creates an empty {@link SchemaInfo} element.
+ * @return The new element.
+ */
+ public static final SchemaInfo schemaInfo() {
+ return new SchemaInfo();
+ }
+
+ /**
+ * Creates an empty {@link SecurityScheme} element.
+ * @return The new element.
+ */
+ public static final SecurityScheme securityScheme() {
+ return new SecurityScheme();
+ }
+
+ /**
+ * Creates an {@link SecurityScheme} element with the specified {@link SecurityScheme#type(String)} attribute.
+ * @param type The {@link SecurityScheme#type(String)} attribute.
+ * @return The new element.
+ */
+ public static final SecurityScheme securityScheme(String type) {
+ return securityScheme().type(type);
+ }
+
+ /**
+ * Creates an {@link SecurityScheme} element with the specified {@link SecurityScheme#type(String)} attribute.
+ * @param type The {@link SecurityScheme#type(String)} attribute.
+ * @return The new element.
+ */
+ public static final SecurityScheme securitySchemeStrict(String type) {
+ return securityScheme().strict().type(type);
+ }
+
+ /**
+ * Creates an empty {@link Swagger} element.
+ * @return The new element.
+ */
+ public static final Swagger swagger() {
+ return new Swagger();
+ }
+
+ /**
+ * Creates an {@link Swagger} element with the specified {@link Swagger#info(Info)} attribute.
+ * @param info The {@link Swagger#info(Info)} attribute.
+ * @return The new element.
+ */
+ public static final Swagger swagger(Info info) {
+ return swagger().info(info);
+ }
+
+ /**
+ * Creates an empty {@link Tag} element.
+ * @return The new element.
+ */
+ public static final Tag tag() {
+ return new Tag();
+ }
+
+ /**
+ * Creates an {@link Tag} element with the specified {@link Tag#name(String)} attribute.
+ * @param name The {@link Tag#name(String)} attribute.
+ * @return The new element.
+ */
+ public static final Tag tag(String name) {
+ return tag().name(name);
+ }
+
+ /**
+ * Creates an empty {@link Xml} element.
+ * @return The new element.
+ */
+ public static final Xml xml() {
+ return new Xml();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
new file mode 100644
index 0000000..5b610cf
--- /dev/null
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/SwaggerElement.java
@@ -0,0 +1,40 @@
+// ***************************************************************************************************************************
+// * 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;
+
+/**
+ * Root class for all Swagger beans.
+ */
+public class SwaggerElement {
+
+ private boolean strict;
+
+ /**
+ * Returns <jk>true</jk> if contents should be validated per the Swagger spec.
+ *
+ * @return <jk>true</jk> if contents should be validated per the Swagger spec.
+ */
+ protected boolean isStrict() {
+ return strict;
+ }
+
+ /**
+ * Sets strict mode on this bean.
+ *
+ * @return This object (for method chaining).
+ */
+ protected SwaggerElement strict() {
+ this.strict = true;
+ return this;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Tag.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Tag.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Tag.java
index fe5f979..17b0092 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Tag.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Tag.java
@@ -28,23 +28,14 @@ import org.apache.juneau.annotation.*;
* </p>
*/
@Bean(properties="name,description,externalDocs")
-public class Tag {
+@SuppressWarnings("hiding")
+public class Tag extends SwaggerElement {
private String name;
private String description;
private ExternalDocumentation externalDocs;
/**
- * Convenience method for creating a new Tag object.
- *
- * @param name Required. The name of the tag.
- * @return A new Tag object.
- */
- public static Tag create(String name) {
- return new Tag().setName(name);
- }
-
- /**
* Bean property getter: <property>name</property>.
* <p>
* Required. The name of the tag.
@@ -69,6 +60,16 @@ public class Tag {
}
/**
+ * Synonym for {@link #setName(String)}.
+ *
+ * @param name The new value for the <property>name</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Tag name(String name) {
+ return setName(name);
+ }
+
+ /**
* Bean property getter: <property>description</property>.
* <p>
* A short description for the tag.
@@ -95,6 +96,16 @@ public class Tag {
}
/**
+ * Synonym for {@link #setDescription(String)}.
+ *
+ * @param description The new value for the <property>description</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Tag description(String description) {
+ return setDescription(description);
+ }
+
+ /**
* Bean property getter: <property>externalDocs</property>.
* <p>
* Additional external documentation for this tag.
@@ -117,4 +128,14 @@ public class Tag {
this.externalDocs = externalDocs;
return this;
}
+
+ /**
+ * Synonym for {@link #setExternalDocs(ExternalDocumentation)}.
+ *
+ * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Tag externalDocs(ExternalDocumentation externalDocs) {
+ return setExternalDocs(externalDocs);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Xml.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Xml.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Xml.java
index b81471d..0c2df4f 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Xml.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Xml.java
@@ -20,7 +20,8 @@ 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.
*/
@Bean(properties="name,namespace,prefix,attribute,wrapped")
-public class Xml {
+@SuppressWarnings("hiding")
+public class Xml extends SwaggerElement {
private String name;
private String namespace;
@@ -29,15 +30,6 @@ public class Xml {
private Boolean wrapped;
/**
- * Convenience method for creating a new Xml object.
- *
- * @return A new Xml object.
- */
- public static Xml create() {
- return new Xml();
- }
-
- /**
* Bean property getter: <property>name</property>.
* <p>
* Replaces the name of the element/attribute used for the described schema property.
@@ -68,6 +60,16 @@ public class Xml {
}
/**
+ * Synonym for {@link #setName(String)}.
+ *
+ * @param name The new value for the <property>name</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Xml name(String name) {
+ return setName(name);
+ }
+
+ /**
* Bean property getter: <property>namespace</property>.
* <p>
* The URL of the namespace definition. Value SHOULD be in the form of a URL.
@@ -92,6 +94,16 @@ public class Xml {
}
/**
+ * Synonym for {@link #setNamespace(String)}.
+ *
+ * @param namespace The new value for the <property>namespace</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Xml namespace(String namespace) {
+ return setNamespace(namespace);
+ }
+
+ /**
* Bean property getter: <property>prefix</property>.
* <p>
* The prefix to be used for the name.
@@ -116,6 +128,16 @@ public class Xml {
}
/**
+ * Synonym for {@link #setPrefix(String)}.
+ *
+ * @param prefix The new value for the <property>prefix</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Xml prefix(String prefix) {
+ return setPrefix(prefix);
+ }
+
+ /**
* Bean property getter: <property>attribute</property>.
* <p>
* Declares whether the property definition translates to an attribute instead of an element. Default value is <jk>false</jk>.
@@ -140,6 +162,16 @@ public class Xml {
}
/**
+ * Synonym for {@link #setAttribute(Boolean)}.
+ *
+ * @param attribute The new value for the <property>attribute</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Xml attribute(Boolean attribute) {
+ return setAttribute(attribute);
+ }
+
+ /**
* Bean property getter: <property>wrapped</property>.
* <p>
* MAY be used only for an array definition.
@@ -168,4 +200,14 @@ public class Xml {
this.wrapped = wrapped;
return this;
}
+
+ /**
+ * Synonym for {@link #setWrapped(Boolean)}.
+ *
+ * @param wrapped The new value for the <property>wrapped</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Xml wrapped(Boolean wrapped) {
+ return setWrapped(wrapped);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/package.html
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/package.html b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/package.html
index e0ecfe3..694657f 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/package.html
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/package.html
@@ -54,5 +54,159 @@
}
}
</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>
\ No newline at end of file
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/javadoc/overview.html
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/javadoc/overview.html b/juneau-core/src/main/javadoc/overview.html
index af45a96..3ce43ed 100644
--- a/juneau-core/src/main/javadoc/overview.html
+++ b/juneau-core/src/main/javadoc/overview.html
@@ -1763,7 +1763,136 @@
<a id="DTOs.Swagger"></a>
<h3 class='topic' onclick='toggle(this)'>3.3 - Swagger</h3>
<div class='topic'>
- TODO
+ <p>
+ The Juneau Swagger DTOs are simply beans with fluent-style setters that allow you to quickly construct Swagger
+ documents as Java objects. These object can then be serialized to JSON using one of the existing JSON serializers,
+ or to other languages such as XML or HTML using the other serializers.
+ </p>
+ <p>
+ The {@link org.apache.juneau.dto.swagger.SwaggerBuilder} class is a utility class with predefined static methods
+ that allow you to easily construct DTO instances in a minimal amount of code.
+ </p>
+ <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>
+ <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>
<!-- ======================================================================================================== -->
@@ -5467,9 +5596,15 @@
<li>{@link org.apache.juneau.html.HtmlSerializerContext#HTML_addBeanTypeProperties}
<li>{@link org.apache.juneau.json.JsonSerializerContext#JSON_addBeanTypeProperties}
<li>{@link org.apache.juneau.msgpack.MsgPackSerializerContext#MSGPACK_addBeanTypeProperties}
- <li>{@link org.apache.juneau.uon.UonSerializerContext#UON_addBeanTypeProperties}
+ <li>{@link org.apache.juneau.urlencoding.UonSerializerContext#UON_addBeanTypeProperties}
<li>{@link org.apache.juneau.xml.XmlSerializerContext#XML_addBeanTypeProperties}
- <li>{@link org.apache.juneau.rdf.RdfSerializerContext#RDF_addBeanTypeProperties}
+ <li>{@link org.apache.juneau.jena.RdfSerializerContext#RDF_addBeanTypeProperties}
+ </ul>
+ <li>Improvements to Swagger support.
+ <ul>
+ <li>New {@link org.apache.juneau.dto.swagger.SwaggerBuilder} class.
+ <li>Fluent-style setters added to the Swagger beans.
+ <li>Added Swagger examples <a href="#DTOs.Swagger">here</a> and in the {@link org.apache.juneau.dto.swagger package javadocs}.
</ul>
</ul>
</div>
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java
----------------------------------------------------------------------
diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java
index d09c79d..52a3581 100644
--- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java
+++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServlet.java
@@ -15,6 +15,7 @@ package org.apache.juneau.rest;
import static java.lang.String.*;
import static java.util.logging.Level.*;
import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
import static org.apache.juneau.internal.ArrayUtils.*;
import static org.apache.juneau.internal.ClassUtils.*;
import static org.apache.juneau.rest.RestServlet.ParamType.*;
@@ -816,22 +817,22 @@ public abstract class RestServlet extends HttpServlet {
if (s != null)
return s;
- Info info = Info.create(getTitle(req), getVersion(req))
- .setContact(getContact(req))
- .setLicense(getLicense(req))
- .setDescription(getDescription(req))
- .setTermsOfService(getTermsOfService(req));
-
- s = Swagger.create(info)
- .addConsumes(getSupportedAcceptTypes())
- .addProduces(getSupportedContentTypes())
- .setTags(getTags(req))
- .setExternalDocs(getExternalDocs(req));
+ s = swagger(
+ info(getTitle(req), getVersion(req))
+ .contact(getContact(req))
+ .license(getLicense(req))
+ .description(getDescription(req))
+ .termsOfService(getTermsOfService(req))
+ )
+ .consumes(getSupportedAcceptTypes())
+ .produces(getSupportedContentTypes())
+ .tags(getTags(req))
+ .externalDocs(getExternalDocs(req));
for (MethodMeta sm : javaRestMethods.values()) {
if (sm.isRequestAllowed(req)) {
Operation o = sm.getSwaggerOperation(req);
- s.addPath(
+ s.path(
sm.pathPattern.patternString,
sm.httpMethod.toLowerCase(),
o
@@ -2347,23 +2348,23 @@ public abstract class RestServlet extends HttpServlet {
}
private Operation getSwaggerOperation(RestRequest req) throws ParseException {
- Operation o = Operation.create()
- .setOperationId(method.getName())
- .setDescription(getDescription(req))
- .setTags(getTags(req))
- .setSummary(getSummary(req))
- .setExternalDocs(getExternalDocs(req))
- .setParameters(getParameters(req))
- .setResponses(getResponses(req));
+ Operation o = operation()
+ .operationId(method.getName())
+ .description(getDescription(req))
+ .tags(getTags(req))
+ .summary(getSummary(req))
+ .externalDocs(getExternalDocs(req))
+ .parameters(getParameters(req))
+ .responses(getResponses(req));
if (isDeprecated())
- o.setDeprecated(true);
+ o.deprecated(true);
if (! mParsers.getSupportedMediaTypes().equals(getParsers().getSupportedMediaTypes()))
- o.setConsumes(mParsers.getSupportedMediaTypes());
+ o.consumes(mParsers.getSupportedMediaTypes());
if (! mSerializers.getSupportedMediaTypes().equals(getSerializers().getSupportedMediaTypes()))
- o.setProduces(mSerializers.getSupportedMediaTypes());
+ o.produces(mSerializers.getSupportedMediaTypes());
return o;
}
@@ -2453,28 +2454,28 @@ public abstract class RestServlet extends HttpServlet {
// First parse @RestMethod.parameters() annotation.
for (org.apache.juneau.rest.annotation.Parameter v : parameters) {
String in = vr.resolve(v.in());
- ParameterInfo p = ParameterInfo.createStrict(in, vr.resolve(v.name()));
+ ParameterInfo p = parameterInfo(in, vr.resolve(v.name()));
if (! v.description().isEmpty())
- p.setDescription(vr.resolve(v.description()));
+ p.description(vr.resolve(v.description()));
if (v.required())
- p.setRequired(v.required());
+ p.required(v.required());
if ("body".equals(in)) {
if (! v.schema().isEmpty())
- p.setSchema(jp.parse(vr.resolve(v.schema()), SchemaInfo.class));
+ p.schema(jp.parse(vr.resolve(v.schema()), SchemaInfo.class));
} else {
if (v.allowEmptyValue())
- p.setAllowEmptyValue(v.allowEmptyValue());
+ p.allowEmptyValue(v.allowEmptyValue());
if (! v.collectionFormat().isEmpty())
- p.setCollectionFormat(vr.resolve(v.collectionFormat()));
+ p.collectionFormat(vr.resolve(v.collectionFormat()));
if (! v._default().isEmpty())
- p.setDefault(vr.resolve(v._default()));
+ p._default(vr.resolve(v._default()));
if (! v.format().isEmpty())
- p.setFormat(vr.resolve(v.format()));
+ p.format(vr.resolve(v.format()));
if (! v.items().isEmpty())
- p.setItems(jp.parse(vr.resolve(v.items()), Items.class));
- p.setType(vr.resolve(v.type()));
+ p.items(jp.parse(vr.resolve(v.items()), Items.class));
+ p.type(vr.resolve(v.type()));
}
m.put(p.getIn() + '.' + p.getName(), p);
}
@@ -2498,31 +2499,31 @@ public abstract class RestServlet extends HttpServlet {
String k2 = in + '.' + name;
ParameterInfo p = m.get(k2);
if (p == null) {
- p = ParameterInfo.createStrict(in, name);
+ p = parameterInfoStrict(in, name);
m.put(k2, p);
}
if (field.equals("description"))
- p.setDescription(value);
+ p.description(value);
else if (field.equals("required"))
- p.setRequired(Boolean.valueOf(value));
+ p.required(Boolean.valueOf(value));
if ("body".equals(in)) {
if (field.equals("schema"))
- p.setSchema(jp.parse(value, SchemaInfo.class));
+ p.schema(jp.parse(value, SchemaInfo.class));
} else {
if (field.equals("allowEmptyValue"))
- p.setAllowEmptyValue(Boolean.valueOf(value));
+ p.allowEmptyValue(Boolean.valueOf(value));
else if (field.equals("collectionFormat"))
- p.setCollectionFormat(value);
+ p.collectionFormat(value);
else if (field.equals("default"))
- p.setDefault(value);
+ p._default(value);
else if (field.equals("format"))
- p.setFormat(value);
+ p.format(value);
else if (field.equals("items"))
- p.setItems(jp.parse(value, Items.class));
+ p.items(jp.parse(value, Items.class));
else if (field.equals("type"))
- p.setType(value);
+ p.type(value);
}
} else {
System.err.println("Unknown bundle key '"+key+"'");
@@ -2537,7 +2538,7 @@ public abstract class RestServlet extends HttpServlet {
String k2 = in + '.' + ("body".equals(in) ? null : mp.name);
ParameterInfo p = m.get(k2);
if (p == null) {
- p = ParameterInfo.createStrict(in, mp.name);
+ p = parameterInfoStrict(in, mp.name);
m.put(k2, p);
}
}
@@ -2549,36 +2550,36 @@ public abstract class RestServlet extends HttpServlet {
}
@SuppressWarnings("unchecked")
- private Map<String,ResponseInfo> getResponses(RestRequest req) throws ParseException {
+ private Map<Integer,ResponseInfo> getResponses(RestRequest req) throws ParseException {
Operation o = getSwaggerOperationFromFile(req);
if (o != null && o.getResponses() != null)
return o.getResponses();
VarResolverSession vr = req.getVarResolverSession();
JsonParser jp = JsonParser.DEFAULT;
- Map<String,ResponseInfo> m = new TreeMap<String,ResponseInfo>();
+ Map<Integer,ResponseInfo> m = new TreeMap<Integer,ResponseInfo>();
Map<String,HeaderInfo> m2 = new TreeMap<String,HeaderInfo>();
// First parse @RestMethod.parameters() annotation.
for (Response r : responses) {
- String httpCode = String.valueOf(r.value());
+ int httpCode = r.value();
String description = r.description().isEmpty() ? RestUtils.getHttpResponseText(r.value()) : vr.resolve(r.description());
- ResponseInfo r2 = ResponseInfo.create(description);
+ ResponseInfo r2 = responseInfo(description);
if (r.headers().length > 0) {
for (org.apache.juneau.rest.annotation.Parameter v : r.headers()) {
- HeaderInfo h = HeaderInfo.createStrict(vr.resolve(v.type()));
+ HeaderInfo h = headerInfoStrict(vr.resolve(v.type()));
if (! v.collectionFormat().isEmpty())
- h.setCollectionFormat(vr.resolve(v.collectionFormat()));
+ h.collectionFormat(vr.resolve(v.collectionFormat()));
if (! v._default().isEmpty())
- h.setDefault(vr.resolve(v._default()));
+ h._default(vr.resolve(v._default()));
if (! v.description().isEmpty())
- h.setDescription(vr.resolve(v.description()));
+ h.description(vr.resolve(v.description()));
if (! v.format().isEmpty())
- h.setFormat(vr.resolve(v.format()));
+ h.format(vr.resolve(v.format()));
if (! v.items().isEmpty())
- h.setItems(jp.parse(vr.resolve(v.items()), Items.class));
- r2.addHeader(v.name(), h);
+ h.items(jp.parse(vr.resolve(v.items()), Items.class));
+ r2.header(v.name(), h);
m2.put(httpCode + '.' + v.name(), h);
}
}
@@ -2591,10 +2592,10 @@ public abstract class RestServlet extends HttpServlet {
if (key.length() > prefix.length()) {
String value = vr.resolve(msgs.getString(key));
String[] parts = key.substring(prefix.length() + 1).split("\\.");
- String httpCode = parts[0];
+ int httpCode = Integer.parseInt(parts[0]);
ResponseInfo r2 = m.get(httpCode);
if (r2 == null) {
- r2 = ResponseInfo.create(null);
+ r2 = responseInfo(null);
m.put(httpCode, r2);
}
@@ -2607,29 +2608,29 @@ public abstract class RestServlet extends HttpServlet {
String k2 = httpCode + '.' + headerName;
HeaderInfo h = m2.get(k2);
if (h == null) {
- h = HeaderInfo.createStrict("string");
+ h = headerInfoStrict("string");
m2.put(k2, h);
- r2.addHeader(name, h);
+ r2.header(name, h);
}
if (field.equals("collectionFormat"))
- h.setCollectionFormat(value);
+ h.collectionFormat(value);
else if (field.equals("default"))
- h.setDefault(value);
+ h._default(value);
else if (field.equals("description"))
- h.setDescription(value);
+ h.description(value);
else if (field.equals("format"))
- h.setFormat(value);
+ h.format(value);
else if (field.equals("items"))
- h.setItems(jp.parse(value, Items.class));
+ h.items(jp.parse(value, Items.class));
else if (field.equals("type"))
- h.setType(value);
+ h.type(value);
} else if ("description".equals(name)) {
- r2.setDescription(value);
+ r2.description(value);
} else if ("schema".equals(name)) {
- r2.setSchema(jp.parse(value, SchemaInfo.class));
+ r2.schema(jp.parse(value, SchemaInfo.class));
} else if ("examples".equals(name)) {
- r2.setExamples(jp.parse(value, TreeMap.class));
+ r2.examples(jp.parse(value, TreeMap.class));
} else {
System.err.println("Unknown bundle key '"+key+"'");
}
[2/2] incubator-juneau git commit: Improvements to Swagger support.
Posted by ja...@apache.org.
Improvements to Swagger support.
Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/108b5db3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/108b5db3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/108b5db3
Branch: refs/heads/master
Commit: 108b5db3fd54c8d73c17b3bab6a973f34adb9310
Parents: 9499211
Author: JamesBognar <ja...@apache.org>
Authored: Thu Feb 16 21:35:48 2017 -0500
Committer: JamesBognar <ja...@apache.org>
Committed: Thu Feb 16 21:35:48 2017 -0500
----------------------------------------------------------------------
.../org/apache/juneau/dto/swagger/Contact.java | 42 ++-
.../dto/swagger/ExternalDocumentation.java | 33 +-
.../apache/juneau/dto/swagger/HeaderInfo.java | 234 ++++++++++---
.../org/apache/juneau/dto/swagger/Info.java | 74 +++-
.../org/apache/juneau/dto/swagger/Items.java | 225 +++++++++---
.../org/apache/juneau/dto/swagger/License.java | 33 +-
.../apache/juneau/dto/swagger/Operation.java | 259 ++++++++++++--
.../juneau/dto/swagger/ParameterInfo.java | 297 +++++++++++++---
.../apache/juneau/dto/swagger/ResponseInfo.java | 66 +++-
.../apache/juneau/dto/swagger/SchemaInfo.java | 338 +++++++++++++++++--
.../juneau/dto/swagger/SecurityScheme.java | 116 +++++--
.../org/apache/juneau/dto/swagger/Swagger.java | 235 +++++++++++--
.../juneau/dto/swagger/SwaggerBuilder.java | 292 ++++++++++++++++
.../juneau/dto/swagger/SwaggerElement.java | 40 +++
.../java/org/apache/juneau/dto/swagger/Tag.java | 43 ++-
.../java/org/apache/juneau/dto/swagger/Xml.java | 62 +++-
.../org/apache/juneau/dto/swagger/package.html | 156 ++++++++-
juneau-core/src/main/javadoc/overview.html | 141 +++++++-
.../org/apache/juneau/rest/RestServlet.java | 137 ++++----
19 files changed, 2426 insertions(+), 397 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Contact.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Contact.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Contact.java
index 2996c19..a171166 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Contact.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Contact.java
@@ -27,22 +27,14 @@ import org.apache.juneau.annotation.*;
* </p>
*/
@Bean(properties="name,url,email")
-public class Contact {
+@SuppressWarnings("hiding")
+public class Contact extends SwaggerElement {
private String name;
private String url;
private String email;
/**
- * Convenience method for creating a new Contact object.
- *
- * @return A new Contact object.
- */
- public static Contact create() {
- return new Contact();
- }
-
- /**
* Bean property getter: <property>name</property>.
* <p>
* The identifying name of the contact person/organization.
@@ -67,6 +59,16 @@ public class Contact {
}
/**
+ * Synonym for {@link #setName(String)}.
+ *
+ * @param name The new value for the <property>name</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Contact name(String name) {
+ return setName(name);
+ }
+
+ /**
* Bean property getter: <property>url</property>.
* <p>
* The URL pointing to the contact information. MUST be in the format of a URL.
@@ -91,6 +93,16 @@ public class Contact {
}
/**
+ * Synonym for {@link #setUrl(String)}.
+ *
+ * @param url The new value for the <property>url</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Contact url(String url) {
+ return setName(url);
+ }
+
+ /**
* Bean property getter: <property>email</property>.
* <p>
* The email address of the contact person/organization. MUST be in the format of an email address.
@@ -113,4 +125,14 @@ public class Contact {
this.email = email;
return this;
}
+
+ /**
+ * Synonym for {@link #setEmail(String)}.
+ *
+ * @param email The new value for the <property>email</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Contact email(String email) {
+ return setEmail(email);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java
index 0c03be9..7b9a1e5 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ExternalDocumentation.java
@@ -26,22 +26,13 @@ import org.apache.juneau.annotation.*;
* </p>
*/
@Bean(properties="description,url")
-public class ExternalDocumentation {
+@SuppressWarnings("hiding")
+public class ExternalDocumentation extends SwaggerElement {
private String description;
private String url;
/**
- * Convenience method for creating a new ExternalDocumentation object.
- *
- * @param url Required. The URL for the target documentation. Value MUST be in the format of a URL.
- * @return A new ExternalDocumentation object.
- */
- public static ExternalDocumentation create(String url) {
- return new ExternalDocumentation().setUrl(url);
- }
-
- /**
* Bean property getter: <property>description</property>.
* <p>
* A short description of the target documentation. GFM syntax can be used for rich text representation.
@@ -66,6 +57,16 @@ public class ExternalDocumentation {
}
/**
+ * Synonym for {@link #setDescription(String)}.
+ *
+ * @param description The new value for the <property>description</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ExternalDocumentation description(String description) {
+ return setDescription(description);
+ }
+
+ /**
* Bean property getter: <property>url</property>.
* <p>
* Required. The URL for the target documentation. Value MUST be in the format of a URL.
@@ -88,4 +89,14 @@ public class ExternalDocumentation {
this.url = url;
return this;
}
+
+ /**
+ * Synonym for {@link #setUrl(String)}.
+ *
+ * @param url The new value for the <property>url</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ExternalDocumentation url(String url) {
+ return setUrl(url);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
index 9dad31f..b2d3c44 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/HeaderInfo.java
@@ -30,7 +30,8 @@ import org.apache.juneau.json.*;
* </p>
*/
@Bean(properties="description,type,format,items,collectionFormat,default,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,enum,multipleOf")
-public class HeaderInfo {
+@SuppressWarnings({"hiding", "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"};
@@ -53,33 +54,10 @@ public class HeaderInfo {
private Boolean uniqueItems;
private List<Object> _enum;
private Number multipleOf;
- private boolean strict;
- /**
- * Convenience method for creating a new Header object.
- *
- * @param type 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>.
- * @return A new Header object.
- */
- public static HeaderInfo create(String type) {
- return new HeaderInfo().setType(type);
- }
-
- /**
- * Same as {@link #create(String)} except methods will throw runtime exceptions if you attempt
- * to pass in invalid values per the Swagger spec.
- *
- * @param type 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>.
- * @return A new Header object.
- */
- public static HeaderInfo createStrict(String type) {
- return new HeaderInfo().setStrict().setType(type);
- }
-
- private HeaderInfo setStrict() {
- this.strict = true;
+ @Override /* SwaggerElement */
+ protected HeaderInfo strict() {
+ super.strict();
return this;
}
@@ -108,6 +86,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #description(String)}.
+ *
+ * @param description The new value for the <property>description</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo description(String description) {
+ return setDescription(description);
+ }
+
+ /**
* Bean property getter: <property>type</property>.
* <p>
* Required. The type of the object.
@@ -129,13 +117,23 @@ public class HeaderInfo {
* @return This object (for method chaining).
*/
public HeaderInfo setType(String type) {
- if (strict && ! ArrayUtils.contains(type, VALID_TYPES))
+ if (isStrict() && ! ArrayUtils.contains(type, VALID_TYPES))
throw new RuntimeException("Invalid value passed in to setType(String). Value='"+type+"', valid values=" + JsonSerializer.DEFAULT_LAX.toString(VALID_TYPES));
this.type = type;
return this;
}
/**
+ * Synonym for {@link #setType(String)}.
+ *
+ * @param type The new value for the <property>type</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo type(String type) {
+ return setType(type);
+ }
+
+ /**
* 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.
@@ -160,6 +158,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setFormat(String)}.
+ *
+ * @param format The new value for the <property>format</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo format(String format) {
+ return setFormat(format);
+ }
+
+ /**
* Bean property getter: <property>items</property>.
* <p>
* Required if <code>type</code> is <js>"array"</js>.
@@ -186,6 +194,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setItems(Items)}.
+ *
+ * @param items The new value for the <property>items</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo items(Items items) {
+ return setItems(items);
+ }
+
+ /**
* Bean property getter: <property>collectionFormat</property>.
* <p>
* Determines the format of the array if type array is used.
@@ -225,13 +243,23 @@ public class HeaderInfo {
* @return This object (for method chaining).
*/
public HeaderInfo setCollectionFormat(String collectionFormat) {
- if (strict && ! ArrayUtils.contains(collectionFormat, VALID_COLLECTION_FORMATS))
+ if (isStrict() && ! ArrayUtils.contains(collectionFormat, VALID_COLLECTION_FORMATS))
throw new RuntimeException("Invalid value passed in to setCollectionFormat(String). Value='"+collectionFormat+"', valid values=" + JsonSerializer.DEFAULT_LAX.toString(VALID_COLLECTION_FORMATS));
this.collectionFormat = collectionFormat;
return this;
}
/**
+ * Synonym for {@link #setCollectionFormat(String)}.
+ *
+ * @param collectionFormat The new value for the <property>collectionFormat</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo collectionFormat(String collectionFormat) {
+ return setCollectionFormat(collectionFormat);
+ }
+
+ /**
* Bean property getter: <property>default</property>.
* <p>
* Declares the value of the header that the server will use if none is provided.
@@ -262,6 +290,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setDefault(Object)}.
+ *
+ * @param _default The new value for the <property>_default</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo _default(Object _default) {
+ return setDefault(_default);
+ }
+
+ /**
* 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>.
@@ -286,6 +324,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setMaximum(Number)}.
+ *
+ * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo maximum(Number maximum) {
+ return setMaximum(maximum);
+ }
+
+ /**
* 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>.
@@ -310,6 +358,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setExclusiveMaximum(Boolean)}.
+ *
+ * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo exclusiveMaximum(Boolean exclusiveMaximum) {
+ return setExclusiveMaximum(exclusiveMaximum);
+ }
+
+ /**
* 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>.
@@ -334,6 +392,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setMinimum(Number)}.
+ *
+ * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo minimum(Number minimum) {
+ return setMinimum(minimum);
+ }
+
+ /**
* 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>.
@@ -358,6 +426,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setExclusiveMinimum(Boolean)}.
+ *
+ * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo exclusiveMinimum(Boolean exclusiveMinimum) {
+ return setExclusiveMinimum(exclusiveMinimum);
+ }
+
+ /**
* 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>.
@@ -382,6 +460,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setMaxLength(Integer)}.
+ *
+ * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo maxLength(Integer maxLength) {
+ return setMaxLength(maxLength);
+ }
+
+ /**
* 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>.
@@ -406,6 +494,15 @@ public class HeaderInfo {
}
/**
+ *
+ * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo minLength(Integer minLength) {
+ return setMinLength(minLength);
+ }
+
+ /**
* 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>.
@@ -430,6 +527,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setPattern(String)}.
+ *
+ * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo pattern(String pattern) {
+ return setPattern(pattern);
+ }
+
+ /**
* 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>.
@@ -454,6 +561,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setMaxItems(Integer)}.
+ *
+ * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo maxItems(Integer maxItems) {
+ return setMaxItems(maxItems);
+ }
+
+ /**
* 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>.
@@ -478,6 +595,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setMinItems(Integer)}.
+ *
+ * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo minItems(Integer minItems) {
+ return setMinItems(minItems);
+ }
+
+ /**
* 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>.
@@ -502,6 +629,16 @@ public class HeaderInfo {
}
/**
+ * Synonym for {@link #setUniqueItems(Boolean)}.
+ *
+ * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo uniqueItems(Boolean uniqueItems) {
+ return setUniqueItems(uniqueItems);
+ }
+
+ /**
* 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>.
@@ -531,27 +668,32 @@ public class HeaderInfo {
* 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).
*/
- @SuppressWarnings("hiding")
public HeaderInfo addEnum(Object..._enum) {
- return addEnum(Arrays.asList(_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<Object>();
+ this._enum.add(o);
+ }
+ }
+ }
+ 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>.
+ * Synonym for {@link #addEnum(Object...)}.
*
- * @param _enum The new values to add to the <property>enum</property> property on this bean.
+ * @param _enum The new value for the <property>enum</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
- public HeaderInfo addEnum(Collection<Object> _enum) {
- if (this._enum == null)
- this._enum = new LinkedList<Object>();
- this._enum.addAll(_enum);
- return this;
+ public HeaderInfo _enum(Object..._enum) {
+ return addEnum(_enum);
}
/**
@@ -577,4 +719,14 @@ public class HeaderInfo {
this.multipleOf = multipleOf;
return this;
}
+
+ /**
+ * Synonym for {@link #setMultipleOf(Number)}.
+ *
+ * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public HeaderInfo multipleOf(Number multipleOf) {
+ return setMultipleOf(multipleOf);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Info.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Info.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Info.java
index 4041cc9..1a99ba0 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Info.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Info.java
@@ -37,7 +37,8 @@ import org.apache.juneau.annotation.*;
* </p>
*/
@Bean(properties="title,description,termsOfService,contact,license,version")
-public class Info {
+@SuppressWarnings("hiding")
+public class Info extends SwaggerElement {
private String title;
private String description;
@@ -47,17 +48,6 @@ public class Info {
private String version;
/**
- * Convenience method for creating a new Info object.
- *
- * @param title Required. The title of the application.
- * @param version Required. Provides the version of the application API (not to be confused with the specification version).
- * @return A new Info object.
- */
- public static Info create(String title, String version) {
- return new Info().setTitle(title).setVersion(version);
- }
-
- /**
* Bean property getter: <property>title</property>.
* <p>
* Required. The title of the application.
@@ -82,6 +72,16 @@ public class Info {
}
/**
+ * Synonym for {@link #setTitle(String)}.
+ *
+ * @param title The new value for the <property>title</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Info title(String title) {
+ return setTitle(title);
+ }
+
+ /**
* Bean property getter: <property>description</property>.
* <p>
* A short description of the application. GFM syntax can be used for rich text representation.
@@ -106,6 +106,16 @@ public class Info {
}
/**
+ * Synonym for {@link #setDescription(String)}.
+ *
+ * @param description The new value for the <property>description</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Info description(String description) {
+ return setDescription(description);
+ }
+
+ /**
* Bean property getter: <property>termsOfService</property>.
* <p>
* The Terms of Service for the API.
@@ -130,6 +140,16 @@ public class Info {
}
/**
+ * Synonym for {@link #setTermsOfService(String)}.
+ *
+ * @param termsOfService The new value for the <property>termsOfService</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Info termsOfService(String termsOfService) {
+ return setTermsOfService(termsOfService);
+ }
+
+ /**
* Bean property getter: <property>contact</property>.
* <p>
* The contact information for the exposed API.
@@ -154,6 +174,16 @@ public class Info {
}
/**
+ * Synonym for {@link #setContact(Contact)}.
+ *
+ * @param contact The new value for the <property>contact</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Info contact(Contact contact) {
+ return setContact(contact);
+ }
+
+ /**
* Bean property getter: <property>license</property>.
* <p>
* The license information for the exposed API.
@@ -178,6 +208,16 @@ public class Info {
}
/**
+ * Synonym for {@link #setLicense(License)}.
+ *
+ * @param license The new value for the <property>license</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Info license(License license) {
+ return setLicense(license);
+ }
+
+ /**
* Bean property getter: <property>version</property>.
* <p>
* Required. Provides the version of the application API (not to be confused with the specification version).
@@ -200,4 +240,14 @@ public class Info {
this.version = version;
return this;
}
+
+ /**
+ * Synonym for {@link #setVersion(String)}.
+ *
+ * @param version The new value for the <property>version</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Info version(String version) {
+ return setVersion(version);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Items.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Items.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Items.java
index 91afdaf..3d23dac 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Items.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Items.java
@@ -30,7 +30,8 @@ import org.apache.juneau.json.*;
* </p>
*/
@Bean(properties="type,format,items,collectionFormat,default,maximum,exclusiveMaximum,minimum,exclusiveMinimum,maxLength,minLength,pattern,maxItems,minItems,uniqueItems,enum,multipleOf")
-public class Items {
+@SuppressWarnings({ "hiding", "unchecked" })
+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"};
@@ -52,34 +53,10 @@ public class Items {
private Boolean uniqueItems;
private List<Object> _enum;
private Number multipleOf;
- private boolean strict;
- /**
- * Convenience method for creating a new Items object.
- *
- * @param type 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>.
- * Files and models are not allowed.
- * @return A new Items object.
- */
- public static Items create(String type) {
- return new Items().setType(type);
- }
-
- /**
- * Same as {@link #create(String)} except methods will throw runtime exceptions if you attempt
- * to pass in invalid values per the Swagger spec.
- *
- * @param type Required. The tyoe 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>.
- * @return A new Header object.
- */
- public static Items createStrict(String type) {
- return new Items().setStrict().setType(type);
- }
-
- private Items setStrict() {
- this.strict = true;
+ @Override /* SwaggerElement */
+ protected Items strict() {
+ super.strict();
return this;
}
@@ -105,13 +82,23 @@ public class Items {
* @return This object (for method chaining).
*/
public Items setType(String type) {
- if (strict && ! ArrayUtils.contains(type, VALID_TYPES))
+ if (isStrict() && ! ArrayUtils.contains(type, VALID_TYPES))
throw new RuntimeException("Invalid value passed in to setType(String). Value='"+type+"', valid values=" + JsonSerializer.DEFAULT_LAX.toString(VALID_TYPES));
this.type = type;
return this;
}
/**
+ * Synonym for {@link #setType(String)}.
+ *
+ * @param type The new value for the <property>type</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items type(String type) {
+ return setType(type);
+ }
+
+ /**
* 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.
@@ -136,6 +123,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setFormat(String)}.
+ *
+ * @param format The new value for the <property>format</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items format(String format) {
+ return setFormat(format);
+ }
+
+ /**
* Bean property getter: <property>items</property>.
* <p>
* Required if <code>type</code> is <js>"array"</js>.
@@ -162,6 +159,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setItems(Items)}.
+ *
+ * @param items The new value for the <property>items</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items items(Items items) {
+ return setItems(items);
+ }
+
+ /**
* Bean property getter: <property>collectionFormat</property>.
* <p>
* Determines the format of the array if type array is used.
@@ -201,13 +208,23 @@ public class Items {
* @return This object (for method chaining).
*/
public Items setCollectionFormat(String collectionFormat) {
- if (strict && ! ArrayUtils.contains(collectionFormat, VALID_COLLECTION_FORMATS))
+ if (isStrict() && ! ArrayUtils.contains(collectionFormat, VALID_COLLECTION_FORMATS))
throw new RuntimeException("Invalid value passed in to setCollectionFormat(String). Value='"+collectionFormat+"', valid values=" + JsonSerializer.DEFAULT_LAX.toString(VALID_COLLECTION_FORMATS));
this.collectionFormat = collectionFormat;
return this;
}
/**
+ * Synonym for {@link #setCollectionFormat(String)}.
+ *
+ * @param collectionFormat The new value for the <property>collectionFormat</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items collectionFormat(String collectionFormat) {
+ return setCollectionFormat(collectionFormat);
+ }
+
+ /**
* Bean property getter: <property>default</property>.
* <p>
* Declares the value of the item that the server will use if none is provided.
@@ -238,6 +255,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setDefault(Object)}.
+ *
+ * @param _default The new value for the <property>default</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items _default(Object _default) {
+ return setDefault(_default);
+ }
+
+ /**
* 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>.
@@ -262,6 +289,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setMaximum(Number)}.
+ *
+ * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items maximum(Number maximum) {
+ return setMaximum(maximum);
+ }
+
+ /**
* 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>.
@@ -286,6 +323,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setExclusiveMaximum(Boolean)}.
+ *
+ * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items exclusiveMaximum(Boolean exclusiveMaximum) {
+ return setExclusiveMaximum(exclusiveMaximum);
+ }
+
+ /**
* 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>.
@@ -310,6 +357,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setMinimum(Number)}.
+ *
+ * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items minimum(Number minimum) {
+ return setMinimum(minimum);
+ }
+
+ /**
* 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>.
@@ -334,6 +391,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setExclusiveMinimum(Boolean)}.
+ *
+ * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items exclusiveMinimum(Boolean exclusiveMinimum) {
+ return setExclusiveMinimum(exclusiveMinimum);
+ }
+
+ /**
* 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>.
@@ -358,6 +425,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setMaxLength(Integer)}.
+ *
+ * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items maxLength(Integer maxLength) {
+ return setMaxLength(maxLength);
+ }
+
+ /**
* 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>.
@@ -382,6 +459,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setMinLength(Integer)}.
+ *
+ * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items minLength(Integer minLength) {
+ return setMinLength(minLength);
+ }
+
+ /**
* 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>.
@@ -406,6 +493,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setPattern(String)}.
+ *
+ * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items pattern(String pattern) {
+ return setPattern(pattern);
+ }
+
+ /**
* 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>.
@@ -430,6 +527,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setMaxItems(Integer)}.
+ *
+ * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items maxItems(Integer maxItems) {
+ return setMaxItems(maxItems);
+ }
+
+ /**
* 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>.
@@ -454,6 +561,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setMinItems(Integer)}.
+ *
+ * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items minItems(Integer minItems) {
+ return setMinItems(minItems);
+ }
+
+ /**
* 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>.
@@ -478,6 +595,16 @@ public class Items {
}
/**
+ * Synonym for {@link #setUniqueItems(Boolean)}.
+ *
+ * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items uniqueItems(Boolean uniqueItems) {
+ return setUniqueItems(uniqueItems);
+ }
+
+ /**
* 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>.
@@ -507,27 +634,33 @@ public class Items {
* 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).
*/
- @SuppressWarnings("hiding")
public Items addEnum(Object..._enum) {
- return addEnum(Arrays.asList(_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<Object>();
+ this._enum.add(o);
+ }
+ }
+ }
+ 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>.
+ * 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.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
- public Items addEnum(Collection<Object> _enum) {
- if (this._enum == null)
- this._enum = new LinkedList<Object>();
- this._enum.addAll(_enum);
- return this;
+ public Items _enum(Object..._enum) {
+ return addEnum(_enum);
}
/**
@@ -553,4 +686,14 @@ public class Items {
this.multipleOf = multipleOf;
return this;
}
+
+ /**
+ * Synonym for {@link #setMultipleOf(Number)}.
+ *
+ * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Items multipleOf(Number multipleOf) {
+ return setMultipleOf(multipleOf);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/License.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/License.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/License.java
index fdd8f27..bfe7c8b 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/License.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/License.java
@@ -26,22 +26,13 @@ import org.apache.juneau.annotation.*;
* </p>
*/
@Bean(properties="name,url")
-public class License {
+@SuppressWarnings("hiding")
+public class License extends SwaggerElement {
private String name;
private String url;
/**
- * Convenience method for creating a new License object.
- *
- * @param name Required. The license name used for the API.
- * @return A new License object.
- */
- public static License create(String name) {
- return new License().setName(name);
- }
-
- /**
* Bean property getter: <property>name</property>.
* <p>
* Required. The license name used for the API.
@@ -66,6 +57,16 @@ public class License {
}
/**
+ * Synonym for {@link #setName(String)}.
+ *
+ * @param name The new value for the <property>name</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public License name(String name) {
+ return setName(name);
+ }
+
+ /**
* Bean property getter: <property>url</property>.
* <p>
* A URL to the license used for the API. MUST be in the format of a URL.
@@ -88,4 +89,14 @@ public class License {
this.url = url;
return this;
}
+
+ /**
+ * Synonym for {@link #setUrl(String)}.
+ *
+ * @param url The new value for the <property>url</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public License url(String url) {
+ return setUrl(url);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Operation.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Operation.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Operation.java
index cc0fbe9..9c08cb8 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Operation.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/Operation.java
@@ -79,7 +79,8 @@ import org.apache.juneau.annotation.*;
* </p>
*/
@Bean(properties="operationId,summary,description,tags,externalDocs,consumes,produces,parameters,responses,schemes,deprecated,security")
-public class Operation {
+@SuppressWarnings("hiding")
+public class Operation extends SwaggerElement {
private List<String> tags;
private String summary;
@@ -89,21 +90,12 @@ public class Operation {
private List<MediaType> consumes;
private List<MediaType> produces;
private List<ParameterInfo> parameters;
- private Map<String,ResponseInfo> responses;
+ private Map<Integer,ResponseInfo> responses;
private List<String> schemes;
private Boolean deprecated;
private List<Map<String,List<String>>> security;
/**
- * Convenience method for creating a new Operation object.
- *
- * @return A new Operation object.
- */
- public static Operation create() {
- return new Operation();
- }
-
- /**
* Bean property getter: <property>tags</property>.
* <p>
* A list of tags for API documentation control.
@@ -138,7 +130,6 @@ public class Operation {
* @param tags The values to add for the <property>tags</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Operation addTags(String...tags) {
return addTags(Arrays.asList(tags));
}
@@ -150,17 +141,39 @@ public class Operation {
* 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>.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Operation addTags(Collection<String> tags) {
- if (this.tags == null)
- this.tags = new LinkedList<String>();
- this.tags.addAll(tags);
+ if (tags != null) {
+ if (this.tags == null)
+ this.tags = new LinkedList<String>();
+ this.tags.addAll(tags);
+ }
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)}.
+ *
+ * @param tags The new value for the <property>tags</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Operation tags(Collection<String> tags) {
+ return addTags(tags);
+ }
+
+ /**
* Bean property getter: <property>summary</property>.
* <p>
* A short summary of what the operation does.
@@ -187,6 +200,16 @@ public class Operation {
}
/**
+ * Synonym for {@link #setSummary(String)}.
+ *
+ * @param summary The new value for the <property>summary</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Operation summary(String summary) {
+ return setSummary(summary);
+ }
+
+ /**
* Bean property getter: <property>description</property>.
* <p>
* A verbose explanation of the operation behavior.
@@ -213,6 +236,16 @@ public class Operation {
}
/**
+ * Synonym for {@link #setDescription(String)}.
+ *
+ * @param description The new value for the <property>description</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Operation description(String description) {
+ return setDescription(description);
+ }
+
+ /**
* Bean property getter: <property>externalDocs</property>.
* <p>
* Additional external documentation for this operation.
@@ -237,6 +270,16 @@ public class Operation {
}
/**
+ * Synonym for {@link #setExternalDocs(ExternalDocumentation)}.
+ *
+ * @param externalDocs The new value for the <property>externalDocs</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Operation externalDocs(ExternalDocumentation externalDocs) {
+ return setExternalDocs(externalDocs);
+ }
+
+ /**
* 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.
@@ -263,6 +306,16 @@ public class Operation {
}
/**
+ * Synonym for {@link #setOperationId(String)}.
+ *
+ * @param operationId The new value for the <property>operationId</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Operation operationId(String operationId) {
+ return setOperationId(operationId);
+ }
+
+ /**
* Bean property getter: <property>consumes</property>.
* <p>
* A list of MIME types the operation can consume.
@@ -303,7 +356,6 @@ public class Operation {
* @param consumes The new values to add to the <property>consumes</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Operation addConsumes(MediaType...consumes) {
return addConsumes(Arrays.asList(consumes));
}
@@ -319,15 +371,36 @@ public class Operation {
* @param consumes The new values to add to the <property>consumes</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Operation addConsumes(Collection<MediaType> consumes) {
- if (this.consumes == null)
- this.consumes = new LinkedList<MediaType>();
- this.consumes.addAll(consumes);
+ if (consumes != null) {
+ if (this.consumes == null)
+ this.consumes = new LinkedList<MediaType>();
+ this.consumes.addAll(consumes);
+ }
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);
+ }
+
+ /**
+ * 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.
@@ -368,15 +441,56 @@ public class Operation {
* @param produces The new value for the <property>produces</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Operation addProduces(MediaType...produces) {
- if (this.produces == null)
- this.produces = new LinkedList<MediaType>();
- this.produces.addAll(Arrays.asList(produces));
+ if (produces != null) {
+ if (this.produces == null)
+ this.produces = new LinkedList<MediaType>();
+ this.produces.addAll(Arrays.asList(produces));
+ }
+ return this;
+ }
+
+ /**
+ * Bean property adder: <property>produces</property>.
+ * <p>
+ * A list of MIME types the operation can produces.
+ * 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 values to add to the <property>produces</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Operation addProduces(Collection<MediaType> produces) {
+ if (produces != null) {
+ if (this.produces == null)
+ this.produces = new LinkedList<MediaType>();
+ this.produces.addAll(produces);
+ }
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);
+ }
+
+ /**
* Bean property getter: <property>parameters</property>.
* <p>
* A list of parameters that are applicable for this operation.
@@ -420,24 +534,44 @@ public class Operation {
* 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 parameter The new value to add to the <property>parameters</property> property on this bean.
+ * @param parameters The new value to add to the <property>parameters</property> property on this bean.
* @return This object (for method chaining).
*/
- public Operation addParameter(ParameterInfo parameter) {
- if (parameters == null)
- parameters = new LinkedList<ParameterInfo>();
- parameters.add(parameter);
+ public Operation addParameters(ParameterInfo...parameters) {
+ if (this.parameters == null)
+ this.parameters = new LinkedList<ParameterInfo>();
+ 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)}.
+ *
+ * @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(List<ParameterInfo> parameters) {
+ return setParameters(parameters);
+ }
+
+ /**
* Bean property getter: <property>responses</property>.
* <p>
* Required. 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.
*/
- public Map<String,ResponseInfo> getResponses() {
+ public Map<Integer,ResponseInfo> getResponses() {
return responses;
}
@@ -449,7 +583,7 @@ public class Operation {
* @param responses The new value for the <property>responses</property> property on this bean.
* @return This object (for method chaining).
*/
- public Operation setResponses(Map<String,ResponseInfo> responses) {
+ public Operation setResponses(Map<Integer,ResponseInfo> responses) {
this.responses = responses;
return this;
}
@@ -463,14 +597,35 @@ public class Operation {
* @param response The response description.
* @return This object (for method chaining).
*/
- public Operation addResponse(String statusCode, ResponseInfo response) {
+ public Operation addResponse(Integer statusCode, ResponseInfo response) {
if (responses == null)
- responses = new TreeMap<String,ResponseInfo>();
+ responses = new TreeMap<Integer,ResponseInfo>();
responses.put(statusCode, response);
return this;
}
/**
+ * Synonym for {@link #addResponse(Integer,ResponseInfo)}.
+ *
+ * @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);
+ }
+
+ /**
+ * Synonym for {@link #setResponses(Map)}.
+ *
+ * @param responses The new value for the <property>responses</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Operation responses(Map<Integer,ResponseInfo> responses) {
+ return setResponses(responses);
+ }
+
+ /**
* Bean property getter: <property>schemes</property>.
* <p>
* The transfer protocol for the operation.
@@ -508,7 +663,6 @@ public class Operation {
* @param schemes The new values to add to the <property>schemes</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Operation addSchemes(String...schemes) {
return addSchemes(Arrays.asList(schemes));
}
@@ -523,7 +677,6 @@ public class Operation {
* @param schemes The new values to add to the <property>schemes</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Operation addSchemes(Collection<String> schemes) {
if (this.schemes == null)
this.schemes = new LinkedList<String>();
@@ -532,6 +685,16 @@ public class Operation {
}
/**
+ * Synonym for {@link #addSchemes(String...)}.
+ *
+ * @param schemes The new values to add to the <property>schemes</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Operation schemes(String...schemes) {
+ return addSchemes(schemes);
+ }
+
+ /**
* Bean property getter: <property>deprecated</property>.
* <p>
* Declares this operation to be deprecated.
@@ -560,6 +723,16 @@ public class Operation {
}
/**
+ * Synonym for {@link #setDeprecated(Boolean)}.
+ *
+ * @param deprecated The new value for the <property>deprecated</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public Operation deprecated(Boolean deprecated) {
+ return setDeprecated(deprecated);
+ }
+
+ /**
* Bean property getter: <property>security</property>.
* <p>
* A declaration of which security schemes are applied for this operation.
@@ -600,11 +773,23 @@ public class Operation {
* @param security The new value to add to the <property>security</property> property on this bean.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
public Operation addSecurity(Map<String,List<String>> security) {
if (this.security == null)
this.security = new LinkedList<Map<String,List<String>>>();
this.security.add(security);
return this;
}
+
+ /**
+ * Synonym for {@link #addSecurity(Map)}.
+ *
+ * @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).
+ * @return This object (for method chaining).
+ */
+ public Operation security(String scheme, String...alternatives) {
+ Map<String,List<String>> m = new LinkedHashMap<String,List<String>>();
+ m.put(scheme, Arrays.asList(alternatives));
+ return addSecurity(m);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
index 78f6551..3e5c5f7 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ParameterInfo.java
@@ -51,7 +51,8 @@ import org.apache.juneau.json.*;
* </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")
-public class ParameterInfo {
+@SuppressWarnings("hiding")
+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"};
@@ -80,43 +81,10 @@ public class ParameterInfo {
private Boolean uniqueItems;
private List<Object> _enum;
private Number multipleOf;
- private boolean strict;
- /**
- * Convenience method for creating a new Parameter object.
- *
- * @param in Required. The location of the parameter.
- * Possible values are <js>"query"</js>, <js>"header"</js>, <js>"path"</js>, <js>"formData"</js> or <js>"body"</js>.
- * @param name Required. The name of the parameter.
- * 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.
- * @return A new Parameter object.
- */
- public static ParameterInfo create(String in, String name) {
- return new ParameterInfo().setIn(in).setName(name);
- }
-
- /**
- * Same as {@link #create(String, String)} except methods will throw runtime exceptions if you attempt
- * to pass in invalid values per the Swagger spec.
- *
- * @param in Required. The location of the parameter.
- * Possible values are <js>"query"</js>, <js>"header"</js>, <js>"path"</js>, <js>"formData"</js> or <js>"body"</js>.
- * @param name Required. The name of the parameter.
- * 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.
- * @return A new Parameter object.
- */
- public static ParameterInfo createStrict(String in, String name) {
- return new ParameterInfo().setStrict().setIn(in).setName(name);
- }
-
- private ParameterInfo setStrict() {
- this.strict = true;
+ @Override /* SwaggerElement */
+ protected ParameterInfo strict() {
+ super.strict();
return this;
}
@@ -154,6 +122,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setName(String)}.
+ *
+ * @param name The new value for the <property>name</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo name(String name) {
+ return setName(name);
+ }
+
+ /**
* Bean property getter: <property>in</property>.
* <p>
* Required. The location of the parameter.
@@ -175,7 +153,7 @@ public class ParameterInfo {
* @return This object (for method chaining).
*/
public ParameterInfo setIn(String in) {
- if (strict && ! ArrayUtils.contains(in, VALID_IN))
+ if (isStrict() && ! ArrayUtils.contains(in, VALID_IN))
throw new RuntimeException("Invalid value passed in to setIn(String). Value='"+in+"', valid values=" + JsonSerializer.DEFAULT_LAX.toString(VALID_IN));
this.in = in;
if ("path".equals(in))
@@ -184,6 +162,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setIn(String)}.
+ *
+ * @param in The new value for the <property>in</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo in(String in) {
+ return setIn(in);
+ }
+
+ /**
* Bean property getter: <property>description</property>.
* <p>
* A brief description of the parameter.
@@ -212,6 +200,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setDescription(String)}.
+ *
+ * @param description The new value for the <property>description</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo description(String description) {
+ return setDescription(description);
+ }
+
+ /**
* Bean property getter: <property>required</property>.
* <p>
* Determines whether this parameter is mandatory.
@@ -240,6 +238,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setRequired(Boolean)}.
+ *
+ * @param required The new value for the <property>required</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo required(Boolean required) {
+ return setRequired(required);
+ }
+
+ /**
* Bean property getter: <property>schema</property>.
* <p>
* Required. The schema defining the type used for the body parameter.
@@ -264,6 +272,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setSchema(SchemaInfo)}.
+ *
+ * @param schema The new value for the <property>schema</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo schema(SchemaInfo schema) {
+ return setSchema(schema);
+ }
+
+ /**
* Bean property getter: <property>type</property>.
* <p>
* Required. The type of the parameter.
@@ -289,13 +307,23 @@ public class ParameterInfo {
* @return This object (for method chaining).
*/
public ParameterInfo setType(String type) {
- if (strict && ! ArrayUtils.contains(type, VALID_TYPES))
+ if (isStrict() && ! ArrayUtils.contains(type, VALID_TYPES))
throw new RuntimeException("Invalid value passed in to setType(String). Value='"+type+"', valid values=" + JsonSerializer.DEFAULT_LAX.toString(VALID_TYPES));
this.type = type;
return this;
}
/**
+ * Synonym for {@link #setType(String)}.
+ *
+ * @param type The new value for the <property>type</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo type(String type) {
+ return setType(type);
+ }
+
+ /**
* Bean property getter: <property>format</property>.
* <p>
* The extending format for the previously mentioned type.
@@ -322,6 +350,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setFormat(String)}.
+ *
+ * @param format The new value for the <property>format</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo format(String format) {
+ return setFormat(format);
+ }
+
+ /**
* Bean property getter: <property>allowEmptyValue</property>.
* <p>
* Sets the ability to pass empty-valued parameters.
@@ -350,6 +388,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setAllowEmptyValue(Boolean)}.
+ *
+ * @param allowEmptyValue The new value for the <property>allowEmptyValue</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo allowEmptyValue(Boolean allowEmptyValue) {
+ return setAllowEmptyValue(allowEmptyValue);
+ }
+
+ /**
* Bean property getter: <property>items</property>.
* <p>
* Required if <code>type</code> is <js>"array"</js>.
@@ -376,6 +424,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setItems(Items)}.
+ *
+ * @param items The new value for the <property>items</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo items(Items items) {
+ return setItems(items);
+ }
+
+ /**
* Bean property getter: <property>collectionFormat</property>.
* <p>
* Determines the format of the array if type array is used.
@@ -419,13 +477,23 @@ public class ParameterInfo {
* @return This object (for method chaining).
*/
public ParameterInfo setCollectionFormat(String collectionFormat) {
- if (strict && ! ArrayUtils.contains(collectionFormat, VALID_COLLECTION_FORMATS))
+ if (isStrict() && ! ArrayUtils.contains(collectionFormat, VALID_COLLECTION_FORMATS))
throw new RuntimeException("Invalid value passed in to setCollectionFormat(String). Value='"+collectionFormat+"', valid values=" + JsonSerializer.DEFAULT_LAX.toString(VALID_COLLECTION_FORMATS));
this.collectionFormat = collectionFormat;
return this;
}
/**
+ * Synonym for {@link #setCollectionFormat(String)}.
+ *
+ * @param collectionFormat The new value for the <property>collectionFormat</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo collectionFormat(String collectionFormat) {
+ return setCollectionFormat(collectionFormat);
+ }
+
+ /**
* Bean property getter: <property>default</property>.
* <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.
@@ -456,6 +524,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setDefault(Object)}.
+ *
+ * @param _default The new value for the <property>default</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo _default(Object _default) {
+ return setDefault(_default);
+ }
+
+ /**
* 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>.
@@ -480,6 +558,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setMaximum(Number)}.
+ *
+ * @param maximum The new value for the <property>maximum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo maximum(Number maximum) {
+ return setMaximum(maximum);
+ }
+
+ /**
* 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>.
@@ -504,6 +592,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setExclusiveMaximum(Boolean)}.
+ *
+ * @param exclusiveMaximum The new value for the <property>exclusiveMaximum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo exclusiveMaximum(Boolean exclusiveMaximum) {
+ return setExclusiveMaximum(exclusiveMaximum);
+ }
+
+ /**
* 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>.
@@ -528,6 +626,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setMinimum(Number)}.
+ *
+ * @param minimum The new value for the <property>minimum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo minimum(Number minimum) {
+ return setMinimum(minimum);
+ }
+
+ /**
* 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>.
@@ -552,6 +660,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setExclusiveMinimum(Boolean)}.
+ *
+ * @param exclusiveMinimum The new value for the <property>exclusiveMinimum</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo exclusiveMinimum(Boolean exclusiveMinimum) {
+ return setExclusiveMinimum(exclusiveMinimum);
+ }
+
+ /**
* 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>.
@@ -576,6 +694,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setMaxLength(Integer)}.
+ *
+ * @param maxLength The new value for the <property>maxLength</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo maxLength(Integer maxLength) {
+ return setMaxLength(maxLength);
+ }
+
+ /**
* 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>.
@@ -600,6 +728,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setMinLength(Integer)}.
+ *
+ * @param minLength The new value for the <property>minLength</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo minLength(Integer minLength) {
+ return setMinLength(minLength);
+ }
+
+ /**
* 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>.
@@ -624,6 +762,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setPattern(String)}.
+ *
+ * @param pattern The new value for the <property>pattern</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo pattern(String pattern) {
+ return setPattern(pattern);
+ }
+
+ /**
* 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>.
@@ -648,6 +796,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setMaxItems(Integer)}.
+ *
+ * @param maxItems The new value for the <property>maxItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo maxItems(Integer maxItems) {
+ return setMaxItems(maxItems);
+ }
+
+ /**
* 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>.
@@ -672,6 +830,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setMinItems(Integer)}.
+ *
+ * @param minItems The new value for the <property>minItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo minItems(Integer minItems) {
+ return setMinItems(minItems);
+ }
+
+ /**
* 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>.
@@ -696,6 +864,16 @@ public class ParameterInfo {
}
/**
+ * Synonym for {@link #setUniqueItems(Boolean)}.
+ *
+ * @param uniqueItems The new value for the <property>uniqueItems</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo uniqueItems(Boolean uniqueItems) {
+ return setUniqueItems(uniqueItems);
+ }
+
+ /**
* 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>.
@@ -725,27 +903,34 @@ public class ParameterInfo {
* 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).
*/
- @SuppressWarnings("hiding")
+ @SuppressWarnings("unchecked")
public ParameterInfo addEnum(Object..._enum) {
- return addEnum(Arrays.asList(_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<Object>();
+ this._enum.add(o);
+ }
+ }
+ }
+ 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>.
+ * 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.
* @return This object (for method chaining).
*/
- @SuppressWarnings("hiding")
- public ParameterInfo addEnum(Collection<Object> _enum) {
- if (this._enum == null)
- this._enum = new LinkedList<Object>();
- this._enum.addAll(_enum);
- return this;
+ public ParameterInfo _enum(Object..._enum) {
+ return addEnum(_enum);
}
/**
@@ -771,4 +956,14 @@ public class ParameterInfo {
this.multipleOf = multipleOf;
return this;
}
+
+ /**
+ * Synonym for {@link #setMultipleOf(Number)}.
+ *
+ * @param multipleOf The new value for the <property>multipleOf</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ParameterInfo multipleOf(Number multipleOf) {
+ return setMultipleOf(multipleOf);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/108b5db3/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
----------------------------------------------------------------------
diff --git a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
index a95081e..d716915 100644
--- a/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
+++ b/juneau-core/src/main/java/org/apache/juneau/dto/swagger/ResponseInfo.java
@@ -33,7 +33,8 @@ import org.apache.juneau.annotation.*;
* </p>
*/
@Bean(properties="description,schema,headers,examples")
-public class ResponseInfo {
+@SuppressWarnings("hiding")
+public class ResponseInfo extends SwaggerElement {
private String description;
private SchemaInfo schema;
@@ -41,17 +42,6 @@ public class ResponseInfo {
private Map<String,Object> examples;
/**
- * Convenience method for creating a new Response object.
- *
- * @param description A short description of the response.
- * <a class="doclink" href="https://help.github.com/articles/github-flavored-markdown">GFM syntax</a> can be used for rich text representation.
- * @return A new Header object.
- */
- public static ResponseInfo create(String description) {
- return new ResponseInfo().setDescription(description);
- }
-
- /**
* Bean property getter: <property>description</property>.
* <p>
* Required. A short description of the response.
@@ -78,6 +68,16 @@ public class ResponseInfo {
}
/**
+ * Synonym for {@link #setDescription(String)}.
+ *
+ * @param description The new value for the <property>description</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ResponseInfo description(String description) {
+ return setDescription(description);
+ }
+
+ /**
* Bean property getter: <property>schema</property>.
* <p>
* A definition of the response structure.
@@ -110,6 +110,16 @@ public class ResponseInfo {
}
/**
+ * Synonym for {@link #setSchema(SchemaInfo)}.
+ *
+ * @param schema The new value for the <property>schema</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ResponseInfo schema(SchemaInfo schema) {
+ return setSchema(schema);
+ }
+
+ /**
* Bean property getter: <property>headers</property>.
* <p>
* A list of headers that are sent with the response.
@@ -150,6 +160,17 @@ public class ResponseInfo {
}
/**
+ * Synonym for {@link #addHeader(String,HeaderInfo)}.
+ *
+ * @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);
+ }
+
+ /**
* Bean property getter: <property>examples</property>.
* <p>
* An example of the response message.
@@ -190,4 +211,25 @@ public class ResponseInfo {
examples.put(mimeType, example);
return this;
}
+
+ /**
+ * Synonym for {@link #addExample(String,Object)}.
+ *
+ * @param mimeType The mimeType of the example.
+ * @param example The example output.
+ * @return This object (for method chaining).
+ */
+ public ResponseInfo example(String mimeType, Object example) {
+ return addExample(mimeType, example);
+ }
+
+ /**
+ * Synonym for {@link #setExamples(Map)}.
+ *
+ * @param examples The new value for the <property>examples</property> property on this bean.
+ * @return This object (for method chaining).
+ */
+ public ResponseInfo examples(Map<String,Object> examples) {
+ return setExamples(examples);
+ }
}