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
4
5
import io.github.optimumcode.json.schema.SchemaType
6
+ import kotlinx.serialization.ExperimentalSerializationApi
5
7
import kotlinx.serialization.encodeToString
6
8
import kotlinx.serialization.json.ClassDiscriminatorMode
7
9
import kotlinx.serialization.json.Json
@@ -14,6 +16,7 @@ import java.io.InputStreamReader
14
16
import java.util.jar.Attributes
15
17
import java.util.jar.Manifest
16
18
19
+ @OptIn(ExperimentalSerializationApi ::class )
17
20
fun main () {
18
21
val input = BufferedReader (InputStreamReader (System .`in `))
19
22
val outputWriter = System .out .bufferedWriter()
@@ -35,6 +38,8 @@ fun main() {
35
38
}
36
39
37
40
private val SUPPORTED_DIALECTS : Set <String > = hashSetOf(
41
+ " http://json-schema.org/draft-04/schema#" ,
42
+ " http://json-schema.org/draft-06/schema#" ,
38
43
" http://json-schema.org/draft-07/schema#" ,
39
44
" https://json-schema.org/draft/2019-09/schema" ,
40
45
" https://json-schema.org/draft/2020-12/schema" ,
@@ -122,30 +127,30 @@ class BowtieSampsonSchemaValidatorLauncher(
122
127
.apply {
123
128
currentDialect?.also (this ::registerWellKnown)
124
129
for ((uri, schema) in command.case.registry) {
125
- if (skipSchema(uri, schema)) {
130
+ if (skipSchema(schema)) {
126
131
continue
127
132
}
133
+ var schemaType: SchemaType ? = null
134
+ if (uri.contains(" draft4" , ignoreCase = true )) {
135
+ // remote schema for draft 4 does not contain $schema block
136
+ schemaType = SchemaType .DRAFT_4
137
+ }
128
138
@Suppress(" detekt:TooGenericExceptionCaught" )
129
139
try {
130
- register(schema, uri)
140
+ register(schema, Uri .parse( uri), schemaType )
131
141
} catch (ex: Exception ) {
132
142
throw IllegalStateException (" cannot register schema for URI '$uri '" , ex)
133
143
}
134
144
}
135
145
}.fromJsonElement(schemaDefinition, currentDialect)
136
146
137
- private fun skipSchema (uri : String , schema : JsonElement ): Boolean {
138
- if (uri.contains(" draft4" , ignoreCase = true )) {
139
- // skip draft4 schemas
140
- return true
141
- }
147
+ private fun skipSchema (schema : JsonElement ): Boolean =
142
148
// ignore schemas for unsupported drafts
143
- return schema is JsonObject &&
149
+ schema is JsonObject &&
144
150
schema[" \$ schema" ]
145
151
?.jsonPrimitive
146
152
?.content
147
153
.let { it != null && SchemaType .find(it) == null }
148
- }
149
154
150
155
private fun runCase (command : Command .Run , schema : JsonSchema ) {
151
156
val results: List <TestResult > = command.case.tests.map { test ->
0 commit comments