From 46523633ca41b237770955dbe7d7a6377b1e45fc Mon Sep 17 00:00:00 2001 From: erezrokah <26760571+erezrokah@users.noreply.github.com> Date: Fri, 3 Jul 2026 18:26:47 +0100 Subject: [PATCH] fix: Replace wk8/go-ordered-map with pb33f/ordered-map Matches upstream invopop/jsonschema v0.14.0, which switched to the API-compatible pb33f/ordered-map/v2 fork. Required so consumers pinning invopop v0.14.0 (e.g. anthropic-sdk-go v1.52.0) build against this fork without an OrderedMap type mismatch. The go.mod directive moves to go 1.24 (pb33f requirement), so CI is updated too: track the Go version via go-version-file, pin golangci-lint v1.64.8 (last v1 line, go 1.24 compatible) with the existing v1 config, and run Lint on pushes to cqmain (the default branch). --- .github/workflows/lint.yaml | 20 +++++++++++++------- .github/workflows/release.yaml | 3 +++ .github/workflows/test.yaml | 14 +++++++++----- .golangci.yml | 32 ++++++++++++++++++-------------- go.mod | 10 +++++----- go.sum | 24 ++++++++---------------- reflect.go | 2 +- reflect_test.go | 2 +- schema.go | 2 +- utils.go | 2 +- 10 files changed, 60 insertions(+), 51 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index a4de3ed..d4ac4f6 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -4,23 +4,29 @@ on: tags: - v* branches: + - cqmain - main pull_request: + +permissions: + contents: read + jobs: lint: name: golangci-lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v4 + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 with: - go-version: "1.18" + go-version-file: "go.mod" cache: false - - name: Check out code - uses: actions/checkout@v3 - - name: Lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: - version: v1.55 + version: v1.64.8 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7566b5f..d52e242 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -11,6 +11,9 @@ on: #paths-ignore: # - "docs/**" +permissions: + contents: write + jobs: tag-build-publish: name: Tag diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0930332..ff4eb61 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,20 +1,24 @@ name: Test Go on: [push, pull_request] + +permissions: + contents: read + jobs: lint-test-build: name: Lint, Test runs-on: ubuntu-latest steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: - go-version: "1.18" + go-version-file: "go.mod" id: go - - name: Check out code - uses: actions/checkout@v2 - - name: Install Dependencies env: GOPROXY: https://proxy.golang.org,direct diff --git a/.golangci.yml b/.golangci.yml index 3dac8a3..b9868e0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,11 +1,5 @@ run: tests: true - max-same-issues: 50 - skip-dirs: - - resources - - old - skip-files: - - cmd/protopkg/main.go output: print-issued-lines: false @@ -19,20 +13,18 @@ linters: - unconvert - goimports - unused - - vetshadow + - govet - nakedret - errcheck - revive - ineffassign - - goconst - - vet - unparam - gofmt linters-settings: - vet: - check-shadowing: true - use-installed-packages: true + govet: + enable: + - shadow dupl: threshold: 100 goconst: @@ -51,9 +43,21 @@ linters-settings: replacement: 'a[b:]' issues: - max-per-linter: 0 - max-same: 0 + max-issues-per-linter: 0 + max-same-issues: 0 exclude-use-default: false + exclude-dirs: + - resources + - old + exclude-files: + - cmd/protopkg/main.go + exclude-rules: + # Legacy comment extraction relies on go/ast and go/doc APIs that are + # deprecated but still functional; migrating to go/types is out of scope. + - path: comment_extractor\.go + linters: + - staticcheck + text: "SA1019" exclude: # Captured by errcheck. - "^(G104|G204):" diff --git a/go.mod b/go.mod index 14447f3..021d225 100644 --- a/go.mod +++ b/go.mod @@ -1,18 +1,18 @@ module github.com/invopop/jsonschema -go 1.18 +go 1.24 require ( - github.com/stretchr/testify v1.8.1 - github.com/wk8/go-ordered-map/v2 v2.1.8 + github.com/pb33f/ordered-map/v2 v2.3.1 + github.com/stretchr/testify v1.11.1 golang.org/x/exp v0.0.0-20231006140011-7918f672742d ) require ( github.com/bahlo/generic-list-go v0.2.0 // indirect - github.com/buger/jsonparser v1.1.1 // indirect + github.com/buger/jsonparser v1.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/mailru/easyjson v0.7.7 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + go.yaml.in/yaml/v4 v4.0.0-rc.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 0937aeb..1d02d31 100644 --- a/go.sum +++ b/go.sum @@ -1,28 +1,20 @@ github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= -github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= -github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/buger/jsonparser v1.1.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk= +github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/pb33f/ordered-map/v2 v2.3.1 h1:5319HDO0aw4DA4gzi+zv4FXU9UlSs3xGZ40wcP1nBjY= +github.com/pb33f/ordered-map/v2 v2.3.1/go.mod h1:qxFQgd0PkVUtOMCkTapqotNgzRhMPL7VvaHKbd1HnmQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= -github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +go.yaml.in/yaml/v4 v4.0.0-rc.2 h1:/FrI8D64VSr4HtGIlUtlFMGsm7H7pWTbj6vOLVZcA6s= +go.yaml.in/yaml/v4 v4.0.0-rc.2/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/reflect.go b/reflect.go index 02e562a..bb1c7fb 100644 --- a/reflect.go +++ b/reflect.go @@ -1168,7 +1168,7 @@ func (t *Schema) MarshalJSON() ([]byte, error) { if err != nil { return nil, err } - if t.Extras == nil || len(t.Extras) == 0 { + if len(t.Extras) == 0 { return b, nil } m, err := json.Marshal(t.Extras) diff --git a/reflect_test.go b/reflect_test.go index b01d40f..47302cf 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -454,7 +454,7 @@ func TestSchemaGeneration(t *testing.T) { {&MinValue{}, &Reflector{}, "fixtures/schema_with_minimum.json"}, {&TestNullable{}, &Reflector{}, "fixtures/nullable.json"}, {&GrandfatherType{}, &Reflector{ - AdditionalFields: func(r reflect.Type) []reflect.StructField { + AdditionalFields: func(_ reflect.Type) []reflect.StructField { return []reflect.StructField{ { Name: "Addr", diff --git a/schema.go b/schema.go index 1ccbc0f..95c8f7c 100644 --- a/schema.go +++ b/schema.go @@ -4,7 +4,7 @@ import ( "encoding/json" "reflect" - orderedmap "github.com/wk8/go-ordered-map/v2" + orderedmap "github.com/pb33f/ordered-map/v2" ) // Version is the JSON Schema version. diff --git a/utils.go b/utils.go index ed8edf7..3ae8a8e 100644 --- a/utils.go +++ b/utils.go @@ -4,7 +4,7 @@ import ( "regexp" "strings" - orderedmap "github.com/wk8/go-ordered-map/v2" + orderedmap "github.com/pb33f/ordered-map/v2" ) var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")