Skip to content

Commit

Permalink
Revert "Upgrade dependencies (#694)"
Browse files Browse the repository at this point in the history
This reverts commit 0c349ca.
  • Loading branch information
gheine committed Jul 9, 2024
1 parent 0c349ca commit 33d5e3b
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 72 deletions.
58 changes: 28 additions & 30 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "apibuilder-generator"

organization := "io.apibuilder.generator"

ThisBuild / scalaVersion := "2.13.14"
ThisBuild / scalaVersion := "2.13.11"

ThisBuild / javacOptions ++= Seq("-source", "17", "-target", "17")

Expand Down Expand Up @@ -33,7 +33,7 @@ lazy val generated = project
.settings(
libraryDependencies ++= Seq(
ws,
"org.scalacheck" %% "scalacheck" % "1.18.0" % Test
"org.scalacheck" %% "scalacheck" % "1.15.4" % Test
),
scalacOptions ++= allScalacOptions
)
Expand All @@ -60,7 +60,7 @@ lazy val generator = project
routesGenerator := InjectedRoutesGenerator,
libraryDependencies ++= Seq(
ws,
"org.scalatestplus.play" %% "scalatestplus-play" % "7.0.1" % "test"
"org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % "test"
),
scalacOptions ++= allScalacOptions,
Test / javaOptions ++= Seq(
Expand All @@ -75,9 +75,9 @@ lazy val javaAwsLambdaPojos = project
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= Seq(
"com.amazonaws" % "aws-java-sdk-dynamodb" % "1.12.731",
"com.amazonaws" % "aws-java-sdk-dynamodb" % "1.11.461",
"me.geso" % "tinyvalidator" % "0.9.1",
"org.projectlombok" % "lombok" % "1.18.32"
"org.projectlombok" % "lombok" % "1.18.24"
)
)

Expand All @@ -88,7 +88,7 @@ lazy val scalaGenerator = project
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= Seq(
"org.scalameta" %% "scalafmt-core" % "3.8.1"
"org.scalameta" %% "scalafmt-core" % "2.3.2"
)
)

Expand All @@ -98,7 +98,7 @@ lazy val csharpGenerator = project
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "2.12.0"
"org.typelevel" %% "cats-core" % "2.10.0"
)
)

Expand All @@ -108,7 +108,7 @@ lazy val elmGenerator = project
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "2.12.0"
"org.typelevel" %% "cats-core" % "2.10.0"
)
)

Expand Down Expand Up @@ -145,10 +145,9 @@ lazy val graphQLGenerator = project
),
)

val mockitoVersion = "4.11.0"
val scalatestVersion = "3.2.18"
val jacksonVersion = "2.17.1"
val kotlinLangVersion = "2.0.0"
val kotlinLangVersion = "1.3.72"
val mockitoVersion = "4.5.1"
val scalatestVersion = "3.2.12"

lazy val kotlinGenerator = project
.in(file("kotlin-generator"))
Expand All @@ -157,14 +156,13 @@ lazy val kotlinGenerator = project
Test / fork := true,
Test / baseDirectory := file("."),
libraryDependencies ++= Seq(
"com.fasterxml.jackson.module" % "jackson-module-kotlin" % jacksonVersion,
"com.fasterxml.jackson.core" % "jackson-annotations" % jacksonVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion,
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % jacksonVersion,
"org.threeten" % "threetenbp" % "1.6.9",
"com.fasterxml.jackson.module" % "jackson-module-kotlin" % "2.9.9",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.9.9",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.9.9",
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.9.9",
"org.threeten" % "threetenbp" % "1.3.8",
"com.squareup" % "kotlinpoet" % "1.3.0",
//"com.squareup" % "kotlinpoet-jvm" % "1.18.0",
"com.squareup.retrofit2" % "retrofit" % "2.11.0",
"com.squareup.retrofit2" % "retrofit" % "2.5.0",
"com.jakewharton.retrofit" % "retrofit2-rxjava2-adapter" % "1.0.0",
"org.jetbrains.kotlin" % "kotlin-stdlib" % kotlinLangVersion % "test",
"org.jetbrains.kotlin" % "kotlin-stdlib-jdk8" % kotlinLangVersion % "test",
Expand All @@ -183,7 +181,7 @@ lazy val csvGenerator = project
Test / fork := true,
Test / baseDirectory := file("."),
libraryDependencies ++= Seq(
"org.apache.commons" % "commons-csv" % "1.11.0"
"org.apache.commons" % "commons-csv" % "1.7"
)
)

Expand All @@ -193,7 +191,7 @@ lazy val postmanGenerator = project
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= Seq(
"com.lihaoyi" %% "ammonite-ops" % "2.4.1",
"com.lihaoyi" %% "ammonite-ops" % "2.0.4",
)
)

Expand All @@ -203,19 +201,18 @@ lazy val commonSettings: Seq[Setting[_]] = Seq(
testOptions += Tests.Argument("-oF"),
libraryDependencies ++= Seq(
guice,
"com.typesafe.play" %% "play-json-joda" % "2.9.4",
"com.google.inject" % "guice" % "5.1.0",
"com.google.inject.extensions" % "guice-assistedinject" % "5.1.0",
"org.atteo" % "evo-inflector" % "1.3",
"com.squareup.retrofit2" % "retrofit" % "2.11.0",
"io.reactivex.rxjava2" % "rxjava" % "2.2.21",
"org.typelevel" %% "cats-core" % "2.12.0",
"org.scalatestplus.play" %% "scalatestplus-play" % "7.0.1" % "test",
"org.atteo" % "evo-inflector" % "1.2.2",
"com.squareup.retrofit2" % "retrofit" % "2.5.0",
"io.reactivex.rxjava2" % "rxjava" % "2.2.4",
"org.typelevel" %% "cats-core" % "2.10.0",
"org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.11.0" % Test,
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.7.0" % Test,
"org.mockito" % "mockito-core" % mockitoVersion % Test,
"com.github.javaparser" % "javaparser-core" % "3.25.10" % Test,
"org.scalameta" %% "scalameta" % "4.9.5" % Test,
"com.github.javaparser" % "javaparser-core" % "3.24.2" % Test,
"org.scalameta" %% "scalameta" % "4.4.3" % Test,
"com.squareup" % "javapoet" % "1.13.0",
),
scalacOptions ++= allScalacOptions,
Expand All @@ -226,3 +223,4 @@ lazy val commonSettings: Seq[Setting[_]] = Seq(
Compile / doc / sources := Seq.empty,
Compile / packageDoc / publishArtifact := false,
)
version := "0.10.19"
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models.generator.kotlin

import java.io.StringWriter

import com.fasterxml.jackson.annotation._
import com.fasterxml.jackson.core.{JsonGenerator, JsonParser, Version}
import com.fasterxml.jackson.databind._
Expand All @@ -21,17 +22,15 @@ class KotlinGenerator
extends CodeGenerator
with KotlinUtil {

private implicit def classToClassName(clazz: java.lang.Class[?]): ClassName = {
new ClassName(clazz.getPackage.getName, clazz.getSimpleName)
}
private implicit def classToClassName(clazz: java.lang.Class[_]): ClassName = new ClassName(clazz.getPackage.getName, clazz.getSimpleName)

private val kdocClassMessage = s"This code was generated by [${classOf[KotlinGenerator].getName}]\n"

override def invoke(form: InvocationForm): Either[Seq[String], Seq[File]] = {
Right(new GeneratorHelper(form.service).generateSourceFiles(form.service))
}

private class GeneratorHelper(service: Service) {
class GeneratorHelper(service: Service) {

private val nameSpace = makeNameSpace(service.namespace)
private val sharedNameSpace = "io.apibuilder.app"
Expand All @@ -44,13 +43,13 @@ class KotlinGenerator
//Errors
private val errorsHelperClassName = "ErrorsHelper"

private val commonNetworkErrorsClassName = new ClassName(sharedNameSpace, "CommonNetworkErrors")
private val eitherErrorTypeClassName = new ClassName(sharedNameSpace, "EitherCallOrCommonNetworkError")
private val callErrorEitherErrorTypeClassName = new ClassName(eitherErrorTypeClassName.getCanonicalName, "CallError")
private val commonErrorEitherErrorTypeClassName = new ClassName(eitherErrorTypeClassName.getCanonicalName, "CommonNetworkError")
val commonNetworkErrorsClassName = new ClassName(sharedNameSpace, "CommonNetworkErrors")
val eitherErrorTypeClassName = new ClassName(sharedNameSpace, "EitherCallOrCommonNetworkError")
val callErrorEitherErrorTypeClassName = new ClassName(eitherErrorTypeClassName.getCanonicalName, "CallError")
val commonErrorEitherErrorTypeClassName = new ClassName(eitherErrorTypeClassName.getCanonicalName, "CommonNetworkError")

private val apiNetworkCallResponseTypeClassName = new ClassName(sharedNameSpace, "ApiNetworkCallResponse")
private val errorResponsesString = "ErrorResponses"
val apiNetworkCallResponseTypeClassName = new ClassName(sharedNameSpace, "ApiNetworkCallResponse")
val errorResponsesString = "ErrorResponses"
private val processCommonNetworkErrorString = "processCommonNetworkError"


Expand All @@ -61,9 +60,9 @@ class KotlinGenerator
private val serverUnknownErrorClassName = "UnknownNetworkError"


private def createDirectoryPath(namespace: String) = namespace.replace('.', '/')
def createDirectoryPath(namespace: String) = namespace.replace('.', '/')

private def generateEnum(`enum`: io.apibuilder.spec.v0.models.Enum): File = {
def generateEnum(`enum`: io.apibuilder.spec.v0.models.Enum): File = {
val className = toClassName(enum.name)

val builder = TypeSpec.enumBuilder(className)
Expand Down Expand Up @@ -98,11 +97,11 @@ class KotlinGenerator
makeFile(enumsNameSpace, className, builder)
}

private def getRetrofitSingleTypeWrapperClass(): ClassName = classToClassName(classOf[Single[Void]])
def getRetrofitSingleTypeWrapperClass(): ClassName = classToClassName(classOf[Single[Void]])

private def getRetrofitResponseTypeWrapperClass(): ClassName = classToClassName(classOf[retrofit2.Response[Void]])
def getRetrofitResponseTypeWrapperClass(): ClassName = classToClassName(classOf[retrofit2.Response[Void]])

private def generateUnionType(union: Union, service: Service): File = {
def generateUnionType(union: Union, service: Service): File = {
val className = toClassName(union.name)
val undefinedClassName = className + "Undefined"
val modelsUnderUnion = service.models
Expand Down Expand Up @@ -246,15 +245,15 @@ class KotlinGenerator
companionBuilder.build()
}

private def generateModel(model: Model, union: Option[Union], service: Service): File = {
def generateModel(model: Model, union: Option[Union], service: Service): File = {
val className = toClassName(model.name)

val builder = generateModelTypeBuilder(model, union, service)

makeFile(modelsNameSpace, className, builder)
}

private def generateResource(resource: Resource): File = {
def generateResource(resource: Resource): File = {
val className = toClassName(resource.plural) + "Client"

val builder = TypeSpec.interfaceBuilder(className)
Expand Down Expand Up @@ -537,9 +536,9 @@ class KotlinGenerator
makeFile(modelsNameSpace, className, builder)
}

private def emptyCodeBlock(): CodeBlock = CodeBlock.builder().build()
def emptyCodeBlock(): CodeBlock = CodeBlock.builder().build()

private def buildJacksonTypeReferenceTypeSpec(ptn: ParameterizedTypeName): TypeSpec = {
def buildJacksonTypeReferenceTypeSpec(ptn: ParameterizedTypeName): TypeSpec = {
// see https://stackoverflow.com/questions/6349421/how-to-use-jackson-to-deserialise-an-array-of-objects
// see https://fasterxml.github.io/jackson-core/javadoc/2.9/com/fasterxml/jackson/core/type/TypeReference.html
require(ptn.getRawType.toString.equals("kotlin.collections.List"))
Expand All @@ -552,7 +551,7 @@ class KotlinGenerator
.build()
}

private def generateJacksonObjectMapper(): File = {
def generateJacksonObjectMapper(): File = {

val moduleProperty = PropertySpec.builder("module", classOf[SimpleModule])
.initializer("%T(%T(1, 0, 0, null, null, null))", classOf[SimpleModule], classOf[Version])
Expand Down Expand Up @@ -643,7 +642,7 @@ class KotlinGenerator
}


private def generateErrorsHelper(): File = {
def generateErrorsHelper(): File = {

val fileName = errorsHelperClassName

Expand Down Expand Up @@ -797,7 +796,7 @@ class KotlinGenerator
}


private def generateEnums(enums: Seq[Enum]): Seq[File] = {
def generateEnums(enums: Seq[Enum]): Seq[File] = {
enums.map(generateEnum(_))
}

Expand Down Expand Up @@ -825,7 +824,7 @@ class KotlinGenerator
}

//write one file with a single class
private def makeFile(packageName: String, name: String, typeSpecBuilder: TypeSpec.Builder): File = {
def makeFile(packageName: String, name: String, typeSpecBuilder: TypeSpec.Builder): File = {
val typeSpec = typeSpecBuilder.build
val kFile = FileSpec.get(packageName, typeSpec)
val sw = new StringWriter(1024)
Expand All @@ -838,7 +837,7 @@ class KotlinGenerator
}

//write one file with multiple classes
private def makeFile(name: String, fileBuilder: FileSpec.Builder): File = {
def makeFile(name: String, fileBuilder: FileSpec.Builder): File = {
val sw = new StringWriter(1024)
val fileSpec = fileBuilder.build()
val packageName = fileSpec.getPackageName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ class KotlinGeneratorTest

import models.TestHelper._

/* This test is no longer working. TODO: debug and upgrade
private val serviceDefs = Seq(builtInTypesService,
// dateTimeService,
// generatorApiServiceWithUnionAndDiscriminator,
// generatorApiServiceWithUnionAndDescriminator,
apidocApiService,
collectionJsonDefaultsService,
referenceApiService,
referenceWithImportsApiService)

describe("Kotlin code compiles") {
for (service <- serviceDefs) {
it(s"[${service.name}] imports=${service.imports.nonEmpty}") {
it(s"[${service.name}] imports=${(service.imports.size > 0)}") {
val dir = generateSourceFiles(service)
assertKotlinCodeCompiles(dir)
}
}
}
*/

describe("Package names") {
val service = referenceApiService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ object KotlinTestHelper extends Matchers {

def assertKotlinCodeCompiles(kotlinSourceDirectory: java.io.File): Unit = {
assert(kotlinSourceDirectory.exists())
assert(kotlinSourceDirectory.canRead)
assert(kotlinSourceDirectory.isDirectory)
assert(kotlinSourceDirectory.canRead())
assert(kotlinSourceDirectory.isDirectory())
val result = new KotlinCompiler().compileSourceDir(kotlinSourceDirectory.toPath)
result.isSuccess shouldBe true
()
Expand Down
3 changes: 1 addition & 2 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
sbt.version=1.10.0

sbt.version=1.7.1
4 changes: 1 addition & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ logLevel := Level.Warn
resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.9.3")

addSbtPlugin("com.github.sbt" % "sbt-javaagent" % "0.1.8")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.20")
2 changes: 1 addition & 1 deletion scala-generator/src/main/scala/utils/ScalaFormatter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package utils
object ScalaFormatter {

def format(code: String): Either[Throwable, String] =
org.scalafmt.Scalafmt.format(code, org.scalafmt.config.ScalafmtConfig.default)
org.scalafmt.Scalafmt.format(code, org.scalafmt.config.ScalafmtConfig.default120)
.toEither

}
14 changes: 8 additions & 6 deletions scala-generator/src/test/scala/utils/ScalaFormatterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import org.scalatest.matchers.should.Matchers

class ScalaFormatterSpec extends AnyFunSpec with Matchers {

private[this] def format(code: String) = {
ScalaFormatter.format(code)
}

it("ScalaFormatter should format valid scala code") {
format("case class Foo(bar: String)") should be(Symbol("right"))
val contents = "case class Foo(bar: String)"
val result = ScalaFormatter.format(contents)

result should be(Symbol("right"))
}

it("ScalaFormatter should fail to format invalid scala code") {
format("Foo Bar {") should be(Symbol("left"))
val contents = "Foo Bar"
val result = ScalaFormatter.format(contents)

result should be(Symbol("left"))
}

}

0 comments on commit 33d5e3b

Please sign in to comment.