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

Update error_prone_annotations to 2.21.1 #610

Closed
541 changes: 532 additions & 9 deletions README.md

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
organization in ThisBuild := "com.iheart"
organization in ThisBuild := "io.github.play-swagger"

sonatypeCredentialHost := "s01.oss.sonatype.org"

ThisBuild / scalafixDependencies ++= Seq(
"com.github.liancheng" %% "organize-imports" % "0.6.0",
Expand Down Expand Up @@ -45,7 +47,7 @@ lazy val playSwagger = project.in(file("core"))
"org.scalameta" %% "scalameta" % "4.8.5",
"net.steppschuh.markdowngenerator" % "markdowngenerator" % "1.3.1.1",
"joda-time" % "joda-time" % "2.12.5" % Test,
"com.google.errorprone" % "error_prone_annotations" % "2.20.0" % Test
"com.google.errorprone" % "error_prone_annotations" % "2.21.1" % Test
),
libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always,
addCompilerPlugin("com.github.takezoe" %% "runtime-scaladoc-reader" % "1.0.3"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import scala.reflect.runtime.universe._

import com.fasterxml.jackson.databind.{BeanDescription, ObjectMapper}
import com.github.takezoe.scaladoc.Scaladoc
import com.iheart.playSwagger.Domain.{CustomMappings, Definition, GenSwaggerParameter, SwaggerParameter}
import com.iheart.playSwagger.SwaggerParameterMapper.mapParam
import com.iheart.playSwagger.Domain.Definition
import com.iheart.playSwagger.domain.parameter.{GenSwaggerParameter, SwaggerParameter}
import com.iheart.playSwagger.generator.SwaggerParameterMapper
import net.steppschuh.markdowngenerator.MarkdownElement
import net.steppschuh.markdowngenerator.link.Link
import net.steppschuh.markdowngenerator.table.Table
Expand All @@ -18,8 +19,7 @@ import net.steppschuh.markdowngenerator.text.heading.Heading
import play.routes.compiler.Parameter

final case class DefinitionGenerator(
modelQualifier: DomainModelQualifier = PrefixDomainModelQualifier(),
mappings: CustomMappings = Nil,
mapper: SwaggerParameterMapper,
swaggerPlayJava: Boolean = false,
_mapper: ObjectMapper = new ObjectMapper(),
namingStrategy: NamingStrategy = NamingStrategy.None,
Expand Down Expand Up @@ -109,7 +109,7 @@ final case class DefinitionGenerator(
val typeName = parametricType.resolve(rawTypeName)
// passing None for 'fixed' and 'default' here, since we're not dealing with route parameters
val param = Parameter(name, typeName, None, None)
mapParam(param, modelQualifier, mappings, paramDescriptions.get(field.name.decodedName.toString))
mapper.mapParam(param, paramDescriptions.get(field.name.decodedName.toString))
}
}

Expand All @@ -119,7 +119,7 @@ final case class DefinitionGenerator(
)
}

private def definitionForPOJO(tpe: Type): Seq[Domain.SwaggerParameter] = {
private def definitionForPOJO(tpe: Type): Seq[SwaggerParameter] = {
val m = runtimeMirror(cl)
val clazz = m.runtimeClass(tpe.typeSymbol.asClass)
val `type` = _mapper.constructType(clazz)
Expand All @@ -142,7 +142,7 @@ final case class DefinitionGenerator(
generalTypeName
}
val param = Parameter(name, typeName, None, None)
mapParam(param, modelQualifier, mappings)
mapper.mapParam(param, None)
}
}

Expand All @@ -166,9 +166,9 @@ final case class DefinitionGenerator(
case None =>
val thisDef = definition(defName)
val refNames: Seq[String] = for {
p thisDef.properties.collect(genSwaggerParameter)
className findRefTypes(p)
if modelQualifier.isModel(className)
p <- thisDef.properties.collect(genSwaggerParameter)
className <- findRefTypes(p)
if mapper.isReference(className)
} yield className

refNames.foldLeft(thisDef :: memo) { (foundDefs, refName) =>
Expand All @@ -185,27 +185,23 @@ final case class DefinitionGenerator(

object DefinitionGenerator {
def apply(
domainNameSpace: String,
customParameterTypeMappings: CustomMappings,
mapper: SwaggerParameterMapper,
swaggerPlayJava: Boolean,
namingStrategy: NamingStrategy
)(implicit cl: ClassLoader): DefinitionGenerator =
DefinitionGenerator(
PrefixDomainModelQualifier(domainNameSpace),
customParameterTypeMappings,
new DefinitionGenerator(
mapper,
swaggerPlayJava,
namingStrategy = namingStrategy
)

def apply(
domainNameSpace: String,
customParameterTypeMappings: CustomMappings,
mapper: SwaggerParameterMapper,
namingStrategy: NamingStrategy,
embedScaladoc: Boolean
)(implicit cl: ClassLoader): DefinitionGenerator =
DefinitionGenerator(
PrefixDomainModelQualifier(domainNameSpace),
customParameterTypeMappings,
new DefinitionGenerator(
mapper,
namingStrategy = namingStrategy,
embedScaladoc = embedScaladoc
)
Expand Down
61 changes: 1 addition & 60 deletions core/src/main/scala/com/iheart/playSwagger/Domain.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.iheart.playSwagger

import play.api.libs.json.{JsObject, JsPath, JsValue, Reads}
import com.iheart.playSwagger.domain.parameter.SwaggerParameter

object Domain {
type Path = String
Expand All @@ -11,63 +11,4 @@ object Domain {
properties: Seq[SwaggerParameter],
description: Option[String] = None
)

sealed trait SwaggerParameter {
def name: String
def required: Boolean
def nullable: Option[Boolean]
def default: Option[JsValue]
def description: Option[String]

def update(required: Boolean, nullable: Boolean, default: Option[JsValue]): SwaggerParameter
}

final case class GenSwaggerParameter(
name: String,
referenceType: Option[String] = None,
`type`: Option[String] = None,
format: Option[String] = None,
required: Boolean = true,
nullable: Option[Boolean] = None,
default: Option[JsValue] = None,
example: Option[JsValue] = None,
items: Option[SwaggerParameter] = None,
enum: Option[Seq[String]] = None,
description: Option[String] = None
) extends SwaggerParameter {
def update(_required: Boolean, _nullable: Boolean, _default: Option[JsValue]): GenSwaggerParameter =
copy(required = _required, nullable = Some(_nullable), default = _default)
}

final case class CustomSwaggerParameter(
name: String,
specAsParameter: List[JsObject],
specAsProperty: Option[JsObject],
required: Boolean = true,
nullable: Option[Boolean] = None,
default: Option[JsValue] = None,
description: Option[String] = None
) extends SwaggerParameter {
def update(_required: Boolean, _nullable: Boolean, _default: Option[JsValue]): CustomSwaggerParameter =
copy(required = _required, nullable = Some(_nullable), default = _default)
}

type CustomMappings = List[CustomTypeMapping]

case class CustomTypeMapping(
`type`: String,
specAsParameter: List[JsObject] = Nil,
specAsProperty: Option[JsObject] = None,
required: Boolean = true
)

object CustomTypeMapping {
import play.api.libs.functional.syntax._
implicit val csmFormat: Reads[CustomTypeMapping] = (
(JsPath \ 'type).read[String] and
(JsPath \ 'specAsParameter).read[List[JsObject]] and
(JsPath \ 'specAsProperty).readNullable[JsObject] and
((JsPath \ 'required).read[Boolean] orElse Reads.pure(true))
)(CustomTypeMapping.apply _)
}
}
Loading
Loading