-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonSchemaLoader.kt
89 lines (71 loc) · 2.72 KB
/
JsonSchemaLoader.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package io.github.optimumcode.json.schema
import io.github.optimumcode.json.schema.SchemaType.DRAFT_2019_09
import io.github.optimumcode.json.schema.SchemaType.DRAFT_2020_12
import io.github.optimumcode.json.schema.SchemaType.DRAFT_7
import io.github.optimumcode.json.schema.extension.ExternalAssertionFactory
import io.github.optimumcode.json.schema.internal.SchemaLoader
import io.github.optimumcode.json.schema.internal.wellknown.Draft201909
import io.github.optimumcode.json.schema.internal.wellknown.Draft202012
import io.github.optimumcode.json.schema.internal.wellknown.Draft7
import kotlinx.serialization.json.JsonElement
import kotlin.jvm.JvmStatic
@Suppress("detekt:TooManyFunctions")
public interface JsonSchemaLoader {
public fun registerWellKnown(draft: SchemaType): JsonSchemaLoader =
apply {
when (draft) {
DRAFT_7 -> Draft7.entries.forEach { register(it.content) }
DRAFT_2019_09 -> Draft201909.entries.forEach { register(it.content) }
DRAFT_2020_12 -> Draft202012.entries.forEach { register(it.content) }
}
}
public fun register(schema: JsonElement): JsonSchemaLoader = register(schema, null)
public fun register(
schema: JsonElement,
draft: SchemaType?,
): JsonSchemaLoader
public fun register(schema: String): JsonSchemaLoader = register(schema, null)
public fun register(
schema: String,
draft: SchemaType?,
): JsonSchemaLoader
public fun register(
schema: JsonElement,
remoteUri: String,
): JsonSchemaLoader = register(schema, remoteUri, null)
public fun register(
schema: JsonElement,
remoteUri: String,
draft: SchemaType?,
): JsonSchemaLoader
public fun withExtensions(
externalFactory: ExternalAssertionFactory,
vararg otherExternalFactories: ExternalAssertionFactory,
): JsonSchemaLoader
public fun withExtensions(externalFactories: Iterable<ExternalAssertionFactory>): JsonSchemaLoader
@ExperimentalApi
public fun withCustomFormat(
format: String,
formatValidator: FormatValidator,
): JsonSchemaLoader
@ExperimentalApi
public fun withCustomFormats(formats: Map<String, FormatValidator>): JsonSchemaLoader
public fun <T : Any> withSchemaOption(
option: SchemaOption<T>,
value: T,
): JsonSchemaLoader
public fun fromDefinition(schema: String): JsonSchema = fromDefinition(schema, null)
public fun fromDefinition(
schema: String,
draft: SchemaType?,
): JsonSchema
public fun fromJsonElement(schemaElement: JsonElement): JsonSchema = fromJsonElement(schemaElement, null)
public fun fromJsonElement(
schemaElement: JsonElement,
draft: SchemaType?,
): JsonSchema
public companion object {
@JvmStatic
public fun create(): JsonSchemaLoader = SchemaLoader()
}
}