Merge branch 'issues/91' of git://github.com/RobBlairInq/swagger-codegen into RobBlairInq-issues/91

This commit is contained in:
Tony Tam 2013-11-28 10:56:36 -10:00
commit 7f35b875a4
7 changed files with 36 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.api.client.WebResource.Builder;
import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.core.MediaType;
import java.util.Map;
@ -123,7 +124,7 @@ public class ApiInvoker {
else {
throw new ApiException(500, "unknown method type " + method);
}
if(response.getClientResponseStatus() == ClientResponse.Status.OK) {
if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
return (String) response.getEntity(String.class);
}
else {

View File

@ -10,6 +10,7 @@ public class Order {
private Integer quantity = null;
/* Status of the order */
private String status = null;
//public enum statusEnum { placed, approved, delivered, };
/* Date shipped, only if it has been */
private Date shipDate = null;
public Long getId() {

View File

@ -16,6 +16,7 @@ public class Pet {
private List<Tag> tags = new ArrayList<Tag>();
/* pet status in the store */
private String status = null;
//public enum statusEnum { available, pending, sold, };
public Long getId() {
return id;
}

View File

@ -17,6 +17,7 @@ public class User {
private String phone = null;
/* User Status */
private Integer userStatus = null;
//public enum userStatusEnum { 1-registered, 2-active, 3-closed, };
public Long getId() {
return id;
}

View File

@ -10,6 +10,12 @@ public class {{classname}} {
{{#description}}/* {{{description}}} */
{{/description}}
private {{{datatype}}} {{name}} = {{{defaultValue}}};
{{#allowableValues}}{{#min}} // range from {{min}} to {{max}}
{{/min}}
//{{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };
{{/min}}
{{/allowableValues}}
{{/vars}}
{{#vars}}

View File

@ -188,6 +188,19 @@ class Codegen(config: CodegenConfig) {
(srcName, engine -> template)
}
def rawAllowableValuesToString(v: AllowableValues) = {
v match {
case av: AllowableListValues => {
av
}
case av: AllowableRangeValues => {
av
}
case _ => None
}
}
def allowableValuesToString(v: AllowableValues) = {
v match {
case av: AllowableListValues => {
@ -306,6 +319,11 @@ class Codegen(config: CodegenConfig) {
case _ => requiredParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
}
headerParams.size match {
case 0 =>
case _ => headerParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
}
queryParams.size match {
case 0 =>
case _ => queryParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
@ -466,6 +484,7 @@ class Codegen(config: CodegenConfig) {
"defaultValue" -> config.toDeclaration(propertyDocSchema)._2,
"description" -> propertyDocSchema.description,
"notes" -> propertyDocSchema.description,
"allowableValues" -> rawAllowableValuesToString(propertyDocSchema.allowableValues),
(if(propertyDocSchema.required) "required" else "isNotRequired") -> "true",
"getter" -> config.toGetter(prop._1, config.toDeclaration(propertyDocSchema)._1),
"setter" -> config.toSetter(prop._1, config.toDeclaration(propertyDocSchema)._1),

View File

@ -347,10 +347,16 @@ object SwaggerSerializers {
else {
val min = (json \ "min") match {
case e: JObject => e.extract[String]
case e: JString => e.s
case e: JInt => e.num.toString
case e: JDouble => e.num.toString
case _ => ""
}
val max = (json \ "max") match {
case e: JObject => e.extract[String]
case e: JString => e.s
case e: JInt => e.num.toString
case e: JDouble => e.num.toString
case _ => ""
}
if(min != "" && max != "")