com.github.erosb.jsonsKema.Schema.kt Maven / Gradle / Ivy
package com.github.erosb.jsonsKema
abstract class Schema(open val location: SourceLocation) {
abstract fun accept(visitor: SchemaVisitor
): P?
open fun subschemas(): Collection = emptyList()
}
data class CompositeSchema(
val subschemas: Set,
override val location: SourceLocation = UnknownSource,
val id: IJsonString? = null,
val title: IJsonString? = null,
val description: IJsonString? = null,
val deprecated: IJsonBoolean? = null,
val readOnly: IJsonBoolean? = null,
val writeOnly: IJsonBoolean? = null,
val default: IJsonValue? = null,
val dynamicRef: DynamicReference? = null,
val dynamicAnchor: String? = null,
val propertySchemas: Map = emptyMap(),
val patternPropertySchemas: Map = emptyMap(),
val unevaluatedItemsSchema: Schema? = null,
val unevaluatedPropertiesSchema: Schema? = null,
val unprocessedProperties: Map = emptyMap()
) : Schema(location) {
override fun accept(visitor: SchemaVisitor
) = visitor.internallyVisitCompositeSchema(this)
override fun subschemas() = subschemas
}
data class ReferenceSchema(var referredSchema: Schema?, val ref: String, override val location: SourceLocation) :
Schema(location) {
override fun
accept(visitor: SchemaVisitor
) = visitor.visitReferenceSchema(this)
override fun subschemas() = referredSchema?.let { listOf(it) } ?: emptyList()
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ReferenceSchema) return false
if (location != other.location) return false
return referredSchema === other.referredSchema
}
override fun hashCode(): Int {
return location.hashCode()
}
override fun toString(): String {
return "{\"\$ref\": \"${ref}\", \"resolved\":\"${referredSchema !== null}\"}"
}
}
data class DynamicRefSchema(var referredSchema: Schema?, val dynamicRef: String, override val location: SourceLocation) :
Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitDynamicRefSchema(this)
override fun subschemas() = referredSchema?.let { listOf(it) } ?: emptyList()
}
data class DynamicReference(val ref: String, var fallbackReferredSchema: ReferenceSchema? = null)