diff --git a/README.md b/README.md
index ed8244004c..6118d3e985 100644
--- a/README.md
+++ b/README.md
@@ -72,6 +72,7 @@ mvn package
Other languages have petstore samples, too:
```
+./bin/android-petstore.sh
./bin/java-petstore.sh
./bin/objc-petstore.sh
```
diff --git a/src/test/resources/petstore.json b/src/test/resources/petstore.json
new file mode 100644
index 0000000000..ae078d3435
--- /dev/null
+++ b/src/test/resources/petstore.json
@@ -0,0 +1,722 @@
+{
+ "swagger": 2.0,
+ "info": {
+ "description": "This is a sample server Petstore server. You can find out more about Swagger at http://swagger.wordnik.com or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
+ "version": "1.0.0",
+ "title": "Swagger Petstore",
+ "termsOfService": "http://helloreverb.com/terms/",
+ "contact": {
+ "name": "apiteam@wordnik.com"
+ },
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
+ }
+ },
+ "basePath": "/v2",
+ "paths": {
+ "/pet": {
+ "post": {
+ "tags": [
+ "pet"
+ ],
+ "summary": "Add a new pet to the store",
+ "description": "",
+ "operationId": "addPet",
+ "consumes": [
+ "application/json",
+ "application/xml"
+ ],
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "Pet object that needs to be added to the store",
+ "required": false,
+ "schema": {
+ "$ref": "#/definitions/Pet"
+ }
+ }
+ ],
+ "responses": {
+ "405": {
+ "description": "Invalid input"
+ }
+ }
+ },
+ "put": {
+ "tags": [
+ "pet"
+ ],
+ "summary": "Update an existing pet",
+ "description": "",
+ "operationId": "updatePet",
+ "consumes": [
+ "application/json",
+ "application/xml"
+ ],
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "Pet object that needs to be added to the store",
+ "required": false,
+ "schema": {
+ "$ref": "#/definitions/Pet"
+ }
+ }
+ ],
+ "responses": {
+ "405": {
+ "description": "Validation exception"
+ },
+ "404": {
+ "description": "Pet not found"
+ },
+ "400": {
+ "description": "Invalid ID supplied"
+ }
+ }
+ }
+ },
+ "/pet/findByStatus": {
+ "get": {
+ "tags": [
+ "pet"
+ ],
+ "summary": "Finds Pets by status",
+ "description": "Multiple status values can be provided with comma seperated strings",
+ "operationId": "findPetsByStatus",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "query",
+ "name": "status",
+ "description": "Status values that need to be considered for filter",
+ "required": false,
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "collectionFormat": "default"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/Pet"
+ }
+ }
+ },
+ "400": {
+ "description": "Invalid status value"
+ }
+ }
+ }
+ },
+ "/pet/findByTags": {
+ "get": {
+ "tags": [
+ "pet"
+ ],
+ "summary": "Finds Pets by tags",
+ "description": "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
+ "operationId": "findPetsByTags",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "query",
+ "name": "tags",
+ "description": "Tags to filter by",
+ "required": false,
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "collectionFormat": "default"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/Pet"
+ }
+ }
+ },
+ "400": {
+ "description": "Invalid tag value"
+ }
+ }
+ }
+ },
+ "/pet/{petId}": {
+ "get": {
+ "tags": [
+ "pet"
+ ],
+ "summary": "Find pet by ID",
+ "description": "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
+ "operationId": "getPetById",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "path",
+ "name": "petId",
+ "description": "ID of pet that needs to be fetched",
+ "required": true,
+ "type": "integer",
+ "format": "int64"
+ }
+ ],
+ "responses": {
+ "404": {
+ "description": "Pet not found"
+ },
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "$ref": "#/definitions/Pet"
+ }
+ },
+ "400": {
+ "description": "Invalid ID supplied"
+ }
+ }
+ },
+ "delete": {
+ "tags": [
+ "pet"
+ ],
+ "summary": "Deletes a pet",
+ "description": "",
+ "operationId": "deletePet",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "path",
+ "name": "petId",
+ "description": "Pet id to delete",
+ "required": true,
+ "type": "integer",
+ "format": "int64"
+ }
+ ],
+ "responses": {
+ "400": {
+ "description": "Invalid pet value"
+ }
+ }
+ }
+ },
+ "/store/order": {
+ "post": {
+ "tags": [
+ "store"
+ ],
+ "summary": "Place an order for a pet",
+ "description": "",
+ "operationId": "placeOrder",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "order placed for purchasing the pet",
+ "required": false,
+ "schema": {
+ "$ref": "#/definitions/Order"
+ }
+ }
+ ],
+ "responses": {
+ "400": {
+ "description": "Invalid Order"
+ }
+ }
+ }
+ },
+ "/store/order/{orderId}": {
+ "get": {
+ "tags": [
+ "store"
+ ],
+ "summary": "Find purchase order by ID",
+ "description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
+ "operationId": "getOrderById",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "path",
+ "name": "orderId",
+ "description": "ID of pet that needs to be fetched",
+ "required": true,
+ "type": "string"
+ }
+ ],
+ "responses": {
+ "404": {
+ "description": "Order not found"
+ },
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "$ref": "#/definitions/Order"
+ }
+ },
+ "400": {
+ "description": "Invalid ID supplied"
+ }
+ }
+ },
+ "delete": {
+ "tags": [
+ "store"
+ ],
+ "summary": "Delete purchase order by ID",
+ "description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
+ "operationId": "deleteOrder",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "path",
+ "name": "orderId",
+ "description": "ID of the order that needs to be deleted",
+ "required": true,
+ "type": "string"
+ }
+ ],
+ "responses": {
+ "404": {
+ "description": "Order not found"
+ },
+ "400": {
+ "description": "Invalid ID supplied"
+ }
+ }
+ }
+ },
+ "/user": {
+ "post": {
+ "tags": [
+ "user"
+ ],
+ "summary": "Create user",
+ "description": "This can only be done by the logged in user.",
+ "operationId": "createUser",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "Created user object",
+ "required": false,
+ "schema": {
+ "$ref": "#/definitions/User"
+ }
+ }
+ ],
+ "responses": {
+ "default": {
+ "description": "successful operation"
+ }
+ }
+ }
+ },
+ "/user/createWithArray": {
+ "post": {
+ "tags": [
+ "user"
+ ],
+ "summary": "Creates list of users with given input array",
+ "description": "",
+ "operationId": "createUsersWithArrayInput",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "List of user object",
+ "required": false,
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "User"
+ }
+ }
+ }
+ ],
+ "responses": {
+ "default": {
+ "description": "successful operation"
+ }
+ }
+ }
+ },
+ "/user/createWithList": {
+ "post": {
+ "tags": [
+ "user"
+ ],
+ "summary": "Creates list of users with given input array",
+ "description": "",
+ "operationId": "createUsersWithListInput",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "List of user object",
+ "required": false,
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/User"
+ }
+ }
+ }
+ ],
+ "responses": {
+ "default": {
+ "description": "successful operation"
+ }
+ }
+ }
+ },
+ "/user/login": {
+ "get": {
+ "tags": [
+ "user"
+ ],
+ "summary": "Logs user into the system",
+ "description": "",
+ "operationId": "loginUser",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "query",
+ "name": "username",
+ "description": "The user name for login",
+ "required": false,
+ "type": "string"
+ },
+ {
+ "in": "query",
+ "name": "password",
+ "description": "The password for login in clear text",
+ "required": false,
+ "type": "string"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "type": "string"
+ }
+ },
+ "400": {
+ "description": "Invalid username/password supplied"
+ }
+ }
+ }
+ },
+ "/user/logout": {
+ "get": {
+ "tags": [
+ "user"
+ ],
+ "summary": "Logs out current logged in user session",
+ "description": "",
+ "operationId": "logoutUser",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "responses": {
+ "default": {
+ "description": "successful operation"
+ }
+ }
+ }
+ },
+ "/user/{username}": {
+ "get": {
+ "tags": [
+ "user"
+ ],
+ "summary": "Get user by user name",
+ "description": "",
+ "operationId": "getUserByName",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "path",
+ "name": "username",
+ "description": "The name that needs to be fetched. Use user1 for testing. ",
+ "required": true,
+ "type": "string"
+ }
+ ],
+ "responses": {
+ "404": {
+ "description": "User not found"
+ },
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "$ref": "#/definitions/User"
+ }
+ },
+ "400": {
+ "description": "Invalid username supplied"
+ }
+ }
+ },
+ "put": {
+ "tags": [
+ "user"
+ ],
+ "summary": "Updated user",
+ "description": "This can only be done by the logged in user.",
+ "operationId": "updateUser",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "path",
+ "name": "username",
+ "description": "name that need to be deleted",
+ "required": true,
+ "type": "string"
+ },
+ {
+ "in": "body",
+ "name": "body",
+ "description": "Updated user object",
+ "required": false,
+ "schema": {
+ "$ref": "#/definitions/User"
+ }
+ }
+ ],
+ "responses": {
+ "404": {
+ "description": "User not found"
+ },
+ "400": {
+ "description": "Invalid user supplied"
+ }
+ }
+ },
+ "delete": {
+ "tags": [
+ "user"
+ ],
+ "summary": "Delete user",
+ "description": "This can only be done by the logged in user.",
+ "operationId": "deleteUser",
+ "produces": [
+ "application/json",
+ "application/xml"
+ ],
+ "parameters": [
+ {
+ "in": "path",
+ "name": "username",
+ "description": "The name that needs to be deleted",
+ "required": true,
+ "type": "string"
+ }
+ ],
+ "responses": {
+ "404": {
+ "description": "User not found"
+ },
+ "400": {
+ "description": "Invalid username supplied"
+ }
+ }
+ }
+ }
+ },
+ "definitions": {
+ "User": {
+ "properties": {
+ "id": {
+ "type": "integer",
+ "format": "int64"
+ },
+ "username": {
+ "type": "string"
+ },
+ "firstName": {
+ "type": "string"
+ },
+ "lastName": {
+ "type": "string"
+ },
+ "email": {
+ "type": "string"
+ },
+ "password": {
+ "type": "string"
+ },
+ "phone": {
+ "type": "string"
+ },
+ "userStatus": {
+ "type": "integer",
+ "format": "int32",
+ "position": 0
+ }
+ }
+ },
+ "Category": {
+ "properties": {
+ "id": {
+ "type": "integer",
+ "format": "int64"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ },
+ "Pet": {
+ "description": "A single pet in the store",
+ "required": [
+ "name",
+ "photoUrls"
+ ],
+ "properties": {
+ "id": {
+ "description": "the identifier for the pet",
+ "type": "integer",
+ "format": "int64"
+ },
+ "category": {
+ "$ref": "Category"
+ },
+ "name": {
+ "type": "string",
+ "example": "doggie",
+ "position": 0
+ },
+ "photoUrls": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "tags": {
+ "type": "array",
+ "items": {
+ "$ref": "Tag"
+ }
+ },
+ "status": {
+ "type": "string",
+ "position": 0
+ }
+ }
+ },
+ "Tag": {
+ "required": [ "id", "name" ],
+ "properties": {
+ "id": {
+ "type": "integer",
+ "format": "int64"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ },
+ "Order": {
+ "required": [ "id" ],
+ "properties": {
+ "id": {
+ "type": "integer",
+ "format": "int64"
+ },
+ "petId": {
+ "type": "integer",
+ "format": "int64"
+ },
+ "quantity": {
+ "type": "integer",
+ "format": "int32"
+ },
+ "shipDate": {
+ "type": "string",
+ "format": "date-time"
+ },
+ "status": {
+ "type": "string",
+ "position": 0
+ },
+ "complete": {
+ "type": "boolean"
+ },
+ "keyValuePairs": {
+ "type": "object",
+ "additionalProperties": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/scala/Java/JavaModelTest.scala b/src/test/scala/Java/JavaModelTest.scala
new file mode 100644
index 0000000000..79ade48d0a
--- /dev/null
+++ b/src/test/scala/Java/JavaModelTest.scala
@@ -0,0 +1,209 @@
+package Java
+
+import com.wordnik.swagger.codegen.languages.JavaClientCodegen
+import com.wordnik.swagger.util.Json
+import com.wordnik.swagger.models._
+import com.wordnik.swagger.models.properties._
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.FlatSpec
+import org.scalatest.Matchers
+
+import scala.collection.JavaConverters._
+
+@RunWith(classOf[JUnitRunner])
+class JavaModelTest extends FlatSpec with Matchers {
+
+ it should "convert a simple java model" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("id", new LongProperty())
+ .property("name", new StringProperty())
+ .property("createdAt", new DateTimeProperty())
+ .required("id")
+ .required("name")
+
+ val codegen = new JavaClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("Sample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (3)
+
+ val vars = cm.vars
+ vars.get(0).baseName should be ("id")
+ vars.get(0).getter should be ("getId")
+ vars.get(0).setter should be ("setId")
+ vars.get(0).datatype should be ("Long")
+ vars.get(0).name should be ("id")
+ vars.get(0).defaultValue should be ("null")
+ vars.get(0).baseType should be ("Long")
+ vars.get(0).hasMore should equal (true)
+ vars.get(0).required should equal (true)
+ vars.get(0).isNotContainer should equal (true)
+
+ vars.get(1).baseName should be ("name")
+ vars.get(1).getter should be ("getName")
+ vars.get(1).setter should be ("setName")
+ vars.get(1).datatype should be ("String")
+ vars.get(1).name should be ("name")
+ vars.get(1).defaultValue should be ("null")
+ vars.get(1).baseType should be ("String")
+ vars.get(1).hasMore should equal (true)
+ vars.get(1).required should equal (true)
+ vars.get(1).isNotContainer should equal (true)
+
+ vars.get(2).baseName should be ("createdAt")
+ vars.get(2).getter should be ("getCreatedAt")
+ vars.get(2).setter should be ("setCreatedAt")
+ vars.get(2).datatype should be ("Date")
+ vars.get(2).name should be ("createdAt")
+ vars.get(2).defaultValue should be ("null")
+ vars.get(2).baseType should be ("Date")
+ vars.get(2).hasMore should equal (null)
+ vars.get(2).required should equal (false)
+ vars.get(2).isNotContainer should equal (true)
+ }
+
+ it should "convert a model with list property" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("id", new LongProperty())
+ .property("urls", new ArrayProperty()
+ .items(new StringProperty()))
+ .required("id")
+
+ val codegen = new JavaClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("Sample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (2)
+
+ val vars = cm.vars
+ vars.get(1).baseName should be ("urls")
+ vars.get(1).getter should be ("getUrls")
+ vars.get(1).setter should be ("setUrls")
+ vars.get(1).datatype should be ("List")
+ vars.get(1).name should be ("urls")
+ vars.get(1).defaultValue should be ("new ArrayList() ")
+ vars.get(1).baseType should be ("List")
+ vars.get(1).containerType should be ("array")
+ vars.get(1).required should equal (false)
+ vars.get(1).isContainer should equal (true)
+ }
+
+ it should "convert a model wiht a map property" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("translations", new MapProperty()
+ .additionalProperties(new StringProperty()))
+ .required("id")
+
+ val codegen = new JavaClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("Sample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (1)
+
+ val vars = cm.vars
+ vars.get(0).baseName should be ("translations")
+ vars.get(0).getter should be ("getTranslations")
+ vars.get(0).setter should be ("setTranslations")
+ vars.get(0).datatype should be ("Map")
+ vars.get(0).name should be ("translations")
+ vars.get(0).defaultValue should be ("new HashMap() ")
+ vars.get(0).baseType should be ("Map")
+ vars.get(0).containerType should be ("map")
+ vars.get(0).required should equal (false)
+ vars.get(0).isContainer should equal (true)
+ }
+
+ it should "convert a model with complex properties" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("children", new RefProperty("#/definitions/Children"))
+
+ val codegen = new JavaClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("Sample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (1)
+
+ val vars = cm.vars
+ vars.get(0).baseName should be ("children")
+ vars.get(0).getter should be ("getChildren")
+ vars.get(0).setter should be ("setChildren")
+ vars.get(0).datatype should be ("Children")
+ vars.get(0).name should be ("children")
+ vars.get(0).defaultValue should be ("null")
+ vars.get(0).baseType should be ("Children")
+ vars.get(0).required should equal (false)
+ vars.get(0).isNotContainer should equal (true)
+ }
+
+ it should "convert a model with complex list property" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("children", new ArrayProperty()
+ .items(new RefProperty("#/definitions/Children")))
+
+ val codegen = new JavaClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("Sample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (1)
+
+ val vars = cm.vars
+ vars.get(0).baseName should be ("children")
+ vars.get(0).complexType should be ("Children")
+ vars.get(0).getter should be ("getChildren")
+ vars.get(0).setter should be ("setChildren")
+ vars.get(0).datatype should be ("List")
+ vars.get(0).name should be ("children")
+ vars.get(0).defaultValue should be ("new ArrayList() ")
+ vars.get(0).baseType should be ("List")
+ vars.get(0).containerType should be ("array")
+ vars.get(0).required should equal (false)
+ vars.get(0).isContainer should equal (true)
+ }
+
+ it should "convert a model with complex map property" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("children", new MapProperty()
+ .additionalProperties(new RefProperty("#/definitions/Children")))
+
+ val codegen = new JavaClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("Sample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (1)
+ (cm.imports.asScala.toSet & Set("Map", "List", "Children")).size should be (3)
+
+ val vars = cm.vars
+ vars.get(0).baseName should be ("children")
+ vars.get(0).complexType should be ("Children")
+ vars.get(0).getter should be ("getChildren")
+ vars.get(0).setter should be ("setChildren")
+ vars.get(0).datatype should be ("Map")
+ vars.get(0).name should be ("children")
+ vars.get(0).defaultValue should be ("new HashMap() ")
+ vars.get(0).baseType should be ("Map")
+ vars.get(0).containerType should be ("map")
+ vars.get(0).required should equal (false)
+ vars.get(0).isContainer should equal (true)
+ vars.get(0).isNotContainer should be (null)
+ }
+}
\ No newline at end of file
diff --git a/src/test/scala/Objc/ObjcModelTest.scala b/src/test/scala/Objc/ObjcModelTest.scala
new file mode 100644
index 0000000000..454fbedea1
--- /dev/null
+++ b/src/test/scala/Objc/ObjcModelTest.scala
@@ -0,0 +1,218 @@
+package objc
+
+import com.wordnik.swagger.codegen.languages.ObjcClientCodegen
+import com.wordnik.swagger.util.Json
+import com.wordnik.swagger.models._
+import com.wordnik.swagger.models.properties._
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.FlatSpec
+import org.scalatest.Matchers
+
+import scala.collection.JavaConverters._
+
+@RunWith(classOf[JUnitRunner])
+class ObjcModelTest extends FlatSpec with Matchers {
+
+ it should "convert a simple java model" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("id", new LongProperty())
+ .property("name", new StringProperty())
+ .property("createdAt", new DateTimeProperty())
+ .required("id")
+ .required("name")
+
+ val codegen = new ObjcClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("SWGSample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (3)
+
+ val vars = cm.vars
+ vars.get(0).baseName should be ("id")
+ vars.get(0).datatype should be ("NSNumber*")
+ vars.get(0).name should be ("_id")
+ vars.get(0).defaultValue should be ("null")
+ vars.get(0).baseType should be ("NSNumber")
+ vars.get(0).hasMore should equal (true)
+ vars.get(0).required should equal (true)
+ vars.get(0).isPrimitiveType should equal (true)
+ vars.get(0).isNotContainer should equal (true)
+
+ vars.get(1).baseName should be ("name")
+ vars.get(1).datatype should be ("NSString*")
+ vars.get(1).name should be ("name")
+ vars.get(1).defaultValue should be ("null")
+ vars.get(1).baseType should be ("NSString")
+ vars.get(1).hasMore should equal (true)
+ vars.get(1).required should equal (true)
+ vars.get(0).isPrimitiveType should equal (true)
+ vars.get(1).isNotContainer should equal (true)
+
+ vars.get(2).baseName should be ("createdAt")
+ vars.get(2).datatype should be ("SWGDate*")
+ vars.get(2).name should be ("createdAt")
+ vars.get(2).defaultValue should be ("null")
+ vars.get(2).baseType should be ("SWGDate")
+ vars.get(2).hasMore should equal (null)
+ vars.get(2).required should equal (false)
+ vars.get(2).isNotContainer should equal (true)
+
+ (cm.imports.asScala.toSet &
+ Set("SWGDate")).size should be (1)
+ }
+
+ it should "convert a model with list property" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("id", new LongProperty())
+ .property("urls", new ArrayProperty()
+ .items(new StringProperty()))
+ .required("id")
+
+ val codegen = new ObjcClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+Json.prettyPrint(cm)
+ cm.name should be ("sample")
+ cm.classname should be ("SWGSample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (2)
+
+ val vars = cm.vars
+ vars.get(0).baseName should be ("id")
+ vars.get(0).datatype should be ("NSNumber*")
+ vars.get(0).name should be ("_id")
+ vars.get(0).defaultValue should be ("null")
+ vars.get(0).baseType should be ("NSNumber")
+ vars.get(0).hasMore should equal (true)
+ vars.get(0).required should equal (true)
+ vars.get(0).isPrimitiveType should equal (true)
+ vars.get(0).isNotContainer should equal (true)
+
+ vars.get(1).baseName should be ("urls")
+ vars.get(1).datatype should be ("NSArray*")
+ vars.get(1).name should be ("urls")
+ // vars.get(1).defaultValue should be ("null")
+ vars.get(1).baseType should be ("NSArray")
+ vars.get(1).hasMore should be (null)
+ vars.get(1).required should equal (false)
+ vars.get(1).isContainer should equal (true)
+ vars.get(1).containerType should equal ("array")
+ }
+
+ it should "convert a model wiht a map property" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("translations", new MapProperty()
+ .additionalProperties(new StringProperty()))
+ .required("id")
+
+ val codegen = new ObjcClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ // cm.name should be ("sample")
+ // cm.classname should be ("SWGSample")
+ // cm.description should be ("a sample model")
+ // cm.vars.size should be (1)
+
+ val vars = cm.vars
+ // vars.get(0).baseName should be ("translations")
+ // vars.get(0).getter should be ("getTranslations")
+ // vars.get(0).setter should be ("setTranslations")
+ // vars.get(0).datatype should be ("Map")
+ // vars.get(0).name should be ("translations")
+ // vars.get(0).defaultValue should be ("new HashMap() ")
+ // vars.get(0).baseType should be ("Map")
+ // vars.get(0).containerType should be ("map")
+ // vars.get(0).required should equal (false)
+ // vars.get(0).isContainer should equal (true)
+ }
+
+ it should "convert a model with complex properties" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("children", new RefProperty("#/definitions/Children"))
+
+ val codegen = new ObjcClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("SWGSample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (1)
+
+ val vars = cm.vars
+ // vars.get(0).baseName should be ("children")
+ // vars.get(0).getter should be ("getChildren")
+ // vars.get(0).setter should be ("setChildren")
+ // vars.get(0).datatype should be ("Children")
+ // vars.get(0).name should be ("children")
+ // vars.get(0).defaultValue should be ("null")
+ // vars.get(0).baseType should be ("Children")
+ // vars.get(0).required should equal (false)
+ // vars.get(0).isNotContainer should equal (true)
+ }
+
+ it should "convert a model with complex list property" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("children", new ArrayProperty()
+ .items(new RefProperty("#/definitions/Children")))
+
+ val codegen = new ObjcClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ // cm.name should be ("sample")
+ // cm.classname should be ("SWGSample")
+ // cm.description should be ("a sample model")
+ // cm.vars.size should be (1)
+
+ val vars = cm.vars
+ // vars.get(0).baseName should be ("children")
+ // vars.get(0).complexType should be ("Children")
+ // vars.get(0).getter should be ("getChildren")
+ // vars.get(0).setter should be ("setChildren")
+ // vars.get(0).datatype should be ("List")
+ // vars.get(0).name should be ("children")
+ // vars.get(0).defaultValue should be ("new ArrayList() ")
+ // vars.get(0).baseType should be ("List")
+ // vars.get(0).containerType should be ("array")
+ // vars.get(0).required should equal (false)
+ // vars.get(0).isContainer should equal (true)
+ }
+
+ it should "convert a model with complex map property" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("children", new MapProperty()
+ .additionalProperties(new RefProperty("#/definitions/Children")))
+
+ val codegen = new ObjcClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ // cm.name should be ("sample")
+ // cm.classname should be ("SWGSample")
+ // cm.description should be ("a sample model")
+ // cm.vars.size should be (1)
+ // (cm.imports.asScala.toSet & Set("Map", "List", "Children")).size should be (3)
+
+ val vars = cm.vars
+ // vars.get(0).baseName should be ("children")
+ // vars.get(0).complexType should be ("Children")
+ // vars.get(0).getter should be ("getChildren")
+ // vars.get(0).setter should be ("setChildren")
+ // vars.get(0).datatype should be ("Map")
+ // vars.get(0).name should be ("children")
+ // vars.get(0).defaultValue should be ("new HashMap() ")
+ // vars.get(0).baseType should be ("Map")
+ // vars.get(0).containerType should be ("map")
+ // vars.get(0).required should equal (false)
+ // vars.get(0).isContainer should equal (true)
+ // vars.get(0).isNotContainer should be (null)
+ }
+}
\ No newline at end of file