Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# See http://about.travis-ci.org/docs/user/build-configuration/
language: scala
scala:
- 2.11.8
- 2.12.1
- 2.11.9
- 2.12.4
jdk:
- oraclejdk8
before_install:
Expand Down
61 changes: 34 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,41 @@ name := "docless"

version := "0.6.0-SNAPSHOT"

val circeVersion = "0.7.0"
val enumeratumVersion = "1.5.7"
val catsVersion = "0.9.0"
val circeVersion = "0.9.1"
val enumeratumVersion = "1.5.13"
val enumeratumCirceVersion = "1.5.17"
val catsVersion = "1.1.0"
val shapelessVersion = "2.3.3"
val ammoniteVersion = "1.0.5"

val readme = "README.md"
val readmePath = file(".") / readme

scalaVersion := "2.12.1"
scalaVersion := "2.12.4"

crossScalaVersions := Seq("2.11.8", "2.12.1")
crossScalaVersions := Seq("2.11.9", "2.12.4")

useGpg := true
useGpgAgent := true

enablePlugins(TutPlugin)

scalacOptions += "-Ypartial-unification"

libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"com.chuusai" %% "shapeless" % "2.3.2",
"com.chuusai" %% "shapeless" % shapelessVersion,
"com.beachape" %% "enumeratum" % enumeratumVersion,
"com.beachape" %% "enumeratum-circe" % "1.5.9",
"org.typelevel" %% "cats" % catsVersion,
"com.beachape" %% "enumeratum-circe" % enumeratumCirceVersion,
"org.typelevel" %% "cats-core" % catsVersion,
"org.typelevel" %% "cats-kernel" % catsVersion,
"org.typelevel" %% "cats-macros" % catsVersion,
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"org.scalatest" %% "scalatest" % "3.0.0" % "test",
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"com.github.fge" % "json-schema-validator" % "2.2.6" % "test",
"com.lihaoyi" % "ammonite" % "0.8.1" % "test" cross CrossVersion.full
"com.lihaoyi" % "ammonite" % ammoniteVersion % "test" cross CrossVersion.full
)

val predef = Seq(
Expand Down Expand Up @@ -66,20 +75,18 @@ copyReadme := {
val pandocReadme =
taskKey[Unit](s"Add a table of content to the README using pandoc")

pandocReadme := {
val readme = copyReadme.value
val log = streams.value.log
val cmd =
s"pandoc -B doc/header.md -f markdown_github --toc -s -S $readme -o $readme"
log.info(s"Running pandoc: $cmd}")
try { Process(cmd) ! log } catch {
case e: java.io.IOException =>
log.error(
"You might need to install the pandoc executable! Please follow instructions here: http://pandoc.org/installing.html"
)
throw e
}

}

tutSettings
pandocReadme := {
val readme = copyReadme.value
val log = streams.value.log
val cmd =
s"pandoc -B doc/header.md -f markdown_github --toc -s -S $readme -o $readme"
log.info(s"Running pandoc: $cmd}")
try { new Fork(cmd, None) } catch {
case e: java.io.IOException =>
log.error(
"You might need to install the pandoc executable! Please follow instructions here: http://pandoc.org/installing.html"
)
throw e
}

}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 0.13.13
sbt.version = 1.1.0
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
logLevel := Level.Warn

//addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.5.2")
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.4.0")

addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.4.8")
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.3")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
12 changes: 8 additions & 4 deletions src/main/scala/com/timeout/docless/schema/JsonSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,15 @@ object JsonSchema
fromRegex[K](".*".r)
}

def tagId[A](tag: ru.WeakTypeTag[A]): String =
tag.tpe.typeSymbol.name +
(if (tag.tpe.typeArgs.nonEmpty) "[" + tag.tpe.typeArgs.map(_.typeSymbol.name).mkString(",") + "]" else "")

def instance[A](
obj: => JsonObject
)(implicit tag: ru.WeakTypeTag[A]): JsonSchema[A] =
new JsonSchema[A] {
override def id = tag.tpe.typeSymbol.fullName
override def id = tagId(tag)
override def inline = false
override def jsonObject = obj
override def relatedDefinitions = Set.empty
Expand All @@ -130,7 +134,7 @@ object JsonSchema
obj: => JsonObject
)(implicit tag: ru.WeakTypeTag[A]): JsonSchema[F[A]] =
new JsonSchema[F[A]] {
override def id = tag.tpe.typeSymbol.fullName
override def id = tagId(tag)
override def inline = false
override def jsonObject = obj
override def relatedDefinitions = Set.empty
Expand All @@ -139,7 +143,7 @@ object JsonSchema
def instanceAndRelated[A](
pair: => (JsonObject, Set[Definition])
)(implicit tag: ru.WeakTypeTag[A]): JsonSchema[A] = new JsonSchema[A] {
override def id = tag.tpe.typeSymbol.fullName
override def id = tagId(tag)
override def inline = false
override def jsonObject = pair._1
override def relatedDefinitions = pair._2
Expand All @@ -149,7 +153,7 @@ object JsonSchema
obj: => JsonObject
)(implicit tag: ru.WeakTypeTag[A]): JsonSchema[A] =
new JsonSchema[A] {
override def id = tag.tpe.typeSymbol.fullName
override def id = tagId(tag)
override def inline = true
override def relatedDefinitions = Set.empty
override def jsonObject = obj
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/com/timeout/docless/schema/Primitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ trait Primitives {
).asJsonObject
)

implicit def listSchema[A: JsonSchema]: JsonSchema[List[A]] = {
val schema = implicitly[JsonSchema[A]]
implicit def listSchema[A: JsonSchema](implicit schema: JsonSchema[A], tag: ru.WeakTypeTag[A]): JsonSchema[List[A]] = {
inlineInstance[List[A]](
JsonObject.fromMap(
Map(
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/timeout/docless/swagger/APISchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ case class APISchema(

object APISchema {

implicit val externalDocsEncoder: Encoder[ExternalDocs] =
implicit val externalDocsEncoder: Encoder[ExternalDocs] =
deriveEncoder[ExternalDocs]
implicit val contactEncoder: Encoder[Info.Contact] =
deriveEncoder[Info.Contact]
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/timeout/docless/swagger/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ case class Path(id: String,

def paramRefs: Set[RefWithContext] =
parameters.flatMap(paramRef).toSet ++
operations.foldMap(_.parameters.flatMap(paramRef))
operations.values.toList.foldMap(_.parameters.flatMap(paramRef))

def responseRefs: Set[RefWithContext] =
operations.flatMap {
Expand Down
20 changes: 18 additions & 2 deletions src/test/scala/com/timeout/docless/schema/JsonSchemaTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ object JsonSchemaTest {
val ref = "$ref"

def id[T: u.WeakTypeTag] =
getClass.getCanonicalName.replace('$', '.') +
implicitly[u.WeakTypeTag[T]].tpe.typeSymbol.name
JsonSchema.tagId(implicitly[u.WeakTypeTag[T]])

sealed abstract class E extends EnumEntry

Expand Down Expand Up @@ -136,6 +135,23 @@ class JsonSchemaTest extends FreeSpec {
schema.relatedDefinitions should ===(Set(fs.NamedDefinition("fooOpt")))
}

"handles list of non-primitive types" in {
implicit val fs: JsonSchema[Foo] = fooSchema

val schema = JsonSchema.deriveFor[List[Foo]]
parser.parse(s"""
|{
| "type": "array",
| "items": {
| "$ref" : "#/definitions/${id[Foo]}"
| }
|}
|
""".stripMargin) should ===(Right(schema.asJson))

schema.id should ===(id[List[Foo]])
}

"with types extending enumeratum.EnumEntry" - {
"does not derive automatically" in {
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SwaggerTest extends FreeSpec {
val petstoreSchema = PetstoreSchema()
val json = JsonLoader.fromResource("/swagger-schema.json")
val schema = JsonSchemaFactory.byDefault().getJsonSchema(json)
val printer = Printer.spaces2.copy(dropNullKeys = true)
val printer = Printer.spaces2.copy(dropNullValues = true)
val jsonS = printer.pretty(petstoreSchema.asJson)
val report = schema.validate(JsonLoader.fromString(jsonS))
val err = System.err
Expand Down