func TestNewSchemaFromStructFieldExampleValues(t *testing.T) {
	g := gen(t)
	type T struct {
		A    string    `example:"value"`
		APtr *string   `example:"value"`
		B    int       `example:"1"`
		BPtr *int      `example:"1"`
		C    float64   `example:"0.1"`
		CPtr *float64  `example:"0.1"`
		D    bool      `example:"true"`
		DPtr *bool     `example:"true"`
		EPtr **bool    `example:"false"`
		FPtr ***uint16 `example:"128"`
	}
	typ := reflect.TypeOf(T{})
	sor := g.newSchemaFromStructField(typ.Field(0), false, "A", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, "value", sor.Example)
	sor = g.newSchemaFromStructField(typ.Field(1), false, "APtr", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, "value", sor.Example)
	sor = g.newSchemaFromStructField(typ.Field(2), false, "B", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, int64(1), sor.Example)
	sor = g.newSchemaFromStructField(typ.Field(3), false, "BPtr", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, int64(1), sor.Example)
	sor = g.newSchemaFromStructField(typ.Field(4), false, "C", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, 0.1, sor.Example)
	sor = g.newSchemaFromStructField(typ.Field(5), false, "CPtr", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, 0.1, sor.Example)
	sor = g.newSchemaFromStructField(typ.Field(6), false, "D", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, true, sor.Example)
	sor = g.newSchemaFromStructField(typ.Field(7), false, "DPtr", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, true, sor.Example)
	sor = g.newSchemaFromStructField(typ.Field(8), false, "EPtr", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, false, sor.Example)
	sor = g.newSchemaFromStructField(typ.Field(9), false, "FPtr", typ)
	assert.NotNil(t, sor)
	assert.Equal(t, uint16(128), sor.Example)
}
TestNewSchemaFromStructFieldExampleValues tests the
case of setting example values.
package openapi
import (
	"encoding/json"
	"io/ioutil"
	"math"
	"reflect"
	"testing"
	"time"
	"github.com/Pallinder/go-randomdata"
	"github.com/loopfz/gadgeto/tonic"
	"github.com/stretchr/testify/assert"
)
var genConfig = &SpecGenConfig{
	ValidatorTag:      tonic.ValidationTag,
	PathLocationTag:   tonic.PathTag,
	QueryLocationTag:  tonic.QueryTag,
	HeaderLocationTag: tonic.HeaderTag,
	EnumTag:           tonic.EnumTag,
	DefaultTag:        tonic.DefaultTag,
}
var rt = reflect.TypeOf
type (
	W struct {
		A, B string
	}
	u struct {
		S int
	}
	q int
	X struct {
		*X  
		*Y
		A string `validate:"required"`
		B *int
		C bool `deprecated:"true"`
		D []*Y
		E [3]*X
		F *X
		G *Y
		H map[int]*Y  
		*u
		uu *u  
		q      
	}
	Y struct {
		H float32   `validate:"required"`
		I time.Time `format:"date"`
		J *uint8    `deprecated:"oui"`  
		K *Z        `validate:"required"`
		N struct {
			Na, Nb string
			Nc     time.Duration
		}
		l int  
		M int `json:"-"`
	}
	Z map[string]*Y
)
func (*X) TypeName() string { return "XXX" }
func (*W) Format() string   { return "wallet" }
func (*W) Type() string     { return "string" }
func TestStructFieldName(t *testing.T) {
	type T struct {
		A  string `name:"A"`
		Ba string `name:""`
		AB string `name:"-"`
		B  struct{}
	}
	to := reflect.TypeOf(T{})
	assert.Equal(t, "A", fieldNameFromTag(to.Field(0), "name"))
	assert.Equal(t, "Ba", fieldNameFromTag(to.Field(1), "name"))
	assert.Equal(t, "", fieldNameFromTag(to.Field(2), "name"))
}
func TestAddTag(t *testing.T) {
	g := gen(t)
	g.api.Tags = append(g.api.Tags, nil)
	g.AddTag("", "Test routes")
	assert.Len(t, g.API().Tags, 1)
	g.AddTag("Test", "Test routes")
	assert.Len(t, g.API().Tags, 2)
	tag := g.API().Tags[1]
	assert.NotNil(t, tag)
	assert.Equal(t, tag.Name, "Test")
	assert.Equal(t, tag.Description, "Test routes")
	g.AddTag("Test", "Routes test")
	assert.Equal(t, tag.Description, "Routes test")
	g.AddTag("A", "")
	assert.Len(t, g.API().Tags, 3)
	tag = g.API().Tags[1]
	assert.Equal(t, "A", tag.Name)
}
func TestSchemaFromPrimitiveType(t *testing.T) {
	g := gen(t)
	schema := g.newSchemaFromType(rt(new(int64)))
	if schema.Schema == nil {
		t.Error("expected an inlined schema, got a schema reference")
	}
	assert.Equal(t, "integer", schema.Type)
	assert.Equal(t, "int64", schema.Format)
	assert.True(t, schema.Nullable)
}
func TestSchemaFromInterface(t *testing.T) {
	g := gen(t)
	schema := g.newSchemaFromType(tofEmptyInterface)
	assert.NotNil(t, schema)
	assert.Empty(t, schema.Type)
	assert.Empty(t, schema.Format)
	assert.True(t, schema.Nullable)
	assert.NotEmpty(t, schema.Description)
}
func TestSchemaFromUnsupportedType(t *testing.T) {
	g := gen(t)
	schema := g.newSchemaFromType(nil)
	assert.Nil(t, schema)
	schema = g.newSchemaFromType(rt(func() {}))
	assert.Nil(t, schema)
	assert.Len(t, g.Errors(), 1)
	assert.Implements(t, (*error)(nil), g.Errors()[0])
	assert.NotEmpty(t, g.Errors()[0])
}
func TestSchemaFromMapWithUnsupportedKeys(t *testing.T) {
	g := gen(t)
	schema := g.newSchemaFromType(rt(map[int]string{}))
	assert.Nil(t, schema)
	assert.Len(t, g.Errors(), 1)
	assert.Implements(t, (*error)(nil), g.Errors()[0])
	assert.NotEmpty(t, g.Errors()[0].Error())
}
func TestSchemaFromComplex(t *testing.T) {
	g := gen(t)
	g.UseFullSchemaNames(false)
	sor := g.newSchemaFromType(rt(new(X)))
	assert.NotNil(t, sor)
	b, err := json.Marshal(sor)
	if err != nil {
		t.Error(err)
	}
	assert.Equal(t, `{"$ref":"#/components/schemas/XXX"}`, string(b))
	schema := g.resolveSchema(sor)
	assert.NotNil(t, schema)
	actual, err := json.Marshal(schema)
	if err != nil {
		t.Error(err)
	}
	expected, err := ioutil.ReadFile("../testdata/schemas/X.json")
	if err != nil {
		t.Error(err)
	}
	m, err := diffJSON(actual, expected)
	if err != nil {
		t.Error(err)
	}
	if !m {
		t.Error("expected json outputs to be equal")
	}
	sor = g.API().Components.Schemas["Y"]
	schema = g.resolveSchema(sor)
	assert.NotNil(t, schema)
	actual, err = json.Marshal(schema)
	if err != nil {
		t.Error(err)
	}
	expected, err = ioutil.ReadFile("../testdata/schemas/Y.json")
	if err != nil {
		t.Error(err)
	}
	m, err = diffJSON(actual, expected)
	if err != nil {
		t.Error(err)
	}
	if !m {
		t.Error("expected json outputs to be equal")
	}
}
func TestNewSchemaFromStructErrors(t *testing.T) {
	g := gen(t)
	sor := g.newSchemaFromStruct(reflect.TypeOf(new(string)))
	assert.Nil(t, sor)
}