Skip to content

Commit 73720f1

Browse files
committed
WIP: using go-json
Signed-off-by: Frederic BIDON <[email protected]>
1 parent 096f80c commit 73720f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+70
-50
lines changed

cache.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ package spec
1616

1717
import (
1818
"sync"
19-
20-
jsoniter "github.com/json-iterator/go"
2119
)
2220

2321
// ResolutionCache a cache for resolving urls
@@ -73,19 +71,14 @@ var (
7371
resCache *simpleCache
7472
onceCache sync.Once
7573

76-
_ ResolutionCache = &simpleCache{}
77-
json jsoniter.API
74+
_ ResolutionCache = &simpleCache{}
7875
)
7976

8077
// initResolutionCache initializes the URI resolution cache. To be wrapped in a sync.Once.Do call.
8178
func initResolutionCache() {
8279
resCache = defaultResolutionCache()
8380
}
8481

85-
func init() {
86-
json = jsoniter.ConfigFastest
87-
}
88-
8982
func defaultResolutionCache() *simpleCache {
9083
return &simpleCache{store: map[string]interface{}{
9184
"http://swagger.io/v2/schema.json": MustLoadSwagger20Schema(),

circular_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"time"
1010

11+
json "github.com/goccy/go-json"
1112
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314
)

contact_info.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package spec
1616

1717
import (
1818
"github.com/go-openapi/swag"
19+
json "github.com/goccy/go-json"
1920
)
2021

2122
// ContactInfo contact information for the exposed API.

contact_info_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package spec
1717
import (
1818
"testing"
1919

20+
json "github.com/goccy/go-json"
2021
"github.com/stretchr/testify/assert"
2122
"github.com/stretchr/testify/require"
2223
)

expander.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
package spec
1616

1717
import (
18-
stdjson "encoding/json"
1918
"fmt"
19+
20+
json "github.com/goccy/go-json"
2021
)
2122

2223
// ExpandOptions provides options for the spec expander.
@@ -28,11 +29,11 @@ import (
2829
//
2930
// PathLoader injects a document loading method. By default, this resolves to the function provided by the SpecLoader package variable.
3031
type ExpandOptions struct {
31-
RelativeBase string // the path to the root document to expand. This is a file, not a directory
32-
SkipSchemas bool // do not expand schemas, just paths, parameters and responses
33-
ContinueOnError bool // continue expanding even after and error is found
34-
PathLoader func(string) (stdjson.RawMessage, error) `json:"-"` // the document loading method that takes a path as input and yields a json document
35-
AbsoluteCircularRef bool // circular $ref remaining after expansion remain absolute URLs
32+
RelativeBase string // the path to the root document to expand. This is a file, not a directory
33+
SkipSchemas bool // do not expand schemas, just paths, parameters and responses
34+
ContinueOnError bool // continue expanding even after and error is found
35+
PathLoader func(string) (json.RawMessage, error) `json:"-"` // the document loading method that takes a path as input and yields a json document
36+
AbsoluteCircularRef bool // circular $ref remaining after expansion remain absolute URLs
3637
}
3738

3839
func optionsOrDefault(opts *ExpandOptions) *ExpandOptions {

expander_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package spec
1616

1717
import (
18-
stdjson "encoding/json"
1918
"io"
2019
"log"
2120
"net/http"
@@ -24,6 +23,7 @@ import (
2423
"path/filepath"
2524
"testing"
2625

26+
json "github.com/goccy/go-json"
2727
"github.com/stretchr/testify/assert"
2828
"github.com/stretchr/testify/require"
2929
)
@@ -38,7 +38,7 @@ const (
3838

3939
var (
4040
// PetStoreJSONMessage json raw message for Petstore20
41-
PetStoreJSONMessage = stdjson.RawMessage([]byte(PetStore20))
41+
PetStoreJSONMessage = json.RawMessage([]byte(PetStore20))
4242
specs = filepath.Join("fixtures", "specs")
4343
)
4444

go.mod

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require (
44
github.com/go-openapi/jsonpointer v0.20.2
55
github.com/go-openapi/jsonreference v0.20.4
66
github.com/go-openapi/swag v0.22.6
7-
github.com/json-iterator/go v1.1.12
7+
github.com/goccy/go-json v0.10.2
88
github.com/stretchr/testify v1.8.4
99
gopkg.in/yaml.v3 v3.0.1
1010
)
@@ -13,8 +13,6 @@ require (
1313
github.com/davecgh/go-spew v1.1.1 // indirect
1414
github.com/josharian/intern v1.0.0 // indirect
1515
github.com/mailru/easyjson v0.7.7 // indirect
16-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
17-
github.com/modern-go/reflect2 v1.0.2 // indirect
1816
github.com/pmezard/go-difflib v1.0.0 // indirect
1917
)
2018

go.sum

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
21
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
32
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
43
github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q=
@@ -7,25 +6,17 @@ github.com/go-openapi/jsonreference v0.20.4 h1:bKlDxQxQJgwpUSgOENiMPzCTBVuc7vTdX
76
github.com/go-openapi/jsonreference v0.20.4/go.mod h1:5pZJyJP2MnYCpoeoMAql78cCHauHj0V9Lhc506VOpw4=
87
github.com/go-openapi/swag v0.22.6 h1:dnqg1XfHXL9aBxSbktBqFR5CxVyVI+7fYWhAf1JOeTw=
98
github.com/go-openapi/swag v0.22.6/go.mod h1:Gl91UqO+btAM0plGGxHqJcQZ1ZTy6jbmridBTsDy8A0=
10-
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
9+
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
10+
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
1111
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
1212
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
13-
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
14-
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
1513
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1614
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1715
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
1816
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
19-
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
20-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
21-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
22-
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
23-
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
2417
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2518
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2619
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
27-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
28-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
2920
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
3021
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
3122
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

header.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/go-openapi/jsonpointer"
2121
"github.com/go-openapi/swag"
22+
json "github.com/goccy/go-json"
2223
)
2324

2425
const (

header_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"testing"
1919

2020
"github.com/go-openapi/swag"
21+
json "github.com/goccy/go-json"
2122
"github.com/stretchr/testify/assert"
2223
"github.com/stretchr/testify/require"
2324
)

helpers_spec_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
package spec_test
22

33
import (
4-
"encoding/json"
5-
stdjson "encoding/json"
64
"fmt"
75
"regexp"
86
"strings"
97
"testing"
108

119
"github.com/go-openapi/spec"
1210
"github.com/go-openapi/swag"
11+
json "github.com/goccy/go-json"
1312
"github.com/stretchr/testify/assert"
1413
"github.com/stretchr/testify/require"
1514
)
1615

1716
var (
1817
rex = regexp.MustCompile(`"\$ref":\s*"(.*?)"`)
19-
testLoader func(string) (stdjson.RawMessage, error)
18+
testLoader func(string) (json.RawMessage, error)
2019
)
2120

2221
func init() {
2322
// mimics what the go-openapi/load does
24-
testLoader = func(path string) (stdjson.RawMessage, error) {
23+
testLoader = func(path string) (json.RawMessage, error) {
2524
if swag.YAMLMatcher(path) {
2625
return swag.YAMLDoc(path)
2726
}
2827
data, err := swag.LoadFromFileOrHTTP(path)
2928
if err != nil {
3029
return nil, err
3130
}
32-
return stdjson.RawMessage(data), nil
31+
return json.RawMessage(data), nil
3332
}
3433
}
3534

helpers_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package spec
22

33
import (
4-
stdjson "encoding/json"
54
"fmt"
65
"regexp"
76
"strings"
87
"testing"
98

109
"github.com/go-openapi/swag"
10+
json "github.com/goccy/go-json"
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
1313
)
1414

1515
var rex = regexp.MustCompile(`"\$ref":\s*"(.*?)"`)
1616

17-
func jsonDoc(path string) (stdjson.RawMessage, error) {
17+
func jsonDoc(path string) (json.RawMessage, error) {
1818
data, err := swag.LoadFromFileOrHTTP(path)
1919
if err != nil {
2020
return nil, err
2121
}
22-
return stdjson.RawMessage(data), nil
22+
return json.RawMessage(data), nil
2323
}
2424

2525
func docAndOpts(t testing.TB, fixturePath string) ([]byte, *ExpandOptions) {

info.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/go-openapi/jsonpointer"
2222
"github.com/go-openapi/swag"
23+
json "github.com/goccy/go-json"
2324
)
2425

2526
// Extensions vendor specific extensions

info_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package spec
1717
import (
1818
"testing"
1919

20+
json "github.com/goccy/go-json"
2021
"github.com/stretchr/testify/assert"
2122
"github.com/stretchr/testify/require"
2223
)

items.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/go-openapi/jsonpointer"
2121
"github.com/go-openapi/swag"
22+
json "github.com/goccy/go-json"
2223
)
2324

2425
const (

items_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"testing"
1919

2020
"github.com/go-openapi/swag"
21+
json "github.com/goccy/go-json"
2122
"github.com/stretchr/testify/assert"
2223
"github.com/stretchr/testify/require"
2324
)

license.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package spec
1616

1717
import (
1818
"github.com/go-openapi/swag"
19+
json "github.com/goccy/go-json"
1920
)
2021

2122
// License information for the exposed API.

license_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package spec
1717
import (
1818
"testing"
1919

20+
json "github.com/goccy/go-json"
2021
"github.com/stretchr/testify/assert"
2122
"github.com/stretchr/testify/require"
2223
)

operation.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/go-openapi/jsonpointer"
2323
"github.com/go-openapi/swag"
24+
json "github.com/goccy/go-json"
2425
)
2526

2627
func init() {

operation_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/gob"
2020
"testing"
2121

22+
json "github.com/goccy/go-json"
2223
"github.com/stretchr/testify/assert"
2324
"github.com/stretchr/testify/require"
2425
)

parameter.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/go-openapi/jsonpointer"
2121
"github.com/go-openapi/swag"
22+
json "github.com/goccy/go-json"
2223
)
2324

2425
// QueryParam creates a query parameter

parameters_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"testing"
1919

2020
"github.com/go-openapi/swag"
21+
json "github.com/goccy/go-json"
2122
"github.com/stretchr/testify/assert"
2223
"github.com/stretchr/testify/require"
2324
)

path_item.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package spec
1717
import (
1818
"github.com/go-openapi/jsonpointer"
1919
"github.com/go-openapi/swag"
20+
json "github.com/goccy/go-json"
2021
)
2122

2223
// PathItemProps the path item specific properties

path_item_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package spec
1717
import (
1818
"testing"
1919

20+
json "github.com/goccy/go-json"
2021
"github.com/stretchr/testify/assert"
2122
"github.com/stretchr/testify/require"
2223
)

paths.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ import (
1818
"fmt"
1919
"strings"
2020

21-
stdjson "encoding/json"
22-
2321
"github.com/go-openapi/swag"
22+
json "github.com/goccy/go-json"
2423
)
2524

2625
// Paths holds the relative paths to the individual endpoints.
@@ -47,7 +46,7 @@ func (p Paths) JSONLookup(token string) (interface{}, error) {
4746

4847
// UnmarshalJSON hydrates this items instance with the data from JSON
4948
func (p *Paths) UnmarshalJSON(data []byte) error {
50-
var res map[string]stdjson.RawMessage
49+
var res map[string]json.RawMessage
5150
if err := json.Unmarshal(data, &res); err != nil {
5251
return err
5352
}

paths_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package spec
1717
import (
1818
"testing"
1919

20+
json "github.com/goccy/go-json"
2021
"github.com/stretchr/testify/assert"
2122
"github.com/stretchr/testify/require"
2223
)

properties.go

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"bytes"
55
"reflect"
66
"sort"
7+
8+
json "github.com/goccy/go-json"
79
)
810

911
// OrderSchemaItem holds a named schema (e.g. from a property of an object)

ref.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"path/filepath"
2323

2424
"github.com/go-openapi/jsonreference"
25+
json "github.com/goccy/go-json"
2526
)
2627

2728
// Refable is a struct for things that accept a $ref property

ref_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/gob"
2020
"testing"
2121

22+
json "github.com/goccy/go-json"
2223
"github.com/stretchr/testify/assert"
2324
"github.com/stretchr/testify/require"
2425
)

resolver_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/go-openapi/jsonpointer"
11+
json "github.com/goccy/go-json"
1112
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314
)

0 commit comments

Comments
 (0)