Skip to content

Commit

Permalink
apply scalafmt (#236)
Browse files Browse the repository at this point in the history
* apply formatting

Co-authored-by: aonyshchuk <[email protected]>
  • Loading branch information
andyglow and aonyshchuk authored Dec 29, 2021
1 parent 559383f commit fc68be0
Show file tree
Hide file tree
Showing 144 changed files with 3,552 additions and 2,596 deletions.
4 changes: 4 additions & 0 deletions .githooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

/usr/local/bin/scalafmt-native
21 changes: 21 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version = "3.3.0"
runner.dialect = scala213
maxColumn = 200 # For my wide 30" display.
project.git = true
project.excludeFilters = ["target/"]
align.preset = more
align.stripMargin = true
align.arrowEnumeratorGenerator = true
assumeStandardLibraryStripMargin = true
includeCurlyBraceInSelectChains = false
newlines.penalizeSingleSelectMultiArgList = false
continuationIndent.defnSite = 2
docstrings.style = SpaceAsterisk

fileOverride {
"glob:**/scala-3*/**" {
runner.dialect = scala3
}
}


7 changes: 4 additions & 3 deletions api/src/main/scala/json/Json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import json.schema.{Predef, Version}

import scala.language.experimental.macros


object Json {

def schema[T]: Schema[T] = macro Macroses.deriveSchema[T]

def objectSchema[T](decorations: (String, String)*): `object`[T] = macro Macroses.deriveObjectSchema[T]
def objectSchema[T](decorations: (String, String)*): `object`[T] =
macro Macroses.deriveObjectSchema[T]

def sig[T]: TypeSignature[T] = macro Macroses.deriveSignature[T]

Expand All @@ -20,5 +20,6 @@ object Json {
implicit def derived[T]: Predef[T] = macro Macroses.derivePredef[T]
}

def stringify[T, V <: Version : AsValueBuilder](schema: Schema[T], version: V): String = schema.stringify(version)
def stringify[T, V <: Version: AsValueBuilder](schema: Schema[T], version: V): String =
schema.stringify(version)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ case class UserProfile(
credentials: Credentials = Credentials("anonymous", "-"),
role: Role = Role.User,
lastLoginMs: Option[Long], // = None; not supported currently for scala 2.11
notes: Option[Notes] = Some(Notes("initial note", Nil)))
notes: Option[Notes] = Some(Notes("initial note", Nil))
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import json.Schema._
import json.Schema.`object`._
import org.scalatest.matchers.should.Matchers._
import org.scalatest.funsuite.AnyFunSuite
import com.github.andyglow.jsonschema.{ model => case0 }
import com.github.andyglow.jsonschema.{model => case0}

object NoneForDefaultValueCases {

Expand All @@ -24,15 +24,12 @@ class NoneForDefaultValueSpec extends AnyFunSuite {
test("scala.None for default value") {

// type id specified in external file
Json.schema[case0.Foo] shouldBe `object`(
Field("value", `string`, required = false))
Json.schema[case0.Foo] shouldBe `object`(Field("value", `string`, required = false))

// type is specified in same file
Json.schema[case2.Foo] shouldBe `object`(
Field("value", `string`, required = false))
Json.schema[case2.Foo] shouldBe `object`(Field("value", `string`, required = false))

// type is specified in same file, companion object
Json.schema[case1.Foo] shouldBe `object`(
Field("value", `string`, required = false))
Json.schema[case1.Foo] shouldBe `object`(Field("value", `string`, required = false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import json.Schema.{`number`, `object`, `oneof`}
import org.scalatest.matchers.should.Matchers._
import org.scalatest.wordspec.AnyWordSpec


class SchemaMacro212Spec extends AnyWordSpec {
import SchemaMacro212Spec._

"generate schema for Sealed Trait subclasses defined inside of another object" in {
import `object`.Field

Json.schema[NestedFooBar] shouldEqual `oneof`(Set(
`object`(Field("foo", `number`[Double])),
`object`(Field("bar", `number`[Double]))))
Json.schema[NestedFooBar] shouldEqual `oneof`(
Set(`object`(Field("foo", `number`[Double])), `object`(Field("bar", `number`[Double])))
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ case class UserProfile(
credentials: Credentials = Credentials("anonymous", "-"),
role: Role = Role.User,
lastLoginMs: Option[Long] = None,
notes: Option[Notes] = Some(Notes("initial note", Nil)))
notes: Option[Notes] = Some(Notes("initial note", Nil))
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import json.Schema._
import json.Schema.`object`._
import org.scalatest.matchers.should.Matchers._
import org.scalatest.funsuite.AnyFunSuite
import com.github.andyglow.jsonschema.{ model => case0 }
import com.github.andyglow.jsonschema.{model => case0}

object NoneForDefaultValueCases {

Expand All @@ -24,15 +24,12 @@ class NoneForDefaultValueSpec extends AnyFunSuite {
test("scala.None for default value") {

// type id specified in external file
Json.schema[case0.Foo] shouldBe `object`(
Field("value", `string`, required = false))
Json.schema[case0.Foo] shouldBe `object`(Field("value", `string`, required = false))

// type is specified in same file
Json.schema[case2.Foo] shouldBe `object`(
Field("value", `string`, required = false))
Json.schema[case2.Foo] shouldBe `object`(Field("value", `string`, required = false))

// type is specified in same file, companion object
Json.schema[case1.Foo] shouldBe `object`(
Field("value", `string`, required = false))
Json.schema[case1.Foo] shouldBe `object`(Field("value", `string`, required = false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class SchemaMacro213Spec extends AnyWordSpec {
"generate schema for Sealed Trait subclasses defined inside of another object" in {
import `object`.Field

Json.schema[NestedFooBar] shouldEqual `oneof`(Set(
`object`(Field("foo", `number`[Double])),
`object`(Field("bar", `number`[Double]))))
Json.schema[NestedFooBar] shouldEqual `oneof`(Set(`object`(Field("foo", `number`[Double])), `object`(Field("bar", `number`[Double]))))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ case class UserProfile(
credentials: Credentials = Credentials("anonymous", "-"),
role: Role = Role.User,
lastLoginMs: Option[Long] = None,
notes: Option[Notes] = Some(Notes("initial note", Nil)))
notes: Option[Notes] = Some(Notes("initial note", Nil))
)
4 changes: 1 addition & 3 deletions api/src/test/scala/com/example/unrelated/CommentsMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ object CommentsMain {
}

def main(args: Array[String]): Unit = {
val s0 = json.Json.objectSchema[models.Foo](
"c" -> "C, C, ccc",
"b" -> "bcd")
val s0 = json.Json.objectSchema[models.Foo]("c" -> "C, C, ccc", "b" -> "bcd")

printSchema(s0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package com.example.unrelated
import org.scalatest.matchers.should.Matchers._
import org.scalatest.wordspec.AnyWordSpec

/** This spec checks that the macro works even when names from
* `com.github.andyglow.jsonschema` are not in scope.
/** This spec checks that the macro works even when names from `com.github.andyglow.jsonschema` are not in scope.
*/
class SchemaMacroNamesSpec extends AnyWordSpec {

Expand Down
12 changes: 8 additions & 4 deletions api/src/test/scala/com/example/unrelated/models.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ object models {

/** My perfect class
*
* @param a A Param
* @param b B Param
* @param a
* A Param
* @param b
* B Param
*/
case class Foo(
a: String,
b: Int,
c: Boolean,
@description("some description") d: Map[String, String])
@description("some description") d: Map[String, String]
)

@title("A Bar Title")
@description("this is Bar. description")
case class Bar(
@description("aaa") a: String,
@description("bbb") b: Int,
@description("ccc") c: Boolean,
@description("ddd") d: Map[String, String])
@description("ddd") d: Map[String, String]
)
}
Loading

0 comments on commit fc68be0

Please sign in to comment.