Skip to content

Commit

Permalink
Allow self.supersededBy and self.supersedes properties in a schema (c…
Browse files Browse the repository at this point in the history
…lose #155)
  • Loading branch information
spenes committed Mar 27, 2023
1 parent df99786 commit 51241ad
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ object SelfSyntaxChecker {
| "vendor": {"type":"string"},
| "name": {"type":"string"},
| "format": {"type":"string"},
| "version": {"type":"string"}
| "version": {"type":"string"},
| "supersededBy": {"type":"string"},
| "supersedes": {"type": "array","items": {"type":"string"}}
| },
| "additionalProperties": false
| },
Expand Down Expand Up @@ -125,6 +127,17 @@ object SelfSyntaxChecker {
| "version": {
| "type":"string",
| "pattern": "$versionRegex"
| },
| "supersededBy": {
| "type":"string",
| "pattern": "$versionRegex"
| },
| "supersedes": {
| "type": "array",
| "items": {
| "type":"string",
| "pattern": "$versionRegex"
| }
| }
| }
| }
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 'self.supersededBy' type" in {
val jsonSchema =
json"""{
"$$schema" : "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"description": "Schema for an example event",
"self": {
"vendor": "com.snowplowanalytics",
"name": "example_event",
"format": "jsonschema",
"version": "1-0-0",
"supersededBy": "1-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 'self.supersedes' type" in {
val jsonSchema =
json"""{
"$$schema" : "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"description": "Schema for an example event",
"self": {
"vendor": "com.snowplowanalytics",
"name": "example_event",
"format": "jsonschema",
"version": "1-0-0",
"supersedes": ["1-0-1", "1-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 'self.supersedes' and 'self.supersededBy' fields" in {
val jsonSchema =
json"""{
"$$schema" : "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"description": "Schema for an example event",
"self": {
"vendor": "com.snowplowanalytics",
"name": "example_event",
"format": "jsonschema",
"version": "1-0-0",
"supersededBy": "1-0-4",
"supersedes": ["1-0-1", "1-0-2"]
},
"type": "object",
"properties": { }
}"""

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

0 comments on commit 51241ad

Please sign in to comment.