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>"[email protected]"</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>"[email protected]"</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>"[email protected]"</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>"[email protected]"</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+"'"); }
