Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove final modifiers #225

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.github.andyglow.jsonschema.{ model => case0 }

object NoneForDefaultValueCases {

final object case1 {
object case1 {
case class Foo(value: Option[String] = None)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.github.andyglow.jsonschema.{ model => case0 }

object NoneForDefaultValueCases {

final object case1 {
object case1 {
case class Foo(value: Option[String] = None)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import JsonMatchers._
object DiscriminatorSpec {

// phantom
final object case0 {
object case0 {
@discriminator sealed trait Root
final object Root {
object Root {
final case class Member1(value: Int) extends Root
final case class Member2(value: String) extends Root
}
}

// not a phantom
final object case1 {
object case1 {
@discriminator(field = "type", phantom = false) sealed trait Root
final object Root {
object Root {
final case class Member1(`type`: String, value: Int) extends Root
final case class Member2(`type`: String, value: String) extends Root
}
Expand All @@ -33,36 +33,36 @@ object DiscriminatorSpec {
// not a phantom, should fail because discriminator field is both
// - not a phantom
// - and not present
final object case2 {
object case2 {
@discriminator(field = "tpe", phantom = false) sealed trait Root
final object Root {
object Root {
final case class Member1(`type`: String, value: Int) extends Root
final case class Member2(`type`: String, value: String) extends Root
}
}

// not a phantom, non-standard discrimination field
final object case3 {
object case3 {
@discriminator(field = "tpe", phantom = false) sealed trait Root
final object Root {
object Root {
final case class Member1(tpe: String, value: Int) extends Root
final case class Member2(tpe: String, value: String) extends Root
}
}

// specific discriminator keys
final object case4 {
object case4 {
@discriminator sealed trait Root
final object Root {
object Root {
@discriminatorKey("m1") final case class Member1(value: Int) extends Root
@discriminatorKey("m2") final case class Member2(value: String) extends Root
}
}

// definition + specific discriminator keys
final object case5 {
object case5 {
@discriminator sealed trait Root
final object Root {
object Root {
@definition("m1") @discriminatorKey("m1") final case class Member1(value: Int) extends Root
@definition("m2") @discriminatorKey("m2") final case class Member2(value: String) extends Root
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import org.scalatest.wordspec._
// comes first because otherwise it fails on directKnownSubclass resolution
object RecursiveTypesSpec {

final object case1 {
object case1 {
final case class SList(head: String, tail: Option[SList])
}

final object case2 {
object case2 {
sealed trait Node
final object Node {
object Node {
final case class Element(tag: String, children: List[Node]) extends Node
final case class Text(content: String) extends Node
}
}

final object case3 {
object case3 {
final case class LList[T](head: T, tail: Option[LList[T]])
final case class User(id: String, friends: LList[String])
}
Expand Down
60 changes: 30 additions & 30 deletions core/src/main/scala/json/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ object Schema {
override def jsonType: String = "boolean"
override def toString: String = ToString(_ append "boolean")
}
final object `boolean` extends `boolean`
object `boolean` extends `boolean`

// +------------
// | Integer
Expand All @@ -132,7 +132,7 @@ object Schema {
override def jsonType: String = "integer"
override def toString: String = ToString(_ append "integer")
}
final object `integer` extends `integer`
object `integer` extends `integer`

// +------------
// | Number
Expand All @@ -145,7 +145,7 @@ object Schema {
override def jsonType: String = "number"
override def toString: String = ToString(_ append "number")
}
final object `number` {
object `number` {
def apply[T: Numeric]: `number`[T] = new `number`[T]
}

Expand All @@ -171,25 +171,25 @@ object Schema {
}
}
}
final object `string` extends `string`[String](None) {
object `string` extends `string`[String](None) {
def apply[T]: `string`[T] = new `string`[T](None)
def apply[T](format: Format): `string`[T] = new `string`[T](Some(format))
trait Format extends Product
object Format {
final case object `date` extends Format
final case object `time` extends Format
final case object `date-time` extends Format // Date representation, as defined by RFC 3339, section 5.6.
final case object `email` extends Format // Internet email address, see RFC 5322, section 3.4.1.
final case object `hostname` extends Format // Internet host name, see RFC 1034, section 3.1.
final case object `ipv4` extends Format // Internet host name, see RFC 1034, section 3.1.
final case object `ipv6` extends Format // IPv6 address, as defined in RFC 2373, section 2.2.
final case object `uri` extends Format // A universal resource identifier (URI), according to RFC3986.
case object `date` extends Format
case object `time` extends Format
case object `date-time` extends Format // Date representation, as defined by RFC 3339, section 5.6.
case object `email` extends Format // Internet email address, see RFC 5322, section 3.4.1.
case object `hostname` extends Format // Internet host name, see RFC 1034, section 3.1.
case object `ipv4` extends Format // Internet host name, see RFC 1034, section 3.1.
case object `ipv6` extends Format // IPv6 address, as defined in RFC 2373, section 2.2.
case object `uri` extends Format // A universal resource identifier (URI), according to RFC3986.

// added in 2019-09
final case object `duration` extends Format // The duration format is from the ISO 8601 ABNF as given in Appendix A of RFC 3339
final case object `idn-hostname` extends Format // Use RFC 1123 instead of RFC 1034; this allows for a leading digit,
case object `duration` extends Format // The duration format is from the ISO 8601 ABNF as given in Appendix A of RFC 3339
case object `idn-hostname` extends Format // Use RFC 1123 instead of RFC 1034; this allows for a leading digit,
// `hostname` is also RFC 1123 since 2019-09
final case object `uuid` extends Format // A string instance is valid against this attribute if it is a valid string representation of a UUID, according to RFC4122
case object `uuid` extends Format // A string instance is valid against this attribute if it is a valid string representation of a UUID, according to RFC4122
}
}

Expand Down Expand Up @@ -242,20 +242,20 @@ object Schema {
sb append ")"
}
}
final object `dictionary` {
object `dictionary` {
abstract class KeyPattern[T](val pattern: String)
final object KeyPattern {
object KeyPattern {
def mk[T](pattern: String): KeyPattern[T] = new KeyPattern[T](pattern) {}
def forEnum[T](vals: Iterable[String]): KeyPattern[T] = {
require(vals.nonEmpty)
mk[T](vals.toList.distinct.sorted.mkString("^(?:", "|", ")$"))
}
implicit final object StringKeyPattern extends KeyPattern[String]("^.*$")
implicit final object CharKeyPattern extends KeyPattern[Char]("^.{1}$")
implicit final object ByteKeyPattern extends KeyPattern[Byte]("^[0-9]+$")
implicit final object ShortKeyPattern extends KeyPattern[Short]("^[0-9]+$")
implicit final object IntKeyPattern extends KeyPattern[Int]("^[0-9]+$")
implicit final object LongKeyPattern extends KeyPattern[Long]("^[0-9]+$")
implicit object StringKeyPattern extends KeyPattern[String]("^.*$")
implicit object CharKeyPattern extends KeyPattern[Char]("^.{1}$")
implicit object ByteKeyPattern extends KeyPattern[Byte]("^[0-9]+$")
implicit object ShortKeyPattern extends KeyPattern[Short]("^[0-9]+$")
implicit object IntKeyPattern extends KeyPattern[Int]("^[0-9]+$")
implicit object LongKeyPattern extends KeyPattern[Long]("^[0-9]+$")
}
}

Expand Down Expand Up @@ -302,12 +302,12 @@ object Schema {
}
}
}
final object `object` {
object `object` {
sealed trait Free { this: `object`[_] =>
type Type
def strict: `object`[Type]
}
final object Free {
object Free {
def apply[T](): `object`[T] with Free = {
new `object`[T](Set.empty) with Free {
type Type = T
Expand Down Expand Up @@ -347,7 +347,7 @@ object Schema {
def setReadOnly: Field[T] = withRWMode(RWMode.ReadOnly)
def setWriteOnly: Field[T] = withRWMode(RWMode.WriteOnly)
}
final object Field {
object Field {
sealed trait RWMode
object RWMode {
case object ReadOnly extends RWMode
Expand Down Expand Up @@ -401,7 +401,7 @@ object Schema {
sb append ")"
}
}
final object `enum` {
object `enum` {
def of[T](tpe: Schema[_], x: Value, xs: Value*): `enum`[T] = new `enum`[T](tpe, (x +: xs).toSet)
def of[T](x: T, xs: T*)(implicit va: ValueAdapter[T], vs: ValueSchema[T]): `enum`[vs.S] = {
new `enum`[vs.S](
Expand Down Expand Up @@ -440,7 +440,7 @@ object Schema {
}
def discriminatedBy(x: String): Self = new `oneof`[T](subTypes, Some(x))
}
final object `oneof` {
object `oneof` {
def of[T](x: Schema[_], xs: Schema[_]*): `oneof`[T] = new `oneof`[T]((x +: xs).toSet, None)
}

Expand Down Expand Up @@ -468,7 +468,7 @@ object Schema {
sb append ")"
}
}
final object `allof` {
object `allof` {
def of[T](x: Schema[_], xs: Schema[_]*): `allof`[T] = new `allof`[T]((x +: xs).toSet)
}

Expand Down Expand Up @@ -535,7 +535,7 @@ object Schema {
}
}

final object `def` {
object `def` {
def apply[T](tpe: Schema[_])(sig: => String): `def`[T] = tpe match {
case `def`(originalSig, innerTpe) => `def`(originalSig, innerTpe)
case `value-class`(innerTpe) => `def`(sig, innerTpe)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/json/schema/Version.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sealed trait Version {

object Version {

final case object Raw extends Version {
case object Raw extends Version {
def uri = ???
}

Expand Down
38 changes: 19 additions & 19 deletions core/src/main/scala/json/schema/validation/Instance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,42 @@ sealed abstract class Instance[S, V]()(implicit conv: V => Value) extends Produc

object Instance {

final case object `multipleOf` extends Instance[Number, Number]()(num.apply)
case object `multipleOf` extends Instance[Number, Number]()(num.apply)

final case object `maximum` extends Instance[Number, Number]()(num.apply)
case object `maximum` extends Instance[Number, Number]()(num.apply)

final case object `minimum` extends Instance[Number, Number]()(num.apply)
case object `minimum` extends Instance[Number, Number]()(num.apply)

final case object `exclusiveMaximum` extends Instance[Number, Number]()(num.apply)
case object `exclusiveMaximum` extends Instance[Number, Number]()(num.apply)

final case object `exclusiveMinimum` extends Instance[Number, Number]()(num.apply)
case object `exclusiveMinimum` extends Instance[Number, Number]()(num.apply)

final case object `contentEncoding` extends Instance[String, String]()(str.apply)
case object `contentEncoding` extends Instance[String, String]()(str.apply)

final case object `contentMediaType` extends Instance[String, String]()(str.apply)
case object `contentMediaType` extends Instance[String, String]()(str.apply)

final case object `contentSchema` extends Instance[String, json.Schema[_]]()(AsValue.schema(_, Draft04())) // FIXME: shouldn't specify a Version at this level
case object `contentSchema` extends Instance[String, json.Schema[_]]()(AsValue.schema(_, Draft04())) // FIXME: shouldn't specify a Version at this level

final case object `maxLength` extends Instance[String, Int]()(num.apply)
case object `maxLength` extends Instance[String, Int]()(num.apply)

final case object `minLength` extends Instance[String, Int]()(num.apply)
case object `minLength` extends Instance[String, Int]()(num.apply)

final case object `pattern` extends Instance[String, String]()(str.apply)
case object `pattern` extends Instance[String, String]()(str.apply)

final case object `maxItems` extends Instance[Iterable[_], Int]()(num.apply)
case object `maxItems` extends Instance[Iterable[_], Int]()(num.apply)

final case object `minItems` extends Instance[Iterable[_], Int]()(num.apply)
case object `minItems` extends Instance[Iterable[_], Int]()(num.apply)

final case object `maxContains` extends Instance[Iterable[_], Int]()(num.apply)
case object `maxContains` extends Instance[Iterable[_], Int]()(num.apply)

final case object `minContains` extends Instance[Iterable[_], Int]()(num.apply)
case object `minContains` extends Instance[Iterable[_], Int]()(num.apply)

final case object `uniqueItems` extends Instance[Iterable[_], Boolean]()(bool.apply)
case object `uniqueItems` extends Instance[Iterable[_], Boolean]()(bool.apply)

final case object `maxProperties` extends Instance[Map[_, _], Int]()(num.apply)
case object `maxProperties` extends Instance[Map[_, _], Int]()(num.apply)

final case object `minProperties` extends Instance[Map[_, _], Int]()(num.apply)
case object `minProperties` extends Instance[Map[_, _], Int]()(num.apply)

final case object `patternProperties` extends Instance[Map[_, _], String]()(str.apply)
case object `patternProperties` extends Instance[Map[_, _], String]()(str.apply)
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object ScalaParts {
tpe: String,
default: Option[String])

final object ParsedParameter {
object ParsedParameter {

def fromString(x: String): ParsedParameter = {
val colonIdx = x.indexOf(':')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private[jsonschema] trait UCommons extends SchemaTypes with ULogging { this: UCo
val Field = q"$Schema.`object`.Field"
val Predef = q"$json.schema.Predef"
val Validation = q"$json.schema.validation.Instance"
final object internal {
object internal {
private val prefix = q"_root_.com.github.andyglow"
val json = q"$prefix.json"
val jsonschema = q"$prefix.jsonschema"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait UFieldDecorations { this: UContext with UCommons =>
*/
type FieldDecorations = Map[String, String]

final object FieldDecorations {
object FieldDecorations {

val Empty: FieldDecorations = Map.empty

Expand Down
Loading