From fe92889b1069ab090acfbd00d8fb513e5c5f1f07 Mon Sep 17 00:00:00 2001 From: russellb337 Date: Mon, 23 Mar 2015 17:01:35 -0700 Subject: [PATCH 1/4] merge latest from develop_2.0 to to fork --- .../client/petstore/php/models/Category.php | 60 ------------- samples/client/petstore/php/models/Order.php | 79 ----------------- samples/client/petstore/php/models/Pet.php | 2 +- samples/client/petstore/php/models/Tag.php | 60 ------------- samples/client/petstore/php/models/pet.php | 79 ----------------- samples/client/petstore/php/models/user.php | 87 ------------------- 6 files changed, 1 insertion(+), 366 deletions(-) delete mode 100644 samples/client/petstore/php/models/Category.php delete mode 100644 samples/client/petstore/php/models/Order.php delete mode 100644 samples/client/petstore/php/models/Tag.php delete mode 100644 samples/client/petstore/php/models/pet.php delete mode 100644 samples/client/petstore/php/models/user.php diff --git a/samples/client/petstore/php/models/Category.php b/samples/client/petstore/php/models/Category.php deleted file mode 100644 index 98e7ba24800..00000000000 --- a/samples/client/petstore/php/models/Category.php +++ /dev/null @@ -1,60 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/models/Order.php b/samples/client/petstore/php/models/Order.php deleted file mode 100644 index 2770e8bbbdf..00000000000 --- a/samples/client/petstore/php/models/Order.php +++ /dev/null @@ -1,79 +0,0 @@ - 'int', - 'pet_id' => 'int', - 'quantity' => 'int', - 'ship_date' => 'DateTime', - 'status' => 'string', - 'complete' => 'boolean' - ); - - static $attributeMap = array( - 'id' => 'id', - 'pet_id' => 'petId', - 'quantity' => 'quantity', - 'ship_date' => 'shipDate', - 'status' => 'status', - 'complete' => 'complete' - ); - - - public $id; /* int */ - public $pet_id; /* int */ - public $quantity; /* int */ - public $ship_date; /* DateTime */ - /** - * Order Status - */ - public $status; /* string */ - public $complete; /* boolean */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->pet_id = $data["pet_id"]; - $this->quantity = $data["quantity"]; - $this->ship_date = $data["ship_date"]; - $this->status = $data["status"]; - $this->complete = $data["complete"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/models/Pet.php b/samples/client/petstore/php/models/Pet.php index eee7fa3784c..e980d858a2f 100644 --- a/samples/client/petstore/php/models/Pet.php +++ b/samples/client/petstore/php/models/Pet.php @@ -22,7 +22,7 @@ * */ -class Pet implements ArrayAccess { +class pet implements ArrayAccess { static $swaggerTypes = array( 'id' => 'int', 'category' => 'Category', diff --git a/samples/client/petstore/php/models/Tag.php b/samples/client/petstore/php/models/Tag.php deleted file mode 100644 index f8efc998df6..00000000000 --- a/samples/client/petstore/php/models/Tag.php +++ /dev/null @@ -1,60 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/models/pet.php b/samples/client/petstore/php/models/pet.php deleted file mode 100644 index e980d858a2f..00000000000 --- a/samples/client/petstore/php/models/pet.php +++ /dev/null @@ -1,79 +0,0 @@ - 'int', - 'category' => 'Category', - 'name' => 'string', - 'photo_urls' => 'array[string]', - 'tags' => 'array[Tag]', - 'status' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'category' => 'category', - 'name' => 'name', - 'photo_urls' => 'photoUrls', - 'tags' => 'tags', - 'status' => 'status' - ); - - - public $id; /* int */ - public $category; /* Category */ - public $name; /* string */ - public $photo_urls; /* array[string] */ - public $tags; /* array[Tag] */ - /** - * pet status in the store - */ - public $status; /* string */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->category = $data["category"]; - $this->name = $data["name"]; - $this->photo_urls = $data["photo_urls"]; - $this->tags = $data["tags"]; - $this->status = $data["status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/models/user.php b/samples/client/petstore/php/models/user.php deleted file mode 100644 index 1ae88e5e2aa..00000000000 --- a/samples/client/petstore/php/models/user.php +++ /dev/null @@ -1,87 +0,0 @@ - 'int', - 'username' => 'string', - 'first_name' => 'string', - 'last_name' => 'string', - 'email' => 'string', - 'password' => 'string', - 'phone' => 'string', - 'user_status' => 'int' - ); - - static $attributeMap = array( - 'id' => 'id', - 'username' => 'username', - 'first_name' => 'firstName', - 'last_name' => 'lastName', - 'email' => 'email', - 'password' => 'password', - 'phone' => 'phone', - 'user_status' => 'userStatus' - ); - - - public $id; /* int */ - public $username; /* string */ - public $first_name; /* string */ - public $last_name; /* string */ - public $email; /* string */ - public $password; /* string */ - public $phone; /* string */ - /** - * User Status - */ - public $user_status; /* int */ - - public function __construct(array $data) { - $this->id = $data["id"]; - $this->username = $data["username"]; - $this->first_name = $data["first_name"]; - $this->last_name = $data["last_name"]; - $this->email = $data["email"]; - $this->password = $data["password"]; - $this->phone = $data["phone"]; - $this->user_status = $data["user_status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} From 970facaa8ae79e15cee4bd81020ff7ee1fc473c3 Mon Sep 17 00:00:00 2001 From: russellb337 Date: Mon, 23 Mar 2015 17:01:49 -0700 Subject: [PATCH 2/4] merge latest from develop_2.0 to fork --- samples/client/petstore/php/models/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/client/petstore/php/models/User.php b/samples/client/petstore/php/models/User.php index d6b520eba51..1ae88e5e2aa 100644 --- a/samples/client/petstore/php/models/User.php +++ b/samples/client/petstore/php/models/User.php @@ -22,7 +22,7 @@ * */ -class User implements ArrayAccess { +class user implements ArrayAccess { static $swaggerTypes = array( 'id' => 'int', 'username' => 'string', From 2edfb96c36e769e22057bf56f5e42b0dd842077c Mon Sep 17 00:00:00 2001 From: russellb337 Date: Thu, 7 May 2015 12:02:25 -0700 Subject: [PATCH 3/4] swagger codegen should honor global mime types --- .../swagger/codegen/DefaultCodegen.java | 10 +++++--- .../swagger/codegen/DefaultGenerator.java | 25 +++++++++++++++++++ .../src/main/resources/JavaJaxRS/api.mustache | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java index 6f51374c536..6275421d773 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java @@ -692,11 +692,13 @@ public class DefaultCodegen { for(String key: operation.getConsumes()) { Map mediaType = new HashMap(); mediaType.put("mediaType", key); - if (count < operation.getConsumes().size()) - mediaType.put("hasMore", "true"); - else - mediaType.put("hasMore", null); count += 1; + if (count < operation.getConsumes().size()) { + mediaType.put("hasMore", "true"); + } + else { + mediaType.put("hasMore", null); + } c.add(mediaType); } op.consumes = c; diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java index 17509973215..634a93c30cd 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java @@ -165,6 +165,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { operation.putAll(config.additionalProperties()); operation.put("classname", config.toApiName(tag)); operation.put("classVarName", config.toApiVarName(tag)); + processMimeTypes(swagger.getConsumes(), operation, "consumes"); + processMimeTypes(swagger.getProduces(), operation, "produces"); + allOperations.add(new HashMap(operation)); for (int i = 0; i < allOperations.size(); i++) { @@ -291,6 +294,28 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { return files; } + private void processMimeTypes(List mimeTypeList, Map operation, String source) { + if(mimeTypeList != null && mimeTypeList.size() > 0) { + List> c = new ArrayList>(); + int count = 0; + for(String key: mimeTypeList) { + Map mediaType = new HashMap(); + mediaType.put("mediaType", key); + count += 1; + if (count < mimeTypeList.size()) { + mediaType.put("hasMore", "true"); + } + else { + mediaType.put("hasMore", null); + } + c.add(mediaType); + } + operation.put(source, c); + String flagFieldName = "has" + source.substring(0, 1).toUpperCase() + source.substring(1); + operation.put(flagFieldName, true); + } + } + public Map> processPaths(Map paths) { Map> ops = new HashMap>(); diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache index b5ebb30f193..832a8bb8243 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache @@ -21,6 +21,8 @@ import javax.ws.rs.core.Response; import javax.ws.rs.*; @Path("/{{baseName}}") +{{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} +{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} @com.wordnik.swagger.annotations.Api(value = "/{{baseName}}", description = "the {{baseName}} API") {{#operations}} public class {{classname}} { From 2eeb96116d8e698025dca093e1500a0e4b42c241 Mon Sep 17 00:00:00 2001 From: russellb337 Date: Thu, 7 May 2015 12:16:44 -0700 Subject: [PATCH 4/4] simplifying diff --- .../java/com/wordnik/swagger/codegen/DefaultCodegen.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java index 6275421d773..74adbe945f0 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java @@ -693,12 +693,10 @@ public class DefaultCodegen { Map mediaType = new HashMap(); mediaType.put("mediaType", key); count += 1; - if (count < operation.getConsumes().size()) { + if (count < operation.getConsumes().size()) mediaType.put("hasMore", "true"); - } - else { + else mediaType.put("hasMore", null); - } c.add(mediaType); } op.consumes = c;