Skip to content

Commit

Permalink
upgade go 1.24 (#655)
Browse files Browse the repository at this point in the history
* upgade to go 1.24
* update deps
* fix bug: lowercase response headers
  • Loading branch information
reuvenharrison authored Feb 23, 2025
1 parent 8cc3ac9 commit 647c0c3
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: true
matrix:
go: ['1.23']
go: ['1.24']
os:
- ubuntu-latest
- windows-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v5
with:
go-version: '1.23'
go-version: '1.24'
cache: false
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23"
go-version: "1.24"
id: go

- name: Run GoReleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vuln.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- id: govulncheck
uses: golang/govulncheck-action@v1
with:
go-version-input: 1.23
go-version-input: 1.24
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### Go get dependecies and build ###
FROM golang:1.23 as builder
FROM golang:1.24 as builder
ENV PLATFORM docker
WORKDIR /go/src/app
COPY go.mod go.sum ./
Expand Down
12 changes: 12 additions & 0 deletions checker/localizations/lang_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package localizations_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker/localizations"
)

func TestLang_Exists(t *testing.T) {
require.Equal(t, []string{localizations.LangEn, localizations.LangRu}, localizations.GetSupportedLanguages())
}
43 changes: 43 additions & 0 deletions checker/localizations/localizations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package localizations_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker/localizations"
)

func TestLocalizations_ExistsNoSunstitute(t *testing.T) {
locales := localizations.New(localizations.LangEn, localizations.LangDefault)
require.Equal(t, "the %s response's property pattern was changed from %s to %s for the status %s", locales.Get("messages.response-property-pattern-changed"))
}

func TestLocalizations_SetLocal(t *testing.T) {
locales := localizations.New(localizations.LangEn, localizations.LangDefault).SetLocale(localizations.LangEn)
require.Equal(t, "the %s response's property pattern was changed from %s to %s for the status %s", locales.Get("messages.response-property-pattern-changed"))
}

func TestLocalizations_SetFallbackLocal(t *testing.T) {
locales := localizations.New(localizations.LangEn, localizations.LangDefault).SetFallbackLocale(localizations.LangEn)
require.Equal(t, "the %s response's property pattern was changed from %s to %s for the status %s", locales.Get("messages.response-property-pattern-changed"))
}

func TestLocalizations_SetLocals(t *testing.T) {
locales := localizations.New(localizations.LangEn, localizations.LangDefault).SetLocales(localizations.LangEn, localizations.LangEn)
require.Equal(t, "the %s response's property pattern was changed from %s to %s for the status %s", locales.Get("messages.response-property-pattern-changed"))
}

func TestLocalizations_NotExists(t *testing.T) {
locales := localizations.New(localizations.LangEn, localizations.LangDefault)
require.Equal(t, "invalid", locales.Get("invalid"))
}

func TestLocalizations_ExistsWithSunstitute(t *testing.T) {
locales := localizations.New(localizations.LangEn, localizations.LangDefault)
locales.Localizations = map[string]string{
"en.messages.response-property-pattern-changed": "{{/* a comment */}}",
}

replacements := localizations.Replacements{}
require.Equal(t, "", locales.Get("messages.response-property-pattern-changed", &replacements))
}
10 changes: 9 additions & 1 deletion data/header-case/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ paths:
get:
tags:
- Test
parameters:
- in: header
name: X-Case
responses:
"200":
description: Success
description: Success
headers:
X-RateLimit-Limit:
schema:
type: integer
description: Request limit per hour.
10 changes: 9 additions & 1 deletion data/header-case/revision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ paths:
get:
tags:
- Test
parameters:
- in: header
name: x-case
responses:
"200":
description: Success
description: Success
headers:
x-ratelimit-limit:
schema:
type: integer
description: Request limit per hour.
31 changes: 31 additions & 0 deletions flatten/commonparams/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package commonparams_test

import (
"net/http"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/flatten/commonparams"
)

func TestMove(t *testing.T) {
spec := &openapi3.T{}
spec.Paths = openapi3.NewPathsWithCapacity(1)
spec.Paths.Set("/path", &openapi3.PathItem{
Parameters: openapi3.Parameters{
&openapi3.ParameterRef{
Value: &openapi3.Parameter{
Name: "X-Header",
In: "query",
},
},
},
})
spec.Paths.Find("/path").SetOperation(http.MethodGet, &openapi3.Operation{})

commonparams.Move(spec)

require.Empty(t, spec.Paths.Find("/path").Parameters.GetByInAndName("query", "X-Header"))
require.NotEmpty(t, spec.Paths.Find("/path").Get.Parameters.GetByInAndName("query", "X-Header"))
}
18 changes: 15 additions & 3 deletions flatten/headers/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ func lowerHeaderNames(spec *openapi3.T) {
}

for _, responseRef := range op.Responses.Map() {
for _, headerRef := range responseRef.Value.Headers {
lowerHeaderName(&headerRef.Value.Parameter)
}
responseRef.Value.Headers = lowerResponseHeaders(responseRef.Value.Headers)
}
}
}
Expand All @@ -39,3 +37,17 @@ func lowerHeaderName(param *openapi3.Parameter) {

param.Name = strings.ToLower(param.Name)
}

// lowerResponseHeaders returns a new headers map with lowercase keys
// Explanation:
// According to the openapi spec, the Header Object follows the structure of the Parameter Object with the following changes:
// 1. name MUST NOT be specified, it is given in the corresponding headers map.
// 2. in MUST NOT be specified, it is implicitly in header.
// See: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#header-object
func lowerResponseHeaders(headers openapi3.Headers) openapi3.Headers {
result := make(openapi3.Headers, len(headers))
for k, v := range headers {
result[strings.ToLower(k)] = v
}
return result
}
92 changes: 92 additions & 0 deletions flatten/headers/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package headers_test

import (
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/flatten/headers"
)

func TestLowercaseInPath(t *testing.T) {
spec := &openapi3.T{}
spec.Paths = openapi3.NewPathsWithCapacity(1)
spec.Paths.Set("/path", &openapi3.PathItem{
Parameters: openapi3.Parameters{
&openapi3.ParameterRef{
Value: &openapi3.Parameter{
Name: "X-Header",
In: "query",
},
},
},
})

headers.Lowercase(spec)

require.Equal(t, "X-Header", spec.Paths.Find("/path").Parameters[0].Value.Name)
}

func TestLowercaseNonHeader(t *testing.T) {
spec := &openapi3.T{}
spec.Paths = openapi3.NewPathsWithCapacity(1)
spec.Paths.Set("/path", &openapi3.PathItem{
Parameters: openapi3.Parameters{
&openapi3.ParameterRef{
Value: &openapi3.Parameter{
Name: "X-Header",
In: "header",
},
},
},
})

headers.Lowercase(spec)

require.Equal(t, "x-header", spec.Paths.Find("/path").Parameters[0].Value.Name)
}

func TestLowercaseInOperation(t *testing.T) {
spec := &openapi3.T{}
spec.Paths = openapi3.NewPathsWithCapacity(1)
spec.Paths.Set("/path", &openapi3.PathItem{
Get: &openapi3.Operation{
Parameters: openapi3.Parameters{
&openapi3.ParameterRef{
Value: &openapi3.Parameter{
Name: "X-Header",
In: "header",
},
},
},
},
})

headers.Lowercase(spec)

require.Equal(t, "x-header", spec.Paths.Find("/path").GetOperation("GET").Parameters[0].Value.Name)
}

func TestLowercaseInResponse(t *testing.T) {
spec := &openapi3.T{}
spec.Paths = openapi3.NewPathsWithCapacity(1)
spec.Paths.Set("/path", &openapi3.PathItem{
Get: &openapi3.Operation{},
})
spec.Paths.Find("/path").GetOperation("GET").Responses = openapi3.NewResponsesWithCapacity(1)
spec.Paths.Find("/path").GetOperation("GET").Responses.Set("default", &openapi3.ResponseRef{
Value: &openapi3.Response{
Headers: openapi3.Headers{
"X-Header": &openapi3.HeaderRef{
Value: &openapi3.Header{
Parameter: openapi3.Parameter{},
},
},
},
},
})

headers.Lowercase(spec)

require.Contains(t, spec.Paths.Find("/path").GetOperation("GET").Responses.Default().Value.Headers, "x-header")
}
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
module github.com/tufin/oasdiff

go 1.23
go 1.24

require (
cloud.google.com/go v0.118.2
cloud.google.com/go v0.118.3
github.com/TwiN/go-color v1.4.1
github.com/getkin/kin-openapi v0.129.0
github.com/spf13/pflag v1.0.6
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/yargevad/filepathx v1.0.0
github.com/yuin/goldmark v1.7.8
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/magiconair/properties v1.8.9 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oasdiff/yaml v0.0.0-20241210131133-6b86fb107d80 // indirect
github.com/oasdiff/yaml3 v0.0.0-20241210130736-a94c01f36349 // indirect
github.com/oasdiff/yaml v0.0.0-20241214135536-5f7845c759c8 // indirect
github.com/oasdiff/yaml3 v0.0.0-20241214160948-977117996672 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)

Expand All @@ -47,7 +47,7 @@ require (
github.com/go-openapi/swag v0.23.0 // indirect
github.com/iancoleman/strcase v0.3.0
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down
Loading

0 comments on commit 647c0c3

Please sign in to comment.