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 <[email protected]> Authored: Thu Feb 16 21:35:48 2017 -0500 Committer: JamesBognar <[email protected]> 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); + } }
