Skip to content

Commit c102200

Browse files
committed
Simplify imports
1 parent 6768c5d commit c102200

File tree

9 files changed

+79
-68
lines changed

9 files changed

+79
-68
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Encode a product:
2727
```scala
2828
import com.melvinlow.json.schema.*
2929
import com.melvinlow.json.schema.generic.auto.given
30-
import com.melvinlow.json.schema.instances.given
3130

3231
case class Foo(x: Int, y: String)
3332

docs/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Encode a product:
2727
```scala mdoc
2828
import com.melvinlow.json.schema.*
2929
import com.melvinlow.json.schema.generic.auto.given
30-
import com.melvinlow.json.schema.instances.given
3130

3231
case class Foo(x: Int, y: String)
3332

src/main/scala/com/melvinlow/json/schema/generic/auto.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import scala.deriving.Mirror
66

77
import io.circe.Json
88

9-
import com.melvinlow.json.schema.JsonSchemaEncoder
109
import com.melvinlow.json.schema.annotation.JsonSchemaField
10+
import com.melvinlow.json.schema.{JsonSchemaEncoder, instances}
1111

12-
object auto {
12+
trait auto {
1313
inline private def summonLabels[Elems <: Tuple]: List[String] =
1414
inline erasedValue[Elems] match {
1515
case _: (elem *: elems) =>
@@ -38,7 +38,7 @@ object auto {
3838
case _: Elem =>
3939
error("infinite recursive derivation")
4040
case _ =>
41-
auto.derived[Elem](using summonInline[Mirror.Of[Elem]])
41+
derived[Elem](using summonInline[Mirror.Of[Elem]])
4242
}
4343

4444
private def sumEncoder[T: Mirror.SumOf](
@@ -110,3 +110,5 @@ object auto {
110110
inline given derivedSum[T: Mirror.SumOf]: JsonSchemaEncoder[T] =
111111
derived[T]
112112
}
113+
114+
object auto extends auto with semiauto with instances
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.melvinlow.json.schema.generic
2+
3+
import com.melvinlow.json.schema.instances
4+
5+
trait semiauto
6+
7+
object semiauto extends semiauto with instances
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.melvinlow.json.schema
2+
3+
import io.circe.Json
4+
5+
trait instances_low_priority {
6+
given intJsonSchemaInstance[T <: Int]: JsonSchemaEncoder[T] with {
7+
def schema: Json = Json.obj("type" -> Json.fromString("integer"))
8+
}
9+
10+
given stringJsonSchemaInstance[T <: String]: JsonSchemaEncoder[T] with {
11+
def schema: Json = Json.obj("type" -> Json.fromString("string"))
12+
}
13+
14+
given longJsonSchemaInstance[T <: Long]: JsonSchemaEncoder[T] with {
15+
def schema: Json = Json.obj("type" -> Json.fromString("integer"))
16+
}
17+
18+
given doubleJsonSchemaInstance[T <: Double]: JsonSchemaEncoder[T] with {
19+
def schema: Json = Json.obj("type" -> Json.fromString("number"))
20+
}
21+
22+
given floatJsonSchemaEncoder[T <: Float]: JsonSchemaEncoder[T] with {
23+
def schema: Json = Json.obj("type" -> Json.fromString("number"))
24+
}
25+
26+
given booleanJsonSchemaEncoder[T <: Boolean]: JsonSchemaEncoder[T] with {
27+
def schema: Json = Json.obj("type" -> Json.fromString("boolean"))
28+
}
29+
30+
given listJsonSchemaEncoder[T: JsonSchemaEncoder]: JsonSchemaEncoder[List[T]]
31+
with {
32+
def schema: Json =
33+
Json
34+
.obj(
35+
"type" -> Json.fromString("array"),
36+
"items" -> JsonSchemaEncoder[T].schema
37+
)
38+
}
39+
40+
given arrayJsonSchemaEncoder[T: JsonSchemaEncoder]
41+
: JsonSchemaEncoder[Array[T]]
42+
with {
43+
def schema: Json =
44+
Json
45+
.obj(
46+
"type" -> Json.fromString("array"),
47+
"items" -> JsonSchemaEncoder[T].schema
48+
)
49+
}
50+
}
51+
52+
trait instances extends instances_low_priority {
53+
given nullJsonSchemaEncoder: JsonSchemaEncoder[Null] with {
54+
def schema: Json = Json.obj("type" -> Json.fromString("null"))
55+
}
56+
}
57+
58+
object instances extends instances

src/main/scala/com/melvinlow/json/schema/instances/pkg.scala

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.melvinlow.json.schema
2+
3+
import io.circe.Json
4+
5+
object syntax {
6+
extension [T: JsonSchemaEncoder](inline dummy: T) {
7+
inline def jsonSchema: Json = JsonSchemaEncoder[T].schema
8+
}
9+
}

src/main/scala/com/melvinlow/json/schema/syntax/pkg.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/test/scala/com/melvinlow/json/schema/JsonSchemaEncoderSuite.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import io.circe.Json
55
import com.melvinlow.json.schema.Resources.*
66
import com.melvinlow.json.schema.annotation.JsonSchemaField
77
import com.melvinlow.json.schema.generic.auto.given
8-
import com.melvinlow.json.schema.instances.given
98
import com.melvinlow.json.schema.syntax.*
109

1110
class JsonSchemaEncoderSuite extends munit.FunSuite {

0 commit comments

Comments
 (0)