diff --git a/doc_test.go b/doc_test.go index 53bcb13..8d51eb9 100644 --- a/doc_test.go +++ b/doc_test.go @@ -41,9 +41,10 @@ func ExampleSpec() { func ExampleSpec_second() { // Example with high level spec validation call, without showing warnings - // Example with online spec URL: - url := "http://petstore.swagger.io/v2/swagger.json" - doc, err := loads.JSONSpec(url) + // Example with the bundled Petstore spec: + // Also works with URL, e.g. http://petstore.swagger.io/v2/swagger.json + path := "fixtures/go-swagger/canary/petstore/swagger.json" + doc, err := loads.JSONSpec(path) if err == nil { validate.SetContinueOnErrors(true) // Set global options errs := validate.Spec(doc, strfmt.Default) // Validates spec with default Swagger 2.0 format definitions @@ -96,9 +97,10 @@ func ExampleSpecValidator_Validate() { func ExampleSpecValidator_Validate_url() { // Example of spec validation call with full result - // Example with online spec URL: - url := "http://petstore.swagger.io/v2/swagger.json" - doc, err := loads.JSONSpec(url) + // Example with the bundled Petstore spec: + // Also works with URL, e.g. http://petstore.swagger.io/v2/swagger.json + path := "fixtures/go-swagger/canary/petstore/swagger.json" + doc, err := loads.JSONSpec(path) if err == nil { validator := validate.NewSpecValidator(doc.Schema(), strfmt.Default) validator.SetContinueOnErrors(true) // Set option for this validator diff --git a/jsonschema_test.go b/jsonschema_test.go index faf547a..55ba1db 100644 --- a/jsonschema_test.go +++ b/jsonschema_test.go @@ -5,6 +5,8 @@ package validate import ( "encoding/json" + "errors" + "net" "net/http" "os" "path/filepath" @@ -97,15 +99,18 @@ func isExtendedEnabled(nm string) bool { func TestJSONSchemaSuite(t *testing.T) { // Internal local server to serve remote $ref + svr := &http.Server{ + ReadTimeout: 5 * time.Second, + WriteTimeout: 10 * time.Second, + Handler: http.FileServer(http.Dir(jsonSchemaFixturesPath + "/remotes")), + } + listener, err := new(net.ListenConfig).Listen(t.Context(), "tcp", "localhost:1234") + require.NoError(t, err) + t.Cleanup(func() { + require.NoError(t, svr.Close()) + }) go func() { - svr := &http.Server{ - ReadTimeout: 5 * time.Second, - WriteTimeout: 10 * time.Second, - Addr: "localhost:1234", - Handler: http.FileServer(http.Dir(jsonSchemaFixturesPath + "/remotes")), - } - err := svr.ListenAndServe() - if err != nil { + if err := svr.Serve(listener); err != nil && !errors.Is(err, http.ErrServerClosed) { panic(err.Error()) } }()