All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.andyglow.jsonschema.AsDraft06.scala Maven / Gradle / Ivy

package com.github.andyglow.jsonschema

import com.github.andyglow.json.Value._
import json.Schema._
import json.schema.Version._


class AsDraft06(val v: Draft06) extends AsValue with AsDraftSupport {

  def schema(x: json.Schema[_]): obj = {
    val base = obj(
      f"$$schema"   -> v.uri,
      f"$$id"       -> v.id,
      "description" -> x.description,
      "title"       -> x.title)

    val definitions = inferDefinitions(x)

    base ++ apply(x) ++ {
      if (definitions.fields.nonEmpty) obj("definitions" -> definitions) else obj()
    }
  }

  override def buildRef(ref: String): String = s"#$ref"

  override def inferDefinition(x: `def`[_], par: ParentSchema): (String, obj) = {
    val ref = x.sig
    ref -> (obj(f"$$id" -> s"#$ref") ++ apply(x.tpe, par orElse Some(x), includeType = true, isRoot = false))
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy