Skip to content

Commit

Permalink
swagger: report golang type []byte as json type string
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedanese committed Aug 8, 2016
1 parent b14c3a9 commit 3cae443
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 11 additions & 2 deletions swagger/model_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
5 changes: 1 addition & 4 deletions swagger/model_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,10 +869,7 @@ func TestRegion_Issue113(t *testing.T) {
],
"properties": {
"id": {
"type": "array",
"items": {
"type": "integer"
}
"type": "string"
},
"name": {
"type": "string"
Expand Down

0 comments on commit 3cae443

Please sign in to comment.