Fix incorrect canonical string comparison
The canonical string for these reference is empty and not "#". Also
added a simple test that this functionality works.
diff --git a/schema.go b/schema.go
index 6f60147..bf9b69f 100644
--- a/schema.go
+++ b/schema.go
@@ -50,10 +50,10 @@
d := Schema{}
d.pool = newSchemaPool(l.LoaderFactory())
d.documentReference = ref
- d.referencePool=newSchemaReferencePool()
+ d.referencePool = newSchemaReferencePool()
var doc interface{}
- if ref.String() != "#" {
+ if ref.String() != "" {
// Get document from schema pool
spd, err := d.pool.GetDocument(d.documentReference)
if err != nil {
diff --git a/schema_test.go b/schema_test.go
index 2a1832c..f79962d 100644
--- a/schema_test.go
+++ b/schema_test.go
@@ -414,3 +414,31 @@
fmt.Printf("\n%d tests performed / %d total tests to perform ( %.2f %% )\n", len(JsonSchemaTestSuiteMap), 248, float32(len(JsonSchemaTestSuiteMap))/248.0*100.0)
}
+
+// From http://json-schema.org/examples.html
+const simpleSchema = `{
+ "title": "Example Schema",
+ "type": "object",
+ "properties": {
+ "firstName": {
+ "type": "string"
+ },
+ "lastName": {
+ "type": "string"
+ },
+ "age": {
+ "description": "Age in years",
+ "type": "integer",
+ "minimum": 0
+ }
+ },
+ "required": ["firstName", "lastName"]
+}`
+
+func TestNewStringLoader(t *testing.T) {
+ loader := NewStringLoader(simpleSchema)
+ _, err := NewSchema(loader)
+ if err != nil {
+ t.Errorf("Got error: %s", err.Error())
+ }
+}