Skip to content

Commit

Permalink
Allow supersededBy and supersedes properties in a schema (close #155)
Browse files Browse the repository at this point in the history
  • Loading branch information
spenes committed Apr 3, 2023
1 parent df99786 commit a5cc5f9
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ object SelfSyntaxChecker {
| },
| "id":{"type":"string"},
| "$schema":{"type":"string"},
| "$supersededBy": {"type":"string"},
| "$supersedes": {"type": "array","items": {"type":"string"}},
| "title":{"type":"string"},
| "description":{"type":"string"},
| "default":{},
Expand Down Expand Up @@ -107,6 +109,17 @@ object SelfSyntaxChecker {
| "type":"string",
| "enum": ["$MetaSchemaUri"]
| },
| "$$supersededBy": {
| "type":"string",
| "pattern": "$versionRegex"
| },
| "$$supersedes": {
| "type": "array",
| "items": {
| "type":"string",
| "pattern": "$versionRegex"
| }
| },
| "self":{
| "required": ["vendor", "name", "format", "version"],
| "properties":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,69 @@ class SelfSyntaxCheckerSpec extends Specification {

}.reduce(_ and _)
}

"recognize invalid 'supersededBy' type" in {
val jsonSchema =
json"""{
"$$schema" : "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"$$supersededBy": "1-0",
"description": "Schema for an example event",
"self": {
"vendor": "com.snowplowanalytics",
"name": "example_event",
"format": "jsonschema",
"version": "1-0-0"
},
"type": "object",
"properties": { }
}"""

SelfSyntaxChecker.validateSchema(jsonSchema).toEither must beLeft.like {
case NonEmptyList(Message(_, msg, Error), Nil) =>
msg must contain("does not match the regex pattern")
}
}

"recognize invalid 'supersedes' type" in {
val jsonSchema =
json"""{
"$$schema" : "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"$$supersedes": ["1-0-1", "1-0"],
"description": "Schema for an example event",
"self": {
"vendor": "com.snowplowanalytics",
"name": "example_event",
"format": "jsonschema",
"version": "1-0-0"
},
"type": "object",
"properties": { }
}"""

SelfSyntaxChecker.validateSchema(jsonSchema).toEither must beLeft.like {
case NonEmptyList(Message(_, msg, Error), Nil) =>
msg must contain("does not match the regex pattern")
}
}

"allow valid 'supersedes' and 'supersededBy' fields" in {
val jsonSchema =
json"""{
"$$schema" : "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"$$supersededBy": "1-0-4",
"$$supersedes": ["1-0-1", "1-0-2"],
"description": "Schema for an example event",
"self": {
"vendor": "com.snowplowanalytics",
"name": "example_event",
"format": "jsonschema",
"version": "1-0-0"
},
"type": "object",
"properties": { }
}"""

SelfSyntaxChecker.validateSchema(jsonSchema).toEither must beRight
}
}
}

0 comments on commit a5cc5f9

Please sign in to comment.