Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #325 from neotoolkit/bump/go
Browse files Browse the repository at this point in the history
bump golang version
  • Loading branch information
sashamelentyev authored Mar 16, 2022
2 parents 3f0969d + ec349ae commit f306153
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 86 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/neotoolkit/dummy

go 1.17
go 1.18

require (
github.com/cristalhq/acmd v0.5.7
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
30 changes: 15 additions & 15 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ type Response struct {
StatusCode int
MediaType string
Schema Schema
Example interface{}
Examples map[string]interface{}
Example any
Examples map[string]any
}

// ExampleValue -.
func (r Response) ExampleValue(key string) interface{} {
func (r Response) ExampleValue(key string) any {
if nil == r.Schema {
return nil
}
Expand All @@ -48,7 +48,7 @@ func (r Response) ExampleValue(key string) interface{} {

// Schema -.
type Schema interface {
ExampleValue() interface{}
ExampleValue() any
}

// BooleanSchema -.
Expand All @@ -57,7 +57,7 @@ type BooleanSchema struct {
}

// ExampleValue -.
func (b BooleanSchema) ExampleValue() interface{} {
func (b BooleanSchema) ExampleValue() any {
return b.Example
}

Expand All @@ -67,7 +67,7 @@ type IntSchema struct {
}

// ExampleValue -.
func (i IntSchema) ExampleValue() interface{} {
func (i IntSchema) ExampleValue() any {
return i.Example
}

Expand All @@ -77,7 +77,7 @@ type FloatSchema struct {
}

// ExampleValue -.
func (f FloatSchema) ExampleValue() interface{} {
func (f FloatSchema) ExampleValue() any {
return f.Example
}

Expand All @@ -87,7 +87,7 @@ type StringSchema struct {
}

// ExampleValue -.
func (s StringSchema) ExampleValue() interface{} {
func (s StringSchema) ExampleValue() any {
return s.Example
}

Expand All @@ -98,27 +98,27 @@ type ArraySchema struct {
}

// ExampleValue -.
func (a ArraySchema) ExampleValue() interface{} {
func (a ArraySchema) ExampleValue() any {
if len(a.Example) > 0 {
return a.Example
}

return []interface{}{a.Type.ExampleValue()}
return []any{a.Type.ExampleValue()}
}

// ObjectSchema -.
type ObjectSchema struct {
Properties map[string]Schema
Example map[string]interface{}
Example map[string]any
}

// ExampleValue -.
func (o ObjectSchema) ExampleValue() interface{} {
func (o ObjectSchema) ExampleValue() any {
if len(o.Example) > 0 {
return o.Example
}

example := make(map[string]interface{}, len(o.Properties))
example := make(map[string]any, len(o.Properties))

for key, propSchema := range o.Properties {
example[key] = propSchema.ExampleValue()
Expand All @@ -129,10 +129,10 @@ func (o ObjectSchema) ExampleValue() interface{} {

// FakerSchema -.
type FakerSchema struct {
Example interface{}
Example any
}

// ExampleValue -.
func (f FakerSchema) ExampleValue() interface{} {
func (f FakerSchema) ExampleValue() any {
return f.Example
}
46 changes: 23 additions & 23 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestSchema_ExampleValue(t *testing.T) {
tests := []struct {
name string
schema api.Schema
want interface{}
want any
}{
{
name: "boolean: default",
Expand Down Expand Up @@ -57,27 +57,27 @@ func TestSchema_ExampleValue(t *testing.T) {
{
name: "array: default",
schema: api.ArraySchema{Type: api.StringSchema{}},
want: []interface{}{""},
want: []any{""},
},
{
name: "array: with int example",
schema: api.ArraySchema{Example: []interface{}{4, 2}},
want: []interface{}{4, 2},
schema: api.ArraySchema{Example: []any{4, 2}},
want: []any{4, 2},
},
{
name: "array: with string example",
schema: api.ArraySchema{Example: []interface{}{"4", "2"}},
want: []interface{}{"4", "2"},
schema: api.ArraySchema{Example: []any{"4", "2"}},
want: []any{"4", "2"},
},
{
name: "object: default",
schema: api.ObjectSchema{},
want: map[string]interface{}{},
want: map[string]any{},
},
{
name: "object: with example",
schema: api.ObjectSchema{Example: map[string]interface{}{"a": "4", "b": "2"}},
want: map[string]interface{}{"a": "4", "b": "2"},
schema: api.ObjectSchema{Example: map[string]any{"a": "4", "b": "2"}},
want: map[string]any{"a": "4", "b": "2"},
},
}

Expand All @@ -95,13 +95,13 @@ func TestResponse_ExampleValue(t *testing.T) {
name string
response api.Response
key string
want interface{}
want any
}{
{
name: "boolean examples",
response: api.Response{
Schema: api.BooleanSchema{},
Examples: map[string]interface{}{"first": false, "second": true},
Examples: map[string]any{"first": false, "second": true},
},
key: "first",
want: false,
Expand All @@ -110,7 +110,7 @@ func TestResponse_ExampleValue(t *testing.T) {
name: "int examples",
response: api.Response{
Schema: api.IntSchema{},
Examples: map[string]interface{}{"first": int64(4), "second": int64(2)},
Examples: map[string]any{"first": int64(4), "second": int64(2)},
},
key: "first",
want: int64(4),
Expand All @@ -119,7 +119,7 @@ func TestResponse_ExampleValue(t *testing.T) {
name: "float examples",
response: api.Response{
Schema: api.FloatSchema{},
Examples: map[string]interface{}{"first": 4.0, "second": 2.0},
Examples: map[string]any{"first": 4.0, "second": 2.0},
},
key: "first",
want: 4.0,
Expand All @@ -128,7 +128,7 @@ func TestResponse_ExampleValue(t *testing.T) {
name: "string examples",
response: api.Response{
Schema: api.StringSchema{},
Examples: map[string]interface{}{"first": "abc", "second": "xyz"},
Examples: map[string]any{"first": "abc", "second": "xyz"},
},
key: "first",
want: "abc",
Expand All @@ -137,7 +137,7 @@ func TestResponse_ExampleValue(t *testing.T) {
name: "array examples",
response: api.Response{
Schema: api.ArraySchema{},
Examples: map[string]interface{}{"first": []int64{4, 2}, "second": []int64{0, 0}},
Examples: map[string]any{"first": []int64{4, 2}, "second": []int64{0, 0}},
},
key: "first",
want: []int64{4, 2},
Expand All @@ -146,27 +146,27 @@ func TestResponse_ExampleValue(t *testing.T) {
name: "object examples",
response: api.Response{
Schema: api.ObjectSchema{},
Examples: map[string]interface{}{"first": map[string]interface{}{"first": "abc"}, "second": map[string]interface{}{"first": "xyz"}},
Examples: map[string]any{"first": map[string]any{"first": "abc"}, "second": map[string]any{"first": "xyz"}},
},
key: "first",
want: map[string]interface{}{"first": "abc"},
},
{
name: "use schema example",
response: api.Response{
Examples: map[string]interface{}{"first": map[string]interface{}{"first": "abc"}, "second": map[string]interface{}{"first": "xyz"}},
Examples: map[string]any{"first": map[string]any{"first": "abc"}, "second": map[string]any{"first": "xyz"}},
Schema: api.ObjectSchema{
Example: map[string]interface{}{"first": "schema variant"},
Example: map[string]any{"first": "schema variant"},
},
},
key: "third",
want: map[string]interface{}{"first": "schema variant"},
want: map[string]any{"first": "schema variant"},
},
{
name: "nil schema",
response: api.Response{
Schema: nil,
Examples: map[string]interface{}{"first": false, "second": true},
Examples: map[string]any{"first": false, "second": true},
},
key: "first",
want: nil,
Expand All @@ -175,10 +175,10 @@ func TestResponse_ExampleValue(t *testing.T) {
name: "example",
response: api.Response{
Schema: api.ObjectSchema{},
Example: map[string]interface{}{"first": "abc", "second": "def"},
Example: map[string]any{"first": "abc", "second": "def"},
},
key: "",
want: map[string]interface{}{"first": "abc", "second": "def"},
want: map[string]any{"first": "abc", "second": "def"},
},
{
name: "object properties",
Expand All @@ -190,7 +190,7 @@ func TestResponse_ExampleValue(t *testing.T) {
},
},
key: "",
want: map[string]interface{}{"key": map[string]interface{}{}},
want: map[string]any{"key": map[string]any{}},
},
{
name: "faker schema",
Expand Down
22 changes: 11 additions & 11 deletions internal/api/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ var ErrEmptyItems = errors.New("empty items in array")

// ArrayExampleError -.
type ArrayExampleError struct {
Data interface{}
Data any
}

func (e *ArrayExampleError) Error() string {
return fmt.Sprintf("unpredicted type for example %T", e.Data)
}

func ParseArrayExample(data interface{}) ([]interface{}, error) {
func ParseArrayExample(data any) ([]any, error) {
if nil == data {
return []interface{}{}, nil
return []any{}, nil
}

d, ok := data.([]interface{})
d, ok := data.([]any)
if ok {
res := make([]interface{}, len(d))
res := make([]any, len(d))
for k, v := range d {
res[k] = v.(map[string]interface{})
res[k] = v.(map[string]any)
}

return res, nil
Expand All @@ -53,20 +53,20 @@ func ParseArrayExample(data interface{}) ([]interface{}, error) {

// ObjectExampleError -.
type ObjectExampleError struct {
Data interface{}
Data any
}

// Error -.
func (e *ObjectExampleError) Error() string {
return fmt.Sprintf("unpredicted type for example %T", e.Data)
}

func ParseObjectExample(data interface{}) (map[string]interface{}, error) {
func ParseObjectExample(data any) (map[string]any, error) {
if nil == data {
return map[string]interface{}{}, nil
return map[string]any{}, nil
}

d, ok := data.(map[string]interface{})
d, ok := data.(map[string]any)
if ok {
return d, nil
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func (b *Builder) Set(path, method string, o *openapi.Operation) (Operation, err

example := openapi.ExampleToResponse(content.Example)

examples := make(map[string]interface{}, len(content.Examples)+1)
examples := make(map[string]any, len(content.Examples)+1)

if len(content.Examples) > 0 {
for key, e := range content.Examples {
Expand Down
24 changes: 12 additions & 12 deletions internal/api/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ func TestArrayExampleError(t *testing.T) {
func TestParseArrayExample(t *testing.T) {
tests := []struct {
name string
data interface{}
want []interface{}
data any
want []any
err error
}{
{
name: "nil data",
data: nil,
want: []interface{}{},
want: []any{},
err: nil,
},
{
name: "array",
data: []interface{}{
map[string]interface{}{
data: []any{
map[string]any{
"key": "value",
},
},
want: []interface{}{
map[string]interface{}{
want: []any{
map[string]any{
"key": "value",
},
},
Expand Down Expand Up @@ -87,20 +87,20 @@ func TestObjectExampleError(t *testing.T) {
func TestParseObjectExample(t *testing.T) {
tests := []struct {
name string
data interface{}
want map[string]interface{}
data any
want map[string]any
err error
}{
{
name: "nil data",
data: nil,
want: map[string]interface{}{},
want: map[string]any{},
err: nil,
},
{
name: "object",
data: map[string]interface{}{},
want: map[string]interface{}{},
data: map[string]any{},
want: map[string]any{},
err: nil,
},
{
Expand Down
Loading

0 comments on commit f306153

Please sign in to comment.