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

Update CI #106

Merged
merged 2 commits into from
Feb 23, 2024
Merged
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 .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
GO111MODULE: "on"
CACHE_BENCHMARK: "off" # Enables benchmark result reuse between runs, may skew latency results.
RUN_BASE_BENCHMARK: "on" # Runs benchmark for PR base in case benchmark result is missing.
GO_VERSION: 1.21.x
GO_VERSION: 1.22.x
jobs:
bench:
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.21.x
go-version: 1.22.x
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.7.0
uses: golangci/golangci-lint-action@v4.0.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.54.1
version: v1.56.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ concurrency:
cancel-in-progress: true

env:
GO_VERSION: 1.21.x
GO_VERSION: 1.22.x
jobs:
gorelease:
runs-on: ubuntu-latest
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ concurrency:
env:
GO111MODULE: "on"
RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing.
COV_GO_VERSION: 1.21.x # Version of Go to collect coverage
COV_GO_VERSION: 1.22.x # Version of Go to collect coverage
TARGET_DELTA_COV: 90 # Target coverage of changed lines, in percents
jobs:
test:
strategy:
matrix:
go-version: [ 1.13.x, 1.20.x, 1.21.x ]
go-version: [ 1.13.x, 1.21.x, 1.22.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go stable
Expand Down Expand Up @@ -88,9 +88,9 @@ jobs:
id: annotate
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
run: |
curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.4.0/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && rm linux_amd64.tar.gz
curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.4.2/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && rm linux_amd64.tar.gz
gocovdiff_hash=$(git hash-object ./gocovdiff)
[ "$gocovdiff_hash" == "f191b45548bb65ec2c7d88909679a57116ff1ba1" ] || (echo "::error::unexpected hash for gocovdiff, possible tampering: $gocovdiff_hash" && exit 1)
[ "$gocovdiff_hash" == "c37862c73a677e5a9c069470287823ab5bbf0244" ] || (echo "::error::unexpected hash for gocovdiff, possible tampering: $gocovdiff_hash" && exit 1)
git fetch origin master ${{ github.event.pull_request.base.sha }}
REP=$(./gocovdiff -mod github.com/$GITHUB_REPOSITORY -cov unit.coverprofile -gha-annotations gha-unit.txt -delta-cov-file delta-cov-unit.txt -target-delta-cov ${TARGET_DELTA_COV})
echo "${REP}"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#GOLANGCI_LINT_VERSION := "v1.54.1" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v1.56.2" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
Expand Down
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func RootRef(rc *ReflectContext) {
// and removes first encountered.
func StripDefinitionNamePrefix(prefix ...string) func(rc *ReflectContext) {
return func(rc *ReflectContext) {
rc.DefName = func(t reflect.Type, defaultDefName string) string {
rc.DefName = func(_ reflect.Type, defaultDefName string) string {
for _, p := range prefix {
s := strings.TrimPrefix(defaultDefName, p)
s = strings.ReplaceAll(s, "["+p, "[")
Expand Down
9 changes: 5 additions & 4 deletions date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/swaggest/jsonschema-go"
)

func TestDate_MarshalText(t *testing.T) {
var d jsonschema.Date

assert.NoError(t, d.UnmarshalText([]byte("2021-05-08")))
require.NoError(t, d.UnmarshalText([]byte("2021-05-08")))
b, err := d.MarshalText()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, "2021-05-08", string(b))

assert.Error(t, d.UnmarshalText([]byte("2021-05-088")))
Expand All @@ -21,9 +22,9 @@ func TestDate_MarshalText(t *testing.T) {
func TestDate_MarshalJSON(t *testing.T) {
var d jsonschema.Date

assert.NoError(t, d.UnmarshalJSON([]byte(`"2021-05-08"`)))
require.NoError(t, d.UnmarshalJSON([]byte(`"2021-05-08"`)))
b, err := d.MarshalJSON()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `"2021-05-08"`, string(b))

assert.Error(t, d.UnmarshalJSON([]byte(`""2021-05-088"`)))
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func ExampleReflector_Reflect() {

// Modify default definition names to better match your packages structure.
reflector.DefaultOptions = append(reflector.DefaultOptions, jsonschema.InterceptDefName(
func(t reflect.Type, defaultDefName string) string {
func(_ reflect.Type, defaultDefName string) string {
return strings.TrimPrefix(defaultDefName, "JsonschemaGoTest")
},
))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/swaggest/jsonschema-go
go 1.18

require (
github.com/bool64/dev v0.2.31
github.com/bool64/dev v0.2.34
github.com/stretchr/testify v1.8.2
github.com/swaggest/assertjson v1.9.0
github.com/swaggest/refl v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/bool64/dev v0.2.31 h1:OS57EqYaYe2M/2bw9uhDCIFiZZwywKFS/4qMLN6JUmQ=
github.com/bool64/dev v0.2.31/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/dev v0.2.34 h1:P9n315P8LdpxusnYQ0X7MP1CZXwBK5ae5RZrd+GdSZE=
github.com/bool64/dev v0.2.34/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestSchema_IsTrivial(t *testing.T) {
t.Run(s.name, func(t *testing.T) {
var schema jsonschema.SchemaOrBool

assert.NoError(t, json.Unmarshal([]byte(s.schema), &schema))
require.NoError(t, json.Unmarshal([]byte(s.schema), &schema))
assert.Equal(t, s.isTrivial, schema.IsTrivial())
})
}
Expand Down
2 changes: 1 addition & 1 deletion reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ func (r *Reflector) kindSwitch(t reflect.Type, v reflect.Value, schema *Schema,
func MakePropertyNameMapping(v interface{}, tagName string) map[string]string {
res := make(map[string]string)

refl.WalkTaggedFields(reflect.ValueOf(v), func(v reflect.Value, sf reflect.StructField, tag string) {
refl.WalkTaggedFields(reflect.ValueOf(v), func(_ reflect.Value, sf reflect.StructField, tag string) {
res[sf.Name] = tag
}, tagName)

Expand Down
36 changes: 18 additions & 18 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func TestReflector_Reflect_mapping(t *testing.T) {
rf := jsonschema.Reflector{}
rf.AddTypeMapping(simpleTestReplacement{}, "")
rf.DefaultOptions = append(rf.DefaultOptions, jsonschema.InterceptDefName(
func(t reflect.Type, defaultDefName string) string {
func(_ reflect.Type, defaultDefName string) string {
return strings.TrimPrefix(defaultDefName, "JsonschemaGoTest")
},
))
Expand Down Expand Up @@ -713,7 +713,7 @@ func TestPreparer(t *testing.T) {
r := jsonschema.Reflector{}

s, err := r.Reflect(nullFloat{})
assert.NoError(t, err)
require.NoError(t, err)
assertjson.EqualMarshal(t, []byte(`{"type":["null", "number"]}`), s)
}

Expand All @@ -726,7 +726,7 @@ func TestReflector_Reflect_inclineScalar(t *testing.T) {

r := jsonschema.Reflector{}
s, err := r.Reflect(topTracesInput{})
assert.NoError(t, err)
require.NoError(t, err)
assertjson.EqualMarshal(t, []byte(`{
"properties":{
"rootSymbol":{"default":"main()","examples":["my_func"],"minLength":5,"type":"string"}
Expand All @@ -745,7 +745,7 @@ func TestReflector_Reflect_MapOfOptionals(t *testing.T) {

r := jsonschema.Reflector{}
s, err := r.Reflect(Optionals{})
assert.NoError(t, err)
require.NoError(t, err)
assertjson.EqualMarshal(t, []byte(`{
"properties":{
"map":{
Expand All @@ -768,7 +768,7 @@ func TestReflector_Reflect_InlineValue(t *testing.T) {

r := jsonschema.Reflector{}
s, err := r.Reflect(InlineValues{})
assert.NoError(t, err)
require.NoError(t, err)

assertjson.EqualMarshal(t, []byte(`{
"properties":{
Expand Down Expand Up @@ -827,7 +827,7 @@ func TestReflector_Reflect_sub_schema(t *testing.T) {
r := jsonschema.Reflector{}

s, err := r.Reflect(WithSubSchemas{}, jsonschema.StripDefinitionNamePrefix("JsonschemaGoTest"))
assert.NoError(t, err)
require.NoError(t, err)

assertjson.EqMarshal(t, `{
"definitions":{
Expand Down Expand Up @@ -881,7 +881,7 @@ func TestReflector_Reflect_jsonEmptyName(t *testing.T) {
r := jsonschema.Reflector{}

s, err := r.Reflect(Test{})
assert.NoError(t, err)
require.NoError(t, err)

assertjson.EqualMarshal(t, []byte(`{
"properties":{"Bar":{"type":"integer"},"Foo":{"type":"string"}},
Expand All @@ -900,7 +900,7 @@ func TestReflector_Reflect_processWithoutTags_true(t *testing.T) {
r := jsonschema.Reflector{}

s, err := r.Reflect(Test{}, jsonschema.ProcessWithoutTags)
assert.NoError(t, err)
require.NoError(t, err)

assertjson.EqualMarshal(t, []byte(`{
"properties":{"Bar":{"type":"integer"},"Foo":{"type":"string"},"baz":{"type":"boolean"}},
Expand All @@ -921,7 +921,7 @@ func TestReflector_Reflect_processWithoutTags_tolerateUnknownTypes(t *testing.T)
r := jsonschema.Reflector{}

s, err := r.Reflect(Test{}, jsonschema.ProcessWithoutTags, jsonschema.SkipUnsupportedProperties)
assert.NoError(t, err)
require.NoError(t, err)

assertjson.EqualMarshal(t, []byte(`{
"properties":{"Bar":{"type":"integer"},"Foo":{"type":"string"},"baz":{"type":"boolean"}},
Expand All @@ -940,7 +940,7 @@ func TestReflector_Reflect_processWithoutTags_false(t *testing.T) {
r := jsonschema.Reflector{}

s, err := r.Reflect(Test{})
assert.NoError(t, err)
require.NoError(t, err)

assertjson.EqualMarshal(t, []byte(`{
"properties":{"baz":{"type":"boolean"}},
Expand All @@ -961,7 +961,7 @@ func TestReflector_Reflect_parentTags(t *testing.T) {
r := jsonschema.Reflector{}

s, err := r.Reflect(Test{})
assert.NoError(t, err)
require.NoError(t, err)

assertjson.EqualMarshal(t, []byte(`{
"title":"Test","description":"This is a test.","additionalProperties":false,
Expand All @@ -972,7 +972,7 @@ func TestReflector_Reflect_parentTags(t *testing.T) {
_, err = r.Reflect(struct {
_ string `additionalProperties:"abc"`
}{})
assert.EqualError(t, err, "failed to parse bool value abc in tag additionalProperties: strconv.ParseBool: parsing \"abc\": invalid syntax")
require.EqualError(t, err, "failed to parse bool value abc in tag additionalProperties: strconv.ParseBool: parsing \"abc\": invalid syntax")

_, err = r.Reflect(struct {
_ string `minProperties:"abc"`
Expand All @@ -996,7 +996,7 @@ func TestReflector_Reflect_parentTagsFiltered(t *testing.T) {
rc.UnnamedFieldWithTag = true
rc.PropertyNameTag = "json"
})
assert.NoError(t, err)
require.NoError(t, err)

// No parent schema update for json, as tag is missing in unnamed field.
assertjson.EqualMarshal(t, []byte(`{"properties":{"foo":{"type":"string"}},"type":"object"}`), s)
Expand All @@ -1005,7 +1005,7 @@ func TestReflector_Reflect_parentTagsFiltered(t *testing.T) {
rc.UnnamedFieldWithTag = true
rc.PropertyNameTag = "query"
})
assert.NoError(t, err)
require.NoError(t, err)

// Parent schema is updated for query, as tag is present in unnamed field.
assertjson.EqualMarshal(t, []byte(`{
Expand All @@ -1017,12 +1017,12 @@ func TestReflector_Reflect_parentTagsFiltered(t *testing.T) {
_, err = r.Reflect(struct {
_ string `additionalProperties:"abc"`
}{})
assert.EqualError(t, err, "failed to parse bool value abc in tag additionalProperties: strconv.ParseBool: parsing \"abc\": invalid syntax")
require.EqualError(t, err, "failed to parse bool value abc in tag additionalProperties: strconv.ParseBool: parsing \"abc\": invalid syntax")

_, err = r.Reflect(struct {
_ string `minProperties:"abc"`
}{})
assert.EqualError(t, err, "failed to parse int value abc in tag minProperties: strconv.ParseInt: parsing \"abc\": invalid syntax")
require.EqualError(t, err, "failed to parse int value abc in tag minProperties: strconv.ParseInt: parsing \"abc\": invalid syntax")
}

func TestReflector_Reflect_context(t *testing.T) {
Expand Down Expand Up @@ -1521,7 +1521,7 @@ func TestReflector_Reflect_example(t *testing.T) {

// Modify default definition names to better match your packages structure.
reflector.DefaultOptions = append(reflector.DefaultOptions, jsonschema.InterceptDefName(
func(t reflect.Type, defaultDefName string) string {
func(_ reflect.Type, defaultDefName string) string {
return strings.TrimPrefix(defaultDefName, "JsonschemaGoTest")
},
))
Expand Down Expand Up @@ -1579,7 +1579,7 @@ func TestReflector_Reflect_inlineRefs_typeCycle(t *testing.T) {

gen, err := ref.Reflect(&ExampleEvent{}, jsonschema.InlineRefs)

assert.NoError(t, err)
require.NoError(t, err)
assertjson.EqMarshal(t, `{
"properties":{
"current_data":{
Expand Down
Loading