Repository: swagger-api/swagger-core
Issue: byte and binary properties are wrong

It looks like these two commits are backwards:

Addition of `binary` property:
https://github.com/swagger-api/swagger-core/commit/a18409eb69d9c69435bb2f0bbec7b2540b46616d

Addition of `byte` property:
https://github.com/swagger-api/swagger-core/commit/4e7a8014d14a8d0dd54f31f825858ae072be1061


Changed files:
modules/swagger-core/src/main/java/io/swagger/util/PrimitiveType.java
modules/swagger-models/src/test/java/io/swagger/StringPropertyTest.java
modules/swagger-models/src/main/java/io/swagger/models/properties/ByteArrayProperty.java
modules/swagger-models/src/test/java/io/swagger/models/properties/PropertyBuilderTest.java
modules/swagger-core/src/test/java/io/swagger/ByteConverterTest.java
modules/swagger-models/src/main/java/io/swagger/models/properties/PropertyBuilder.java
modules/swagger-models/src/main/java/io/swagger/models/properties/ByteProperty.java
modules/swagger-models/src/main/java/io/swagger/models/properties/StringProperty.java

diff --git a/modules/swagger-core/src/main/java/io/swagger/util/PrimitiveType.java b/modules/swagger-core/src/main/java/io/swagger/util/PrimitiveType.java
index 8c4980987..237c592c2 100644
--- a/modules/swagger-core/src/main/java/io/swagger/util/PrimitiveType.java
+++ b/modules/swagger-core/src/main/java/io/swagger/util/PrimitiveType.java
@@ -1,19 +1,7 @@
 package io.swagger.util;
 
 import com.fasterxml.jackson.databind.type.TypeFactory;
-import io.swagger.models.properties.BaseIntegerProperty;
-import io.swagger.models.properties.BooleanProperty;
-import io.swagger.models.properties.DateProperty;
-import io.swagger.models.properties.DateTimeProperty;
-import io.swagger.models.properties.DecimalProperty;
-import io.swagger.models.properties.DoubleProperty;
-import io.swagger.models.properties.FloatProperty;
-import io.swagger.models.properties.IntegerProperty;
-import io.swagger.models.properties.LongProperty;
-import io.swagger.models.properties.ObjectProperty;
-import io.swagger.models.properties.Property;
-import io.swagger.models.properties.StringProperty;
-import io.swagger.models.properties.UUIDProperty;
+import io.swagger.models.properties.*;
 
 import java.lang.reflect.Type;
 import java.util.Collections;
@@ -49,8 +37,17 @@ public enum PrimitiveType {
      */
     BYTE(Byte.class, "byte") {
         @Override
-        public StringProperty createProperty() {
-            return new StringProperty(StringProperty.Format.BYTE);
+        public ByteArrayProperty createProperty() {
+            return new ByteArrayProperty();
+        }
+    },
+    /**
+     * Binary
+     */
+    BINARY(Byte.class, "binary") {
+        @Override
+        public BinaryProperty createProperty() {
+            return new BinaryProperty();
         }
     },
     /**
diff --git a/modules/swagger-core/src/test/java/io/swagger/ByteConverterTest.java b/modules/swagger-core/src/test/java/io/swagger/ByteConverterTest.java
index b043684b1..ef27bd4cf 100644
--- a/modules/swagger-core/src/test/java/io/swagger/ByteConverterTest.java
+++ b/modules/swagger-core/src/test/java/io/swagger/ByteConverterTest.java
@@ -4,10 +4,17 @@ import io.swagger.converter.ModelConverters;
 import io.swagger.matchers.SerializationMatchers;
 import io.swagger.models.Model;
 
+import io.swagger.models.ModelImpl;
+import io.swagger.models.properties.ArrayProperty;
+import io.swagger.models.properties.BinaryProperty;
+import io.swagger.models.properties.ByteArrayProperty;
+import io.swagger.util.Json;
 import org.testng.annotations.Test;
 
 import java.util.Map;
 
+import static org.testng.Assert.assertEquals;
+
 public class ByteConverterTest {
 
     @Test
@@ -30,6 +37,54 @@ public class ByteConverterTest {
         SerializationMatchers.assertEqualsToJson(models, json);
     }
 
+    @Test
+    public void testByteProperty() {
+        Model model = new ModelImpl()
+                .property("byteProperty", new ByteArrayProperty());
+
+        assertEquals(Json.pretty(model), "{\\n" +
+                "  \\"properties\\" : {\\n" +
+                "    \\"byteProperty\\" : {\\n" +
+                "      \\"type\\" : \\"string\\",\\n" +
+                "      \\"format\\" : \\"byte\\"\\n" +
+                "    }\\n" +
+                "  }\\n" +
+                "}");
+    }
+
+    @Test
+    public void testDeserializeByteProperty() throws Exception {
+        String json = "{\\n" +
+                "  \\"properties\\" : {\\n" +
+                "    \\"byteProperty\\" : {\\n" +
+                "      \\"type\\" : \\"string\\",\\n" +
+                "      \\"format\\" : \\"byte\\"\\n" +
+                "    }\\n" +
+                "  }\\n" +
+                "}";
+
+        Model model = Json.mapper().readValue(json, Model.class);
+        Json.prettyPrint(model);
+    }
+
+    @Test
+    public void testByteArray() {
+        Model model = new ModelImpl()
+                .property("byteArray", new ArrayProperty(new BinaryProperty()));
+
+        assertEquals(Json.pretty(model), "{\\n" +
+                "  \\"properties\\" : {\\n" +
+                "    \\"byteArray\\" : {\\n" +
+                "      \\"type\\" : \\"array\\",\\n" +
+                "      \\"items\\" : {\\n" +
+                "        \\"type\\" : \\"string\\",\\n" +
+                "        \\"format\\" : \\"binary\\"\\n" +
+                "      }\\n" +
+                "    }\\n" +
+                "  }\\n" +
+                "}");
+    }
+
     class ByteConverterModel {
         public Byte[] myBytes = new Byte[0];
     }
diff --git a/modules/swagger-models/src/main/java/io/swagger/models/properties/ByteProperty.java b/modules/swagger-models/src/main/java/io/swagger/models/properties/BinaryProperty.java
similarity index 74%
rename from modules/swagger-models/src/main/java/io/swagger/models/properties/ByteProperty.java
rename to modules/swagger-models/src/main/java/io/swagger/models/properties/BinaryProperty.java
index c80d984b9..c1e20c5ac 100644
--- a/modules/swagger-models/src/main/java/io/swagger/models/properties/ByteProperty.java
+++ b/modules/swagger-models/src/main/java/io/swagger/models/properties/BinaryProperty.java
@@ -2,73 +2,52 @@ package io.swagger.models.properties;
 
 import io.swagger.models.Xml;
 
-import java.util.ArrayList;
 import java.util.List;
 
-public class ByteProperty extends AbstractProperty implements Property {
+public class BinaryProperty extends AbstractProperty implements Property {
     private static final String TYPE = "string";
-
-    private static final String FORMAT = "byte";
-
     protected List<String> _enum;
     protected Integer minLength = null, maxLength = null;
     protected String pattern = null;
     protected String _default;
 
-    public ByteProperty() {
-        super.type = TYPE;
-        super.format = FORMAT;
-    }
-
-    public ByteProperty _enum(String value) {
-        if (this._enum == null) {
-            this._enum = new ArrayList<String>();
-        }
-        if (!_enum.contains(value)) {
-            _enum.add(value);
-        }
-        return this;
-    }
-
-    public ByteProperty _enum(List<String> value) {
-        this._enum = value;
-        return this;
+    public BinaryProperty() {
+        super.type = "string";
+        super.format = "binary";
     }
 
     public static boolean isType(String type, String format) {
-        if (TYPE.equals(type) && FORMAT.equals(format)) {
+        if ("string".equals(type) && "binary".equals(format))
             return true;
-        } else {
-            return false;
-        }
+        else return false;
     }
 
-    public ByteProperty xml(Xml xml) {
+    public BinaryProperty xml(Xml xml) {
         this.setXml(xml);
         return this;
     }
 
-    public ByteProperty minLength(Integer minLength) {
+    public BinaryProperty minLength(Integer minLength) {
         this.setMinLength(minLength);
         return this;
     }
 
-    public ByteProperty maxLength(Integer maxLength) {
+    public BinaryProperty maxLength(Integer maxLength) {
         this.setMaxLength(maxLength);
         return this;
     }
 
-    public ByteProperty pattern(String pattern) {
+    public BinaryProperty pattern(String pattern) {
         this.setPattern(pattern);
         return this;
     }
 
-    public ByteProperty _default(String _default) {
+    public BinaryProperty _default(String _default) {
         this._default = _default;
         return this;
     }
 
-    public ByteProperty vendorExtension(String key, Object obj) {
+    public BinaryProperty vendorExtension(String key, Object obj) {
         this.setVendorExtension(key, obj);
         return this;
     }
@@ -130,10 +109,10 @@ public class ByteProperty extends AbstractProperty implements Property {
         if (!super.equals(obj)) {
             return false;
         }
-        if (!(obj instanceof ByteProperty)) {
+        if (!(obj instanceof BinaryProperty)) {
             return false;
         }
-        ByteProperty other = (ByteProperty) obj;
+        BinaryProperty other = (BinaryProperty) obj;
         if (_default == null) {
             if (other._default != null) {
                 return false;
diff --git a/modules/swagger-models/src/main/java/io/swagger/models/properties/ByteArrayProperty.java b/modules/swagger-models/src/main/java/io/swagger/models/properties/ByteArrayProperty.java
index 496a7ed05..c6ba49a34 100644
--- a/modules/swagger-models/src/main/java/io/swagger/models/properties/ByteArrayProperty.java
+++ b/modules/swagger-models/src/main/java/io/swagger/models/properties/ByteArrayProperty.java
@@ -2,18 +2,16 @@ package io.swagger.models.properties;
 
 import io.swagger.models.Xml;
 
-import java.util.*;
-
 public class ByteArrayProperty extends AbstractProperty implements Property {
 
 
     public ByteArrayProperty() {
         super.type = "string";
-        super.format = "binary";
+        super.format = "byte";
     }
 
     public static boolean isType(String type, String format) {
-        if ("string".equals(type) && "binary".equals(format))
+        if ("string".equals(type) && "byte".equals(format))
             return true;
         else return false;
     }
diff --git a/modules/swagger-models/src/main/java/io/swagger/models/properties/PropertyBuilder.java b/modules/swagger-models/src/main/java/io/swagger/models/properties/PropertyBuilder.java
index 750f788d2..8fb677dca 100644
--- a/modules/swagger-models/src/main/java/io/swagger/models/properties/PropertyBuilder.java
+++ b/modules/swagger-models/src/main/java/io/swagger/models/properties/PropertyBuilder.java
@@ -156,6 +156,17 @@ public class PropertyBuilder {
                 return new ByteArrayProperty();
             }
         },
+        BINARY(BinaryProperty.class) {
+            @Override
+            protected boolean isType(String type, String format) {
+                return BinaryProperty.isType(type, format);
+            }
+
+            @Override
+            protected BinaryProperty create() {
+                return new BinaryProperty();
+            }
+        },
         DATE(DateProperty.class) {
             @Override
             protected boolean isType(String type, String format) {
diff --git a/modules/swagger-models/src/main/java/io/swagger/models/properties/StringProperty.java b/modules/swagger-models/src/main/java/io/swagger/models/properties/StringProperty.java
index 0dbb65ced..920ab1b3e 100644
--- a/modules/swagger-models/src/main/java/io/swagger/models/properties/StringProperty.java
+++ b/modules/swagger-models/src/main/java/io/swagger/models/properties/StringProperty.java
@@ -17,7 +17,6 @@ public class StringProperty extends AbstractProperty implements Property {
     protected String _default;
 
     public enum Format {
-        BYTE("byte"),
         URI("uri"),
         URL("url");
 
diff --git a/modules/swagger-models/src/test/java/io/swagger/StringPropertyTest.java b/modules/swagger-models/src/test/java/io/swagger/StringPropertyTest.java
index 19bf1ae6e..45be6930d 100644
--- a/modules/swagger-models/src/test/java/io/swagger/StringPropertyTest.java
+++ b/modules/swagger-models/src/test/java/io/swagger/StringPropertyTest.java
@@ -1,21 +1,17 @@
 package io.swagger;
 
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-
 import io.swagger.models.properties.StringProperty;
-
 import org.testng.annotations.Test;
 
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
+
 public class StringPropertyTest {
     private static final String PROP_1 = "prop1";
     private static final String PROP_2 = "prop2";
 
     @Test
     public void testEquals() {
-        assertNotEquals(new StringProperty(StringProperty.Format.BYTE), new StringProperty(StringProperty.Format.URL));
-        assertEquals(new StringProperty(StringProperty.Format.BYTE), new StringProperty(StringProperty.Format.BYTE));
-
         final StringProperty prop1 = new StringProperty();
         prop1.setName(PROP_1);
         prop1.setRequired(true);
diff --git a/modules/swagger-models/src/test/java/io/swagger/models/properties/PropertyBuilderTest.java b/modules/swagger-models/src/test/java/io/swagger/models/properties/PropertyBuilderTest.java
index d32f3dc27..3c0ff8b69 100644
--- a/modules/swagger-models/src/test/java/io/swagger/models/properties/PropertyBuilderTest.java
+++ b/modules/swagger-models/src/test/java/io/swagger/models/properties/PropertyBuilderTest.java
@@ -1,17 +1,15 @@
 package io.swagger.models.properties;
 
-import java.util.ArrayList;
-import java.util.EnumMap;
-import java.util.Iterator;
-import java.util.List;
-
+import io.swagger.models.properties.PropertyBuilder.PropertyId;
+import io.swagger.models.properties.StringProperty.Format;
 import org.testng.Assert;
-
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
-import io.swagger.models.properties.PropertyBuilder.PropertyId;
-import io.swagger.models.properties.StringProperty.Format;
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.Iterator;
+import java.util.List;
 
 public class PropertyBuilderTest {
 
@@ -57,8 +55,8 @@ public class PropertyBuilderTest {
                 {"number", "float", FloatProperty.class},
                 {"number", "double", DoubleProperty.class},
                 {"string", null, StringProperty.class},
-                {"string", "byte", StringProperty.class}, // are this and the next one correct?
-                {"string", "binary", ByteArrayProperty.class},
+                {"string", "byte", ByteArrayProperty.class},
+                {"string", "binary", BinaryProperty.class},
                 {"boolean", null, BooleanProperty.class},
                 {"string", "date", DateProperty.class},
                 {"string", "date-time", DateTimeProperty.class},