[Swift] Handle binary data types

This commit is contained in:
Jason Gavris
2016-06-30 14:31:31 -04:00
parent ef857176a6
commit 4f0b7dfaed
10 changed files with 174 additions and 51 deletions

View File

@@ -1,5 +1,12 @@
package io.swagger.codegen.languages;
package io.swagger.codegen.swift;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.InlineModelResolver;
import io.swagger.codegen.languages.SwiftCodegen;
import io.swagger.models.Operation;
import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -42,6 +49,20 @@ public class SwiftCodegenTest {
Assert.assertEquals(swiftCodegen.toSwiftyEnumName("entry_name"), "EntryName");
}
@Test(description = "returns NSData when response format is binary")
public void binaryDataTest() {
final Swagger model = new SwaggerParser().read("src/test/resources/2_0/binaryDataTest.json");
final DefaultCodegen codegen = new SwiftCodegen();
final String path = "/tests/binaryResponse";
final Operation p = model.getPaths().get(path).getPost();
final CodegenOperation op = codegen.fromOperation(path, "post", p, model.getDefinitions());
Assert.assertEquals(op.returnType, "NSData");
Assert.assertEquals(op.bodyParam.dataType, "NSData");
Assert.assertTrue(op.bodyParam.isBinary);
Assert.assertTrue(op.responses.get(0).isBinary);
}
@Test
public void testDefaultPodAuthors() throws Exception {
// Given

View File

@@ -18,6 +18,8 @@ public class SwiftModelTest {
.property("id", new LongProperty())
.property("name", new StringProperty())
.property("createdAt", new DateTimeProperty())
.property("binary", new BinaryProperty())
.property("byte", new ByteArrayProperty())
.property("uuid", new UUIDProperty())
.required("id")
.required("name")
@@ -28,7 +30,7 @@ public class SwiftModelTest {
Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a sample model");
Assert.assertEquals(cm.vars.size(), 4);
Assert.assertEquals(cm.vars.size(), 6);
Assert.assertEquals(cm.discriminator,"test");
final CodegenProperty property1 = cm.vars.get(0);
@@ -64,14 +66,34 @@ public class SwiftModelTest {
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.assertEquals(property4.baseName, "binary");
Assert.assertEquals(property4.datatype, "NSData");
Assert.assertEquals(property4.name, "binary");
Assert.assertNull(property4.defaultValue);
Assert.assertEquals(property4.baseType, "NSUUID");
Assert.assertNull(property4.hasMore);
Assert.assertEquals(property4.baseType, "NSData");
Assert.assertTrue(property4.hasMore);
Assert.assertNull(property4.required);
Assert.assertTrue(property4.isNotContainer);
final CodegenProperty property5 = cm.vars.get(4);
Assert.assertEquals(property5.baseName, "byte");
Assert.assertEquals(property5.datatype, "NSData");
Assert.assertEquals(property5.name, "byte");
Assert.assertNull(property5.defaultValue);
Assert.assertEquals(property5.baseType, "NSData");
Assert.assertTrue(property5.hasMore);
Assert.assertNull(property5.required);
Assert.assertTrue(property5.isNotContainer);
final CodegenProperty property6 = cm.vars.get(5);
Assert.assertEquals(property6.baseName, "uuid");
Assert.assertEquals(property6.datatype, "NSUUID");
Assert.assertEquals(property6.name, "uuid");
Assert.assertNull(property6.defaultValue);
Assert.assertEquals(property6.baseType, "NSUUID");
Assert.assertNull(property6.hasMore);
Assert.assertNull(property6.required);
Assert.assertTrue(property6.isNotContainer);
}
}