Skip to content

Commit c4931e5

Browse files
committed
prepare
1 parent 0a3beeb commit c4931e5

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ clean:
22
rm coverage.out
33

44
test:
5-
go test -cover -race -count=1 ./...
5+
go test -cover ./...
66

77
coverage:
88
go test -coverprofile=coverage.out ./...

build_path_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func TestReadArrayObjectInBody(t *testing.T) {
303303
Writes([]Sample{}))
304304

305305
p := buildPaths(ws, Config{})
306-
t.Log(asJSON(p))
306+
//t.Log(asJSON(p))
307307

308308
postInfo := p.Paths["/tests/a/a/b"].Post
309309

@@ -349,7 +349,7 @@ func TestWritesPrimitive(t *testing.T) {
349349
Writes(Sample{}))
350350

351351
p := buildPaths(ws, Config{})
352-
t.Log(asJSON(p))
352+
//t.Log(asJSON(p))
353353

354354
// Make sure that the operation that returns a primitive type is correct.
355355
if pathInfo, okay := p.Paths["/tests/returns/primitive"]; !okay {

definition_builder.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package restfulspec
22

33
import (
4-
"encoding/json"
54
"reflect"
65
"strings"
76

@@ -172,17 +171,17 @@ func (b definitionBuilder) buildProperty(field reflect.StructField, model *spec.
172171
fieldType := field.Type
173172

174173
// check if type is doing its own marshalling
175-
marshalerType := reflect.TypeOf((*json.Marshaler)(nil)).Elem()
176-
if fieldType.Implements(marshalerType) {
177-
var pType = "string"
178-
if prop.Type == nil {
179-
prop.Type = []string{pType}
180-
}
181-
if prop.Format == "" {
182-
prop.Format = b.jsonSchemaFormat(keyFrom(fieldType, b.Config), fieldType.Kind())
183-
}
184-
return jsonName, modelDescription, prop
185-
}
174+
// marshalerType := reflect.TypeOf((*json.Marshaler)(nil)).Elem()
175+
// if fieldType.Implements(marshalerType) {
176+
// var pType = "string"
177+
// if prop.Type == nil {
178+
// prop.Type = []string{pType}
179+
// }
180+
// if prop.Format == "" {
181+
// prop.Format = b.jsonSchemaFormat(keyFrom(fieldType, b.Config), fieldType.Kind())
182+
// }
183+
// return jsonName, modelDescription, prop
184+
// }
186185

187186
// check if annotation says it is a string
188187
if jsonTag := field.Tag.Get("json"); jsonTag != "" {
@@ -317,6 +316,7 @@ func (b definitionBuilder) buildArrayTypeProperty(field reflect.StructField, jso
317316
isArray = b.isSliceOrArrayType(itemType.Kind())
318317
if itemType.Kind() == reflect.Uint8 {
319318
stringt := "string"
319+
prop.Format = "binary"
320320
itemSchema.Type = []string{stringt}
321321
return jsonName, prop
322322
}

definition_builder_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package restfulspec
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"testing"
67

78
"github.com/go-openapi/spec"
@@ -433,8 +434,8 @@ type Embed struct {
433434

434435
func TestRecursiveFieldStructure(t *testing.T) {
435436
db := definitionBuilder{Definitions: spec.Definitions{}, Config: Config{}}
437+
// should not panic
436438
db.addModelFrom(Foo{})
437-
t.Log(db)
438439
}
439440

440441
type email struct {
@@ -453,7 +454,6 @@ func TestDoubleByteArray(t *testing.T) {
453454
if !ok {
454455
t.Fail()
455456
}
456-
t.Log(sc)
457457
if got, want := sc.Type[0], "array"; got != want {
458458
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
459459
}
@@ -476,12 +476,13 @@ func TestDoubleStringArray(t *testing.T) {
476476
t.Log(db.Definitions)
477477
t.Fail()
478478
}
479-
t.Logf("%+v", sc)
480479
if got, want := sc.Type[0], "array"; got != want {
481480
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
482481
}
483482
tp := sc.Items.Schema.Type
484-
t.Logf("%+v", tp)
483+
if got, want := fmt.Sprint(tp), "[array]"; got != want {
484+
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
485+
}
485486
}
486487

487488
type Cell struct {
@@ -501,7 +502,7 @@ func TestDoubleStructArray(t *testing.T) {
501502
t.Logf("definitions: %v", db.Definitions)
502503
t.Fail()
503504
}
504-
t.Logf("%+v", schema)
505+
//t.Logf("%+v", schema)
505506
if want, got := schema.Properties["Cells"].Type[0], "array"; got != want {
506507
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
507508
}
@@ -541,22 +542,20 @@ func TestPostBuildSwaggerSchema(t *testing.T) {
541542
t.Logf("definitions: %#v", db.Definitions)
542543
t.Fail()
543544
}
544-
t.Logf("sc: %#v", sc)
545+
// t.Logf("sc: %#v", sc)
545546
if got, want := sc.Description, "parent's description"; got != want {
546547
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
547548
}
548-
t.Log(sc.Description)
549549

550550
sc, ok = db.Definitions["restfulspec.childPostBuildSwaggerSchema"]
551551
if !ok {
552552
t.Logf("definitions: %#v", db.Definitions)
553553
t.Fail()
554554
}
555-
t.Logf("sc: %#v", sc)
555+
//t.Logf("sc: %#v", sc)
556556
if got, want := sc.Description, "child's description"; got != want {
557557
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
558558
}
559-
t.Log(sc.Description)
560559
}
561560

562561
func TestEmbedStruct(t *testing.T) {

issue79_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package restfulspec
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/go-openapi/spec"
8+
)
9+
10+
type Parent struct {
11+
FieldA string
12+
}
13+
14+
func (v Parent) MarshalJSON() ([]byte, error) { return nil, nil }
15+
16+
type Child struct {
17+
FieldA Parent
18+
FieldB int
19+
}
20+
21+
func TestParentChildArray(t *testing.T) {
22+
t.Skip()
23+
db := definitionBuilder{Definitions: spec.Definitions{}, Config: Config{}}
24+
db.addModelFrom(Child{})
25+
s := spec.Schema{
26+
SchemaProps: spec.SchemaProps{
27+
Definitions: db.Definitions,
28+
},
29+
}
30+
data, _ := json.MarshalIndent(s, "", " ")
31+
t.Log(string(data))
32+
}

property_ext_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestThatExtraTagsAreReadIntoModel(t *testing.T) {
2626
NotNullableField string `x-nullable:"false"`
2727
UUID string `type:"string" format:"UUID"`
2828
XGoName string `x-go-name:"specgoname"`
29+
ByteArray []byte `format:"binary"`
2930
}
3031
d := definitionsFromStruct(Anything{})
3132
props, _ := d["restfulspec.Anything"]

0 commit comments

Comments
 (0)