Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public SwiftCodegen() {
Arrays.asList(
"NSDate",
"NSURL", // for file
"NSUUID",
"Array",
"Dictionary",
"Set",
Expand Down Expand Up @@ -131,6 +132,7 @@ public SwiftCodegen() {
// mapped to String as a workaround
typeMapping.put("binary", "String");
typeMapping.put("ByteArray", "String");
typeMapping.put("UUID", "NSUUID");

importMapping = new HashMap<String, String>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ extension NSDate: JSONEncodable {
}
}

extension NSUUID: JSONEncodable {
func encodeToJSON() -> AnyObject {
return self.UUIDString
}
}

{{#usePromiseKit}}extension RequestBuilder {
public func execute() -> Promise<Response<T>> {
let deferred = Promise<Response<T>>.pendingPromise()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class Decoders {
if T.self is Int64.Type && source is NSNumber {
return source.longLongValue as! T;
}
if T.self is NSUUID.Type && source is String {
return NSUUID(UUIDString: source as! String) as! T
}
if source is T {
return source as! T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void simpleModelTest() {
.property("id", new LongProperty())
.property("name", new StringProperty())
.property("createdAt", new DateTimeProperty())
.property("uuid", new UUIDProperty())
.required("id")
.required("name")
.discriminator("test");
Expand All @@ -27,7 +28,7 @@ public void simpleModelTest() {
Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a sample model");
Assert.assertEquals(cm.vars.size(), 3);
Assert.assertEquals(cm.vars.size(), 4);
Assert.assertEquals(cm.discriminator,"test");

final CodegenProperty property1 = cm.vars.get(0);
Expand Down Expand Up @@ -58,9 +59,19 @@ public void simpleModelTest() {
Assert.assertEquals(property3.name, "createdAt");
Assert.assertNull(property3.defaultValue);
Assert.assertEquals(property3.baseType, "NSDate");
Assert.assertNull(property3.hasMore);
Assert.assertTrue(property3.hasMore);
Assert.assertNull(property3.required);
Assert.assertTrue(property3.isNotContainer);

final CodegenProperty property4 = cm.vars.get(3);
Assert.assertEquals(property4.baseName, "uuid");
Assert.assertEquals(property4.datatype, "NSUUID");
Assert.assertEquals(property4.name, "uuid");
Assert.assertNull(property4.defaultValue);
Assert.assertEquals(property4.baseType, "NSUUID");
Assert.assertNull(property4.hasMore);
Assert.assertNull(property4.required);
Assert.assertTrue(property4.isNotContainer);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ extension NSDate: JSONEncodable {
}
}

extension NSUUID: JSONEncodable {
func encodeToJSON() -> AnyObject {
return self.UUIDString
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class Decoders {
if T.self is Int64.Type && source is NSNumber {
return source.longLongValue as! T;
}
if T.self is NSUUID.Type && source is String {
return NSUUID(UUIDString: source as! String) as! T
}
if source is T {
return source as! T
}
Expand Down