|
| 1 | +import com.eygraber.uri.Uri |
1 | 2 | import io.github.optimumcode.json.schema.ErrorCollector
|
2 | 3 | import io.github.optimumcode.json.schema.JsonSchema
|
3 | 4 | import io.github.optimumcode.json.schema.JsonSchemaLoader
|
@@ -35,6 +36,8 @@ fun main() {
|
35 | 36 | }
|
36 | 37 |
|
37 | 38 | private val SUPPORTED_DIALECTS: Set<String> = hashSetOf(
|
| 39 | + "http://json-schema.org/draft-04/schema#", |
| 40 | + "http://json-schema.org/draft-06/schema#", |
38 | 41 | "http://json-schema.org/draft-07/schema#",
|
39 | 42 | "https://json-schema.org/draft/2019-09/schema",
|
40 | 43 | "https://json-schema.org/draft/2020-12/schema",
|
@@ -122,30 +125,30 @@ class BowtieSampsonSchemaValidatorLauncher(
|
122 | 125 | .apply {
|
123 | 126 | currentDialect?.also(this::registerWellKnown)
|
124 | 127 | for ((uri, schema) in command.case.registry) {
|
125 |
| - if (skipSchema(uri, schema)) { |
| 128 | + if (skipSchema(schema)) { |
126 | 129 | continue
|
127 | 130 | }
|
| 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 | + } |
128 | 136 | @Suppress("detekt:TooGenericExceptionCaught")
|
129 | 137 | try {
|
130 |
| - register(schema, uri) |
| 138 | + register(schema, Uri.parse(uri), schemaType) |
131 | 139 | } catch (ex: Exception) {
|
132 | 140 | throw IllegalStateException("cannot register schema for URI '$uri'", ex)
|
133 | 141 | }
|
134 | 142 | }
|
135 | 143 | }.fromJsonElement(schemaDefinition, currentDialect)
|
136 | 144 |
|
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 = |
142 | 146 | // ignore schemas for unsupported drafts
|
143 |
| - return schema is JsonObject && |
| 147 | + schema is JsonObject && |
144 | 148 | schema["\$schema"]
|
145 | 149 | ?.jsonPrimitive
|
146 | 150 | ?.content
|
147 | 151 | .let { it != null && SchemaType.find(it) == null }
|
148 |
| - } |
149 | 152 |
|
150 | 153 | private fun runCase(command: Command.Run, schema: JsonSchema) {
|
151 | 154 | val results: List<TestResult> = command.case.tests.map { test ->
|
|
0 commit comments