Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exp/go json #184

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion circular_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package spec

import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"time"

json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
3 changes: 1 addition & 2 deletions contact_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
package spec

import (
"encoding/json"

"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
)

// ContactInfo contact information for the exposed API.
Expand Down
14 changes: 7 additions & 7 deletions contact_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
package spec

import (
"encoding/json"
"testing"

json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const contactInfoJSON = `{
"name": "wordnik api team",
"url": "http://developer.wordnik.com",
"email": "[email protected]",
"x-teams": "test team"
"name": "wordnik api team",
"url": "http://developer.wordnik.com",
"email": "[email protected]",
"x-teams": "test team"
}`

var contactInfo = ContactInfo{ContactInfoProps: ContactInfoProps{
Expand All @@ -36,9 +36,9 @@ var contactInfo = ContactInfo{ContactInfoProps: ContactInfoProps{
}, VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{"x-teams": "test team"}}}

func TestIntegrationContactInfo(t *testing.T) {
b, err := json.MarshalIndent(contactInfo, "", "\t")
b, err := json.MarshalIndent(contactInfo, "", " ")
require.NoError(t, err)
assert.Equal(t, contactInfoJSON, string(b))
assert.JSONEq(t, contactInfoJSON, string(b))

actual := ContactInfo{}
err = json.Unmarshal([]byte(contactInfoJSON), &actual)
Expand Down
3 changes: 2 additions & 1 deletion expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package spec

import (
"encoding/json"
"fmt"

json "github.com/goccy/go-json"
)

// ExpandOptions provides options for the spec expander.
Expand Down
2 changes: 1 addition & 1 deletion expander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package spec

import (
"encoding/json"
"io"
"log"
"net/http"
Expand All @@ -24,6 +23,7 @@ import (
"path/filepath"
"testing"

json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require (
github.com/go-openapi/jsonpointer v0.20.2
github.com/go-openapi/jsonreference v0.20.4
github.com/go-openapi/swag v0.22.6
github.com/goccy/go-json v0.10.2
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/go-openapi/jsonreference v0.20.4 h1:bKlDxQxQJgwpUSgOENiMPzCTBVuc7vTdX
github.com/go-openapi/jsonreference v0.20.4/go.mod h1:5pZJyJP2MnYCpoeoMAql78cCHauHj0V9Lhc506VOpw4=
github.com/go-openapi/swag v0.22.6 h1:dnqg1XfHXL9aBxSbktBqFR5CxVyVI+7fYWhAf1JOeTw=
github.com/go-openapi/swag v0.22.6/go.mod h1:Gl91UqO+btAM0plGGxHqJcQZ1ZTy6jbmridBTsDy8A0=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down
2 changes: 1 addition & 1 deletion header.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package spec

import (
"encoding/json"
"strings"

"github.com/go-openapi/jsonpointer"
"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package spec

import (
"encoding/json"
"testing"

"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion helpers_spec_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package spec_test

import (
"encoding/json"
"fmt"
"regexp"
"strings"
"testing"

"github.com/go-openapi/spec"
"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package spec

import (
"encoding/json"
"fmt"
"regexp"
"strings"
"testing"

"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
7 changes: 5 additions & 2 deletions info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package spec

import (
"encoding/json"
"strconv"
"strings"

"github.com/go-openapi/jsonpointer"
"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
)

// Extensions vendor specific extensions
Expand Down Expand Up @@ -118,7 +118,10 @@ func (v VendorExtensible) MarshalJSON() ([]byte, error) {

// UnmarshalJSON for this extensible object
func (v *VendorExtensible) UnmarshalJSON(data []byte) error {
var d map[string]interface{}
d := poolOfMaps.BorrowMap()
defer func() {
poolOfMaps.RedeemMap(d)
}()
if err := json.Unmarshal(data, &d); err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package spec

import (
"encoding/json"
"testing"

json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -57,9 +57,9 @@ var info = Info{
}

func TestIntegrationInfo_Serialize(t *testing.T) {
b, err := json.MarshalIndent(info, "", "\t")
b, err := json.MarshalIndent(info, "", " ")
require.NoError(t, err)
assert.Equal(t, infoJSON, string(b))
assert.JSONEq(t, infoJSON, string(b))
}

func TestIntegrationInfo_Deserialize(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion items.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package spec

import (
"encoding/json"
"strings"

"github.com/go-openapi/jsonpointer"
"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package spec

import (
"encoding/json"
"testing"

"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
3 changes: 1 addition & 2 deletions license.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
package spec

import (
"encoding/json"

"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
)

// License information for the exposed API.
Expand Down
6 changes: 3 additions & 3 deletions license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package spec

import (
"encoding/json"
"testing"

json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -36,9 +36,9 @@ func TestIntegrationLicense(t *testing.T) {

// const licenseYAML = "name: the name\nurl: the url\n"

b, err := json.MarshalIndent(license, "", "\t")
b, err := json.MarshalIndent(license, "", " ")
require.NoError(t, err)
assert.Equal(t, licenseJSON, string(b))
assert.JSONEq(t, licenseJSON, string(b))

actual := License{}
err = json.Unmarshal([]byte(licenseJSON), &actual)
Expand Down
2 changes: 1 addition & 1 deletion operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package spec
import (
"bytes"
"encoding/gob"
"encoding/json"
"sort"

"github.com/go-openapi/jsonpointer"
"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package spec
import (
"bytes"
"encoding/gob"
"encoding/json"
"testing"

json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package spec

import (
"encoding/json"
"strings"

"github.com/go-openapi/jsonpointer"
"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
)

// QueryParam creates a query parameter
Expand Down
2 changes: 1 addition & 1 deletion parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package spec

import (
"encoding/json"
"testing"

"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
3 changes: 1 addition & 2 deletions path_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
package spec

import (
"encoding/json"

"github.com/go-openapi/jsonpointer"
"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
)

// PathItemProps the path item specific properties
Expand Down
2 changes: 1 addition & 1 deletion path_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package spec

import (
"encoding/json"
"testing"

json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package spec

import (
"encoding/json"
"fmt"
"strings"

"github.com/go-openapi/swag"
json "github.com/goccy/go-json"
)

// Paths holds the relative paths to the individual endpoints.
Expand Down
2 changes: 1 addition & 1 deletion paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package spec

import (
"encoding/json"
"testing"

json "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
3 changes: 2 additions & 1 deletion properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package spec

import (
"bytes"
"encoding/json"
"reflect"
"sort"

json "github.com/goccy/go-json"
)

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