Skip to content

Commit 05a909b

Browse files
committed
Update version: support for draft6 and draft4
1 parent 85b657d commit 05a909b

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
kotlin = "2.0.0"
3-
json-schema-validator = "0.2.0"
3+
json-schema-validator = "0.2.1"
44

55
[plugins]
66
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

src/main/kotlin/BowtieSampsonSchemaValidatorLauncher.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import com.eygraber.uri.Uri
12
import io.github.optimumcode.json.schema.ErrorCollector
23
import io.github.optimumcode.json.schema.JsonSchema
34
import io.github.optimumcode.json.schema.JsonSchemaLoader
@@ -35,6 +36,8 @@ fun main() {
3536
}
3637

3738
private val SUPPORTED_DIALECTS: Set<String> = hashSetOf(
39+
"http://json-schema.org/draft-04/schema#",
40+
"http://json-schema.org/draft-06/schema#",
3841
"http://json-schema.org/draft-07/schema#",
3942
"https://json-schema.org/draft/2019-09/schema",
4043
"https://json-schema.org/draft/2020-12/schema",
@@ -122,30 +125,30 @@ class BowtieSampsonSchemaValidatorLauncher(
122125
.apply {
123126
currentDialect?.also(this::registerWellKnown)
124127
for ((uri, schema) in command.case.registry) {
125-
if (skipSchema(uri, schema)) {
128+
if (skipSchema(schema)) {
126129
continue
127130
}
131+
var schemaType: SchemaType? = null
132+
if (uri.contains("draft4", ignoreCase = true)) {
133+
// remote schema for draft 4 does not contain $schema block
134+
schemaType = SchemaType.DRAFT_4
135+
}
128136
@Suppress("detekt:TooGenericExceptionCaught")
129137
try {
130-
register(schema, uri)
138+
register(schema, Uri.parse(uri), schemaType)
131139
} catch (ex: Exception) {
132140
throw IllegalStateException("cannot register schema for URI '$uri'", ex)
133141
}
134142
}
135143
}.fromJsonElement(schemaDefinition, currentDialect)
136144

137-
private fun skipSchema(uri: String, schema: JsonElement): Boolean {
138-
if (uri.contains("draft4", ignoreCase = true)) {
139-
// skip draft4 schemas
140-
return true
141-
}
145+
private fun skipSchema(schema: JsonElement): Boolean =
142146
// ignore schemas for unsupported drafts
143-
return schema is JsonObject &&
147+
schema is JsonObject &&
144148
schema["\$schema"]
145149
?.jsonPrimitive
146150
?.content
147151
.let { it != null && SchemaType.find(it) == null }
148-
}
149152

150153
private fun runCase(command: Command.Run, schema: JsonSchema) {
151154
val results: List<TestResult> = command.case.tests.map { test ->

src/main/kotlin/TestFilters.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ interface TestFilter {
1414

1515
fun getFilter(schemaType: SchemaType?): TestFilter =
1616
when (schemaType ?: SchemaType.entries.last()) {
17+
SchemaType.DRAFT_4 -> TestFilterDraft4
18+
SchemaType.DRAFT_6 -> TestFilterDraft6
1719
SchemaType.DRAFT_7 -> TestFilterDraft7
1820
SchemaType.DRAFT_2019_09 -> TestFilterDraft201909
1921
SchemaType.DRAFT_2020_12 -> TestFilterDraft202012
2022
}
2123

24+
object TestFilterDraft4 : TestFilter
25+
26+
object TestFilterDraft6 : TestFilter
27+
2228
object TestFilterDraft7 : TestFilter
2329

2430
object TestFilterDraft201909 : TestFilter {

0 commit comments

Comments
 (0)