From 3cae44326c008a015c46189efd9434b6e5217217 Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Mon, 8 Aug 2016 10:13:04 -0700 Subject: [PATCH] swagger: report golang type []byte as json type string --- swagger/model_builder.go | 13 +++++++++++-- swagger/model_builder_test.go | 5 +---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/swagger/model_builder.go b/swagger/model_builder.go index 696d192e..f62c04ab 100644 --- a/swagger/model_builder.go +++ b/swagger/model_builder.go @@ -65,8 +65,12 @@ func (b modelBuilder) addModel(st reflect.Type, nameOverride string) *Model { // check for slice or array if st.Kind() == reflect.Slice || st.Kind() == reflect.Array { - b.addModel(st.Elem(), "") - return &sm + if st.Elem().Kind() == reflect.Uint8 { + return nil + } else { + b.addModel(st.Elem(), "") + return &sm + } } // check for structure or primitive type if st.Kind() != reflect.Struct { @@ -276,6 +280,11 @@ func (b modelBuilder) buildArrayTypeProperty(field reflect.StructField, jsonName return jsonName, prop } fieldType := field.Type + if fieldType.Elem().Kind() == reflect.Uint8 { + stringt := "string" + prop.Type = &stringt + return jsonName, prop + } var pType = "array" prop.Type = &pType isPrimitive := b.isPrimitiveType(fieldType.Elem().Name()) diff --git a/swagger/model_builder_test.go b/swagger/model_builder_test.go index a2e686ca..1cdaef16 100644 --- a/swagger/model_builder_test.go +++ b/swagger/model_builder_test.go @@ -869,10 +869,7 @@ func TestRegion_Issue113(t *testing.T) { ], "properties": { "id": { - "type": "array", - "items": { - "type": "integer" - } + "type": "string" }, "name": { "type": "string"