Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* @(#) JSONSchema.kt
*
* json-kotlin-schema Kotlin implementation of JSON Schema
* Copyright (c) 2020 Peter Wall
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.pwall.json.schema
import java.io.File
import java.net.URI
import net.pwall.json.JSON
import net.pwall.json.JSONBoolean
import net.pwall.json.JSONMapping
import net.pwall.json.JSONNumberValue
import net.pwall.json.JSONSequence
import net.pwall.json.JSONString
import net.pwall.json.JSONValue
import net.pwall.json.pointer.JSONPointer
import net.pwall.json.schema.output.BasicErrorEntry
import net.pwall.json.schema.output.BasicOutput
import net.pwall.json.schema.output.DetailedOutput
import net.pwall.json.schema.output.Output
import net.pwall.json.schema.parser.Parser
import net.pwall.json.schema.subschema.AllOfSchema
import net.pwall.json.schema.subschema.AnyOfSchema
import net.pwall.json.schema.subschema.OneOfSchema
/**
* A JSON Schema.
*
* @author Peter Wall
*/
sealed class JSONSchema(
/** The URI for the schema */
val uri: URI?,
/** The JSON Pointer for the location of the schema */
val location: JSONPointer
) {
enum class Type(val value: String) {
NULL("null"),
BOOLEAN("boolean"),
OBJECT("object"),
ARRAY("array"),
NUMBER("number"),
STRING("string"),
INTEGER("integer")
}
val absoluteLocation: String?
get() = uri?.let { "$it${location.schemaURIFragment()}" }
open val description: String? = null
open val title: String? = null
open fun childLocation(pointer: JSONPointer): JSONPointer = pointer
abstract fun validate(json: JSONValue?, instanceLocation: JSONPointer = JSONPointer.root): Boolean
abstract fun validateBasic(relativeLocation: JSONPointer, json: JSONValue?, instanceLocation: JSONPointer):
BasicOutput
abstract fun validateDetailed(relativeLocation: JSONPointer, json: JSONValue?, instanceLocation: JSONPointer):
DetailedOutput
fun validateBasic(json: JSONValue?, instanceLocation: JSONPointer = JSONPointer.root) =
validateBasic(JSONPointer.root, json, instanceLocation)
fun validateDetailed(json: JSONValue?, instanceLocation: JSONPointer = JSONPointer.root) =
validateDetailed(JSONPointer.root, json, instanceLocation)
fun validate(json: String, instanceLocation: JSONPointer = JSONPointer.root) =
validate(JSON.parse(json), instanceLocation)
fun validateBasic(json: String, instanceLocation: JSONPointer = JSONPointer.root) =
validateBasic(JSONPointer.root, JSON.parse(json), instanceLocation)
fun validateDetailed(json: String, instanceLocation: JSONPointer = JSONPointer.root) =
validateDetailed(JSONPointer.root, JSON.parse(json), instanceLocation)
fun createAnnotation(relativeLocation: JSONPointer, instanceLocation: JSONPointer, annotation: String,
errors: List