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
) : Schema(location) {
override fun accept(visitor: SchemaVisitor
) = visitor.internallyVisitCompositeSchema(this)
override fun subschemas() = subschemas
}
data class AllOfSchema(
val subschemas: List,
override val location: SourceLocation
) : Schema(location) {
override fun accept(visitor: SchemaVisitor
) = visitor.visitAllOfSchema(this)
override fun subschemas(): Collection = subschemas
}
data class AnyOfSchema(
val subschemas: List,
override val location: SourceLocation
) : Schema(location) {
override fun accept(visitor: SchemaVisitor
) = visitor.visitAnyOfSchema(this)
override fun subschemas(): Collection = subschemas
}
data class OneOfSchema(
val subschemas: List,
override val location: SourceLocation
) : Schema(location) {
override fun accept(visitor: SchemaVisitor
) = visitor.visitOneOfSchema(this)
override fun subschemas(): Collection = 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)
data class TrueSchema(override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
) = visitor.visitTrueSchema(this)
}
data class FalseSchema(override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
) = visitor.visitFalseSchema(this)
}
data class MinLengthSchema(val minLength: Int, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
) = visitor.visitMinLengthSchema(this)
}
data class MaxLengthSchema(val maxLength: Int, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
) = visitor.visitMaxLengthSchema(this)
}
data class AdditionalPropertiesSchema(
val subschema: Schema,
val keysInProperties: List,
val patternPropertyKeys: Collection,
override val location: SourceLocation
) : Schema(location) {
override fun accept(visitor: SchemaVisitor
) = visitor.visitAdditionalPropertiesSchema(this)
override fun subschemas() = listOf(subschema)
}
data class ConstSchema(val constant: IJsonValue, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
) = visitor.visitConstSchema(this)
}
data class TypeSchema(val type: IJsonString, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
) = visitor.visitTypeSchema(this)
}
data class MultiTypeSchema(val types: IJsonArray<*>, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitMultiTypeSchema(this)
}
data class NotSchema(val negatedSchema: Schema, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitNotSchema(this)
override fun subschemas(): Collection = listOf(negatedSchema)
}
data class RequiredSchema(val requiredProperties: List, override val location: SourceLocation) : Schema(location) {
override fun accept(visitor: SchemaVisitor
): P? = visitor.visitRequiredSchema(this)
}
data class MaximumSchema(val maximum: Number, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitMaximumSchema(this)
}
data class MinimumSchema(val minimum: Number, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitMinimumSchema(this)
}
data class ExclusiveMaximumSchema(val maximum: Number, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitExclusiveMaximumSchema(this)
}
data class ExclusiveMinimumSchema(val minimum: Number, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitExclusiveMinimumSchema(this)
}
data class MultipleOfSchema(val denominator: Number, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitMultipleOfSchema(this)
}
data class UniqueItemsSchema(val unique: Boolean, override val location: SourceLocation) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitUniqueItemsSchema(this)
}
data class PatternSchema(
val pattern: Regexp,
override val location: SourceLocation
) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitPatternSchema(this)
}
data class PropertyNamesSchema(
val propertyNamesSchema: Schema,
override val location: SourceLocation
) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitPropertyNamesSchema(this)
override fun subschemas(): Collection = setOf(propertyNamesSchema)
}
data class ItemsSchema(val itemsSchema: Schema, val prefixItemCount: Int, override val location: SourceLocation) : Schema(location) {
override fun accept(visitor: SchemaVisitor
): P? = visitor.visitItemsSchema(this)
override fun subschemas(): Collection = listOf(itemsSchema)
}
data class PrefixItemsSchema(val prefixSchemas: List, override val location: SourceLocation) : Schema(location) {
override fun accept(visitor: SchemaVisitor
): P? = visitor.visitPrefixItemsSchema(this)
override fun subschemas(): Collection = prefixSchemas
}
data class ContainsSchema(
val containedSchema: Schema,
val minContains: Number = 1,
val maxContains: Number?,
override val location: SourceLocation
) : Schema(location) {
override fun accept(visitor: SchemaVisitor
): P? = visitor.visitContainsSchema(this)
override fun subschemas(): Collection = listOf(containedSchema)
}
data class IfThenElseSchema(
val ifSchema: Schema,
val thenSchema: Schema?,
val elseSchema: Schema?,
override val location: SourceLocation
) : Schema(location) {
override fun accept(visitor: SchemaVisitor
): P? = visitor.visitIfThenElseSchema(this)
override fun subschemas() = listOfNotNull(ifSchema, thenSchema, elseSchema)
}
data class DependentSchemasSchema(
val dependentSchemas: Map,
override val location: SourceLocation
) : Schema(location) {
override fun accept(visitor: SchemaVisitor
): P? = visitor.visitDependentSchemas(this)
}
data class UnevaluatedItemsSchema(
val unevaluatedItemsSchema: Schema,
override val location: SourceLocation
) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitUnevaluatedItemsSchema(this)
override fun subschemas() = listOf(unevaluatedItemsSchema)
}
data class UnevaluatedPropertiesSchema(
val unevaluatedPropertiesSchema: Schema,
override val location: SourceLocation
) : Schema(location) {
override fun
accept(visitor: SchemaVisitor
): P? = visitor.visitUnevaluatedPropertiesSchema(this)
override fun subschemas() = listOf(unevaluatedPropertiesSchema)
}