Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from nikhita/update-aug-18
update for final evaluation
- Loading branch information
Showing
19 changed files
with
597 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
notes/go-jsonschema-validator-benchmark/go-jsonschema_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package validator_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/xeipuuv/gojsonschema" | ||
) | ||
|
||
func BenchmarkGoJSONSchema(b *testing.B) { | ||
schemaLoader := gojsonschema.NewReferenceLoader("schema4.json") | ||
documentLoader := gojsonschema.NewReferenceLoader("valid.json") | ||
|
||
for i := 0; i < b.N; i++ { | ||
result, err := gojsonschema.Validate(schemaLoader, documentLoader) | ||
if err != nil { | ||
b.Error(err) | ||
} | ||
if !result.Valid() { | ||
b.Errorf("It is invalid!!!") | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
notes/go-jsonschema-validator-benchmark/go-openapi_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package validator_test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
"io/ioutil" | ||
|
||
"github.com/go-openapi/spec" | ||
"github.com/go-openapi/strfmt" | ||
"github.com/go-openapi/validate" | ||
) | ||
|
||
type schemaTestT struct { | ||
Description string `json:"description"` | ||
Schema *spec.Schema `json:"schema"` | ||
Tests []struct { | ||
Description string `json:"description"` | ||
Data interface{} `json:"data"` | ||
Valid bool `json:"valid"` | ||
} | ||
} | ||
|
||
func TestOpenAPI(t *testing.T) { | ||
file, _ := ioutil.ReadFile("openapi-data.json") | ||
var testDescriptions []schemaTestT | ||
json.Unmarshal(file, &testDescriptions) | ||
|
||
for _, testDescription := range testDescriptions { | ||
// Expand the refs | ||
err := spec.ExpandSchema(testDescription.Schema, nil, nil /*new(noopResCache)*/) | ||
if err != nil { | ||
t.Errorf("should expland clearly: %v", err) | ||
} | ||
|
||
// create the validator | ||
validator := validate.NewSchemaValidator(testDescription.Schema, nil, "data", strfmt.Default) | ||
|
||
// validate against each test | ||
for _, test := range testDescription.Tests { | ||
result := validator.Validate(test.Data) | ||
fmt.Println(test.Data) | ||
if result.AsError() != nil { | ||
t.Error(result.AsError()) | ||
} | ||
} | ||
|
||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
notes/go-jsonschema-validator-benchmark/gojsonschema-benchmark.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Benchmarks | ||
|
||
Bechmarks for validation using: | ||
1. go-openapi | ||
2. go-jsonschema | ||
|
||
Note: The files in this directory were *not* used for testing. Standard test data for JSON Schema validation was used. However, the JSON files in this directory are provided as examples. | ||
|
||
``` | ||
BenchmarkOpenAPI-4 5000 240116 ns/op 71790 B/op 649 allocs/op | ||
BenchmarkGoJSONSchema-4 5000 314191 ns/op 66629 B/op 965 allocs/op | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[ | ||
{ | ||
"description": "maximum validation", | ||
"schema": { | ||
"$schema": "http: //json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"description": "This is an example schema", | ||
"required": [ | ||
"foo" | ||
], | ||
"properties": { | ||
"foo": { | ||
"description": "Foo is a string", | ||
"type": "string", | ||
"default": "abc" | ||
} | ||
} | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "below the maximum is valid", | ||
"bar": { | ||
"foo": "hello" | ||
}, | ||
"valid": true | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name" : "test", | ||
"type" : "object", | ||
"additionalProperties" : false, | ||
"required" : ["fullName", "age", "zip", "married", "dozen", "dozenOrBakersDozen", "favoriteEvenNumber", "topThreeFavoriteColors", "favoriteSingleDigitWholeNumbers", "favoriteFiveLetterWord", "emailAddresses", "ipAddresses"], | ||
"properties" : | ||
{ | ||
"fullName" : { "type" : "string" }, | ||
"age" : { "type" : "integer", "minimum" : 0 }, | ||
"optionalItem" : { "type" : "string" }, | ||
"state" : { "type" : "string" }, | ||
"city" : { "type" : "string" }, | ||
"zip" : { "type" : "integer", "minimum" : 0, "maximum" : 99999 }, | ||
"married" : { "type" : "boolean" }, | ||
"dozen" : { "type" : "integer", "minimum" : 12, "maximum" : 12 }, | ||
"dozenOrBakersDozen" : { "type" : "integer", "minimum" : 12, "maximum" : 13 }, | ||
"favoriteEvenNumber" : { "type" : "integer", "multipleOf" : 2 }, | ||
"topThreeFavoriteColors" : { "type" : "array", "minItems" : 3, "maxItems" : 3, "uniqueItems" : true, "items" : { "type" : "string" }}, | ||
"favoriteSingleDigitWholeNumbers" : { "type" : "array", "minItems" : 1, "maxItems" : 10, "uniqueItems" : true, "items" : { "type" : "integer", "minimum" : 0, "maximum" : 9 }}, | ||
"favoriteFiveLetterWord" : { "type" : "string", "minLength" : 5, "maxLength" : 5 }, | ||
"emailAddresses" : { "type" : "array", "minItems" : 1, "uniqueItems" : true, "items" : { "type" : "string", "format" : "email" }}, | ||
"ipAddresses" : { "type" : "array", "uniqueItems" : true, "items" : { "type" : "string", "format" : "ipv4" }} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"fullName" : "John Doe", | ||
"age" : 47, | ||
"state" : "Massachusetts", | ||
"city" : "Boston", | ||
"zip" : 16417, | ||
"married" : false, | ||
"dozen" : 12, | ||
"dozenOrBakersDozen" : 13, | ||
"favoriteEvenNumber" : 14, | ||
"topThreeFavoriteColors" : [ "red", "blue", "green" ], | ||
"favoriteSingleDigitWholeNumbers" : [ 7 ], | ||
"favoriteFiveLetterWord" : "coder", | ||
"emailAddresses" : | ||
[ | ||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org", | ||
"01234567890@numbers-in-local.net", | ||
"&'*+-./=?^_{}~@other-valid-characters-in-local.net", | ||
"mixed-1234-in-{+^}-local@sld.net", | ||
"one-character-third-level@a.example.com", | ||
"single-character-in-sld@x.org", | ||
"local@dash-in-sld.com", | ||
"letters-in-sld@123.com", | ||
"one-letter-sld@x.org", | ||
"uncommon-tld@sld.museum", | ||
"uncommon-tld@sld.travel", | ||
"uncommon-tld@sld.mobi", | ||
"country-code-tld@sld.uk", | ||
"country-code-tld@sld.rw", | ||
"local@sld.newTLD", | ||
"the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-254-characters-exactly.so-it-should-be-valid.and-im-going-to-add-some-more-words-here.to-increase-the-lenght-blah-blah-blah-blah-bla.org", | ||
"the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-three-characters-so-it-is-valid-blah-blah.com", | ||
"local@sub.domains.com" | ||
], | ||
"ipAddresses" : [ "127.0.0.1", "24.48.64.2", "192.168.1.1", "209.68.44.3", "2.2.2.2" ] | ||
} |
Oops, something went wrong.