Skip to content

Commit

Permalink
Remove whitespace in sdkId for rendering (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Kozłowski authored Jan 19, 2022
1 parent e3d718e commit d87e412
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
20 changes: 8 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ lazy val codegen = projectMatrix
.settings(
buildInfoKeys := Seq[BuildInfoKey](version, scalaBinaryVersion),
buildInfoPackage := "smithy4s.codegen",
isCE3 := true,
libraryDependencies ++= Seq(
Dependencies.Cats.core.value,
Dependencies.Smithy.model,
Expand All @@ -308,8 +309,10 @@ lazy val codegen = projectMatrix
"com.lihaoyi" %% "os-lib" % "0.8.0",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.2.0",
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"io.get-coursier" %% "coursier" % "2.0.16"
"io.get-coursier" %% "coursier" % "2.0.16",
Dependencies.Weaver.cats.value % Test
),
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
scalacOptions := scalacOptions.value
.filterNot(Seq("-Ywarn-value-discard", "-Wvalue-discard").contains)
)
Expand All @@ -328,8 +331,7 @@ lazy val `codegen-cli` = projectMatrix
libraryDependencies ++= Seq(
"com.monovore" %% "decline" % "2.2.0",
Dependencies.Weaver.cats.value % Test
),
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
)
)

/**
Expand Down Expand Up @@ -386,7 +388,6 @@ lazy val protocol = projectMatrix
Dependencies.Weaver.scalacheck.value % Test
),
Test / fork := true,
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
javacOptions ++= Seq(
"-source",
"1.8",
Expand All @@ -405,7 +406,6 @@ lazy val openapi = projectMatrix
.jvmPlatform(buildtimejvmScala2Versions, jvmDimSettings)
.dependsOn(protocol)
.settings(
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
isCE3 := true,
libraryDependencies ++= Seq(
Dependencies.Cats.core.value,
Expand All @@ -432,8 +432,7 @@ lazy val json = projectMatrix
Dependencies.Weaver.cats.value % Test,
Dependencies.Weaver.scalacheck.value % Test
),
Test / fork := virtualAxes.value.contains(VirtualAxis.jvm),
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
Test / fork := virtualAxes.value.contains(VirtualAxis.jvm)
)
.jvmPlatform(allJvmScalaVersions, jvmDimSettings)
.jsPlatform(allJsScalaVersions, jsDimSettings)
Expand All @@ -460,8 +459,7 @@ lazy val http4s = projectMatrix
if (virtualAxes.value.contains(CatsEffect2Axis))
moduleName.value + "-ce2"
else moduleName.value
},
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
}
)
.http4sPlatform(allJvmScalaVersions, jvmDimSettings)

Expand All @@ -484,8 +482,7 @@ lazy val `http4s-swagger` = projectMatrix
if (virtualAxes.value.contains(CatsEffect2Axis))
moduleName.value + "-ce2"
else moduleName.value
},
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
}
)
.http4sJvmPlatform(allJvmScalaVersions, jvmDimSettings)

Expand All @@ -509,7 +506,6 @@ lazy val tests = projectMatrix
Dependencies.Weaver.cats.value
)
},
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
Compile / smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "pizza.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "weather.smithy"
Expand Down
11 changes: 10 additions & 1 deletion modules/codegen/src/smithy4s/codegen/SmithyToIR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ object SmithyToIR {
CompilationUnit(namespace, new SmithyToIR(model, namespace).allDecls)
}

private[codegen] def prettifyName(
maybeSdkId: Option[String],
shapeName: String
): String = {
maybeSdkId
.map(_.replaceAll("\\s+", ""))
.getOrElse(shapeName)
}

}

private[codegen] class SmithyToIR(model: Model, namespace: String) {
Expand Down Expand Up @@ -160,7 +169,7 @@ private[codegen] class SmithyToIR(model: Model, namespace: String) {
.flatMap(st => Option(st.getSdkId()))
.filterNot(_.isEmpty)

val prettyName = maybeSdkId.getOrElse(shape.name)
val prettyName = SmithyToIR.prettifyName(maybeSdkId, shape.name)

Service(
prettyName,
Expand Down
34 changes: 34 additions & 0 deletions modules/codegen/test/src/smithy4s/codegen/SmithyToIRSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package smithy4s.codegen

import weaver._

object SmithyToIRSpec extends FunSuite {

test("prettifyName: sdkId takes precedence") {
expect.eql(
SmithyToIR.prettifyName(Some("Example"), "unused"),
"Example"
)
}
test("prettifyName: shapeName is used as a fallback") {
expect.eql(
SmithyToIR.prettifyName(None, "Example"),
"Example"
)
}

test("prettifyName removes whitespace in sdkId") {
expect.eql(
SmithyToIR.prettifyName(Some("QuickDB \t\nStreams"), "unused"),
"QuickDBStreams"
)
}

// Not a feature, just verifying the name is unaffected
test("prettifyName ignores whitespace in shape name") {
expect.eql(
SmithyToIR.prettifyName(None, "This Has Spaces"),
"This Has Spaces"
)
}
}
3 changes: 2 additions & 1 deletion project/Smithy4sPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ object Smithy4sPlugin extends AutoPlugin {
incOptions := incOptions.value.withLogRecompileOnMacro(false),
// https://scalacenter.github.io/scalafix/docs/users/installation.html
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision
semanticdbVersion := scalafixSemanticdb.revision,
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
) ++ publishSettings ++ loggingSettings ++ compilerPlugins ++ headerSettings

lazy val compilerPlugins = Seq(
Expand Down

0 comments on commit d87e412

Please sign in to comment.