Skip to content
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
14 changes: 8 additions & 6 deletions doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Comment thread
fredbi marked this conversation as resolved.
// 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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions jsonschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package validate

import (
"encoding/json"
"errors"
"net"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -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())
}
}()
Expand Down
Loading