Skip to content

Commit 7f35b87

Browse files
committed
Merge branch 'issues/91' of git://github.com/RobBlairInq/swagger-codegen into RobBlairInq-issues/91
2 parents b5d2ed0 + 90c14fd commit 7f35b87

File tree

7 files changed

+36
-1
lines changed

7 files changed

+36
-1
lines changed

samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.sun.jersey.api.client.filter.LoggingFilter;
1313
import com.sun.jersey.api.client.WebResource.Builder;
1414

15+
import javax.ws.rs.core.Response.Status.Family;
1516
import javax.ws.rs.core.MediaType;
1617

1718
import java.util.Map;
@@ -123,7 +124,7 @@ else if ("DELETE".equals(method)) {
123124
else {
124125
throw new ApiException(500, "unknown method type " + method);
125126
}
126-
if(response.getClientResponseStatus() == ClientResponse.Status.OK) {
127+
if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
127128
return (String) response.getEntity(String.class);
128129
}
129130
else {

samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Order {
1010
private Integer quantity = null;
1111
/* Status of the order */
1212
private String status = null;
13+
//public enum statusEnum { placed, approved, delivered, };
1314
/* Date shipped, only if it has been */
1415
private Date shipDate = null;
1516
public Long getId() {

samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class Pet {
1616
private List<Tag> tags = new ArrayList<Tag>();
1717
/* pet status in the store */
1818
private String status = null;
19+
//public enum statusEnum { available, pending, sold, };
1920
public Long getId() {
2021
return id;
2122
}

samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/User.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class User {
1717
private String phone = null;
1818
/* User Status */
1919
private Integer userStatus = null;
20+
//public enum userStatusEnum { 1-registered, 2-active, 3-closed, };
2021
public Long getId() {
2122
return id;
2223
}

src/main/resources/Java/model.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public class {{classname}} {
1010
{{#description}}/* {{{description}}} */
1111
{{/description}}
1212
private {{{datatype}}} {{name}} = {{{defaultValue}}};
13+
{{#allowableValues}}{{#min}} // range from {{min}} to {{max}}
14+
{{/min}}
15+
//{{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };
16+
{{/min}}
17+
{{/allowableValues}}
18+
1319
{{/vars}}
1420

1521
{{#vars}}

src/main/scala/com/wordnik/swagger/codegen/Codegen.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ class Codegen(config: CodegenConfig) {
188188
(srcName, engine -> template)
189189
}
190190

191+
def rawAllowableValuesToString(v: AllowableValues) = {
192+
v match {
193+
case av: AllowableListValues => {
194+
av
195+
}
196+
case av: AllowableRangeValues => {
197+
av
198+
}
199+
case _ => None
200+
}
201+
}
202+
203+
191204
def allowableValuesToString(v: AllowableValues) = {
192205
v match {
193206
case av: AllowableListValues => {
@@ -306,6 +319,11 @@ class Codegen(config: CodegenConfig) {
306319
case _ => requiredParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
307320
}
308321

322+
headerParams.size match {
323+
case 0 =>
324+
case _ => headerParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
325+
}
326+
309327
queryParams.size match {
310328
case 0 =>
311329
case _ => queryParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
@@ -466,6 +484,7 @@ class Codegen(config: CodegenConfig) {
466484
"defaultValue" -> config.toDeclaration(propertyDocSchema)._2,
467485
"description" -> propertyDocSchema.description,
468486
"notes" -> propertyDocSchema.description,
487+
"allowableValues" -> rawAllowableValuesToString(propertyDocSchema.allowableValues),
469488
(if(propertyDocSchema.required) "required" else "isNotRequired") -> "true",
470489
"getter" -> config.toGetter(prop._1, config.toDeclaration(propertyDocSchema)._1),
471490
"setter" -> config.toSetter(prop._1, config.toDeclaration(propertyDocSchema)._1),

src/main/scala/com/wordnik/swagger/model/SwaggerModelSerializer.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,16 @@ object SwaggerSerializers {
347347
else {
348348
val min = (json \ "min") match {
349349
case e: JObject => e.extract[String]
350+
case e: JString => e.s
351+
case e: JInt => e.num.toString
352+
case e: JDouble => e.num.toString
350353
case _ => ""
351354
}
352355
val max = (json \ "max") match {
353356
case e: JObject => e.extract[String]
357+
case e: JString => e.s
358+
case e: JInt => e.num.toString
359+
case e: JDouble => e.num.toString
354360
case _ => ""
355361
}
356362
if(min != "" && max != "")

0 commit comments

Comments
 (0)