From a5cc5f9a06447c7f118a9a9fd2828683fff528fa Mon Sep 17 00:00:00 2001 From: spenes Date: Mon, 3 Apr 2023 17:49:39 +0300 Subject: [PATCH] Allow supersededBy and supersedes properties in a schema (close #155) --- .../jsonschema/SelfSyntaxChecker.scala | 13 ++++ .../jsonschema/SelfSyntaxCheckerSpec.scala | 64 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/modules/core/src/main/scala/com.snowplowanalytics/iglu.schemaddl/jsonschema/SelfSyntaxChecker.scala b/modules/core/src/main/scala/com.snowplowanalytics/iglu.schemaddl/jsonschema/SelfSyntaxChecker.scala index e608c304..685c034e 100644 --- a/modules/core/src/main/scala/com.snowplowanalytics/iglu.schemaddl/jsonschema/SelfSyntaxChecker.scala +++ b/modules/core/src/main/scala/com.snowplowanalytics/iglu.schemaddl/jsonschema/SelfSyntaxChecker.scala @@ -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":{}, @@ -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":{ diff --git a/modules/core/src/test/scala/com/snowplowanalytics/iglu/schemaddl/jsonschema/SelfSyntaxCheckerSpec.scala b/modules/core/src/test/scala/com/snowplowanalytics/iglu/schemaddl/jsonschema/SelfSyntaxCheckerSpec.scala index ba6e02b8..10c5f5a6 100644 --- a/modules/core/src/test/scala/com/snowplowanalytics/iglu/schemaddl/jsonschema/SelfSyntaxCheckerSpec.scala +++ b/modules/core/src/test/scala/com/snowplowanalytics/iglu/schemaddl/jsonschema/SelfSyntaxCheckerSpec.scala @@ -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 + } } }