diff --git a/compiler.go b/compiler.go index 942114e..64440fd 100644 --- a/compiler.go +++ b/compiler.go @@ -415,7 +415,6 @@ func (c *Compiler) compileMap(r *resource, stack []schemaRef, sref schemaRef, re switch jsonType(item) { case "object", "array": allPrimitives = false - break } } s.enumError = "enum failed" @@ -681,7 +680,7 @@ func (c *Compiler) compileMap(r *resource, stack []schemaRef, sref schemaRef, re if format, ok := c.Formats[s.Format]; ok { s.format = format } else { - s.format, _ = Formats[s.Format] + s.format = Formats[s.Format] } } } @@ -708,7 +707,7 @@ func (c *Compiler) compileMap(r *resource, stack []schemaRef, sref schemaRef, re if decoder, ok := c.Decoders[s.ContentEncoding]; ok { s.decoder = decoder } else { - s.decoder, _ = Decoders[s.ContentEncoding] + s.decoder = Decoders[s.ContentEncoding] } } if mediaType, ok := m["contentMediaType"]; ok { @@ -716,7 +715,7 @@ func (c *Compiler) compileMap(r *resource, stack []schemaRef, sref schemaRef, re if mediaType, ok := c.MediaTypes[s.ContentMediaType]; ok { s.mediaType = mediaType } else { - s.mediaType, _ = MediaTypes[s.ContentMediaType] + s.mediaType = MediaTypes[s.ContentMediaType] } if s.ContentSchema, err = loadSchema("contentSchema", stack); err != nil { return err diff --git a/example_test.go b/example_test.go index 68b27da..8de21ce 100644 --- a/example_test.go +++ b/example_test.go @@ -6,8 +6,8 @@ import ( "encoding/xml" "fmt" "io" - "io/ioutil" "log" + "os" "strconv" "strings" @@ -20,7 +20,7 @@ func Example() { log.Fatalf("%#v", err) } - data, err := ioutil.ReadFile("testdata/person.json") + data, err := os.ReadFile("testdata/person.json") if err != nil { log.Fatal(err) } @@ -173,7 +173,7 @@ func Example_userDefinedLoader() { if !ok { return nil, fmt.Errorf("%q not found", url) } - return ioutil.NopCloser(strings.NewReader(schema)), nil + return io.NopCloser(strings.NewReader(schema)), nil } sch, err := jsonschema.Compile("map:///main.json") diff --git a/format.go b/format.go index 0568607..4ee1830 100644 --- a/format.go +++ b/format.go @@ -220,7 +220,7 @@ func isDuration(v interface{}) bool { return len(s) == 0 // P_W } if len(units) > 0 { - if strings.Index("YMD", units) == -1 { + if !strings.Contains("YMD", units) { return false } if len(s) == 0 { @@ -232,7 +232,7 @@ func isDuration(v interface{}) bool { } s = s[1:] units, ok = parseUnits() - return ok && len(s) == 0 && len(units) > 0 && strings.Index("HMS", units) != -1 + return ok && len(s) == 0 && len(units) > 0 && strings.Contains("HMS", units) } // isPeriod tells whether given string is a valid period format diff --git a/schema_test.go b/schema_test.go index 539f1dd..eabb1c4 100644 --- a/schema_test.go +++ b/schema_test.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -178,17 +177,6 @@ func TestExtra(t *testing.T) { }) } -type testGroup struct { - Description string - Schema json.RawMessage - Tests []struct { - Description string - Data json.RawMessage - Valid bool - Skip *string - } -} - func TestMain(m *testing.M) { server1 := &http.Server{Addr: "localhost:1234", Handler: http.FileServer(http.Dir("testdata/JSON-Schema-Test-Suite/remotes"))} go func() { @@ -206,26 +194,26 @@ func TestMain(m *testing.M) { } func testFolder(t *testing.T, folder string, draft *jsonschema.Draft) { - fis, err := ioutil.ReadDir(folder) + des, err := os.ReadDir(folder) if err != nil { t.Fatal(err) } - for _, fi := range fis { - if fi.IsDir() { - t.Run(fi.Name(), func(t *testing.T) { - testFolder(t, path.Join(folder, fi.Name()), draft) + for _, de := range des { + if de.IsDir() { + t.Run(de.Name(), func(t *testing.T) { + testFolder(t, path.Join(folder, de.Name()), draft) }) continue } - if path.Ext(fi.Name()) != ".json" { + if path.Ext(de.Name()) != ".json" { continue } - t.Run(fi.Name(), func(t *testing.T) { + t.Run(de.Name(), func(t *testing.T) { skip := skipTests[t.Name()] if skip != nil && len(skip) == 0 { t.Skip() } - f, err := os.Open(path.Join(folder, fi.Name())) + f, err := os.Open(path.Join(folder, de.Name())) if err != nil { t.Fatal(err) } @@ -252,7 +240,7 @@ func testFolder(t *testing.T, folder string, draft *jsonschema.Draft) { } c := jsonschema.NewCompiler() c.Draft = draft - if strings.Index(folder, "optional") != -1 { + if strings.Contains(folder, "optional") { c.AssertFormat = true c.AssertContent = true } @@ -357,7 +345,7 @@ func TestInvalidSchema(t *testing.T) { Schema json.RawMessage Fragment string } - data, err := ioutil.ReadFile("testdata/invalid_schemas.json") + data, err := os.ReadFile("testdata/invalid_schemas.json") if err != nil { t.Fatal(err) } @@ -653,9 +641,9 @@ func TestCompiler_LoadURL(t *testing.T) { c.LoadURL = func(s string) (io.ReadCloser, error) { switch s { case "map:///base.json": - return ioutil.NopCloser(strings.NewReader(base)), nil + return io.NopCloser(strings.NewReader(base)), nil case "map:///schema.json": - return ioutil.NopCloser(strings.NewReader(schema)), nil + return io.NopCloser(strings.NewReader(schema)), nil default: return nil, errors.New("unsupported schema") } @@ -688,7 +676,7 @@ func TestSchemaDraftFeild(t *testing.T) { if !ok { return nil, fmt.Errorf("%q not found", url) } - return ioutil.NopCloser(strings.NewReader(schema)), nil + return io.NopCloser(strings.NewReader(schema)), nil } sch, err := jsonschema.Compile("map:///main.json")