Skip to content

Commit

Permalink
Bumping to guardrail 1.0.0-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Dec 14, 2023
1 parent 242e61d commit 21bb434
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
4 changes: 3 additions & 1 deletion modules/core/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ description := "Core of sbt-guardrail plugin, for custom forks of guardrail"
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3")

// Explicitly pinning this to a binding so we can grep for it
val guardrailCoreVersion = "0.75.3"
val guardrailCoreVersion = "1.0.0-SNAPSHOT"
resolvers +=
"Sonatype OSS Snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots"

// Dependencies
libraryDependencies ++= Seq(
Expand Down
50 changes: 25 additions & 25 deletions modules/core/src/main/scala/AbstractCodegenPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import dev.guardrail.{
Args => ArgsImpl,
AuthImplementation,
CodegenTarget => CodegenTargetImpl,
Context => ContextImpl
Context => ContextImpl,
TagsBehaviour
}

trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin =>
trait AbstractGuardrailPlugin { self: AutoPlugin =>
val runner = new GuardrailRunner {}
override def requires = JvmPlugin
override def trigger = allRequirements

Expand All @@ -29,7 +31,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin =>
encodeOptionalAs: Option[CodingConfig],
decodeOptionalAs: Option[CodingConfig],
customExtraction: Option[Boolean],
tagsBehaviour: Option[ContextImpl.TagsBehaviour],
tagsBehaviour: Option[TagsBehaviour],
authImplementation: Option[AuthImplementation]
): ArgsImpl = {
val propertyRequirement = (encodeOptionalAs, decodeOptionalAs) match {
Expand All @@ -45,27 +47,25 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin =>
def kindaLens[A](member: Option[A])(proj: A => ContextImpl => ContextImpl): ContextImpl => ContextImpl = member.fold[ContextImpl => ContextImpl](identity _)(proj)

val contextTransforms = Seq[ContextImpl => ContextImpl](
kindaLens(authImplementation)(a => _.copy(authImplementation=a)),
kindaLens(customExtraction)(a => _.copy(customExtraction=a)),
kindaLens(tagsBehaviour)(a => _.copy(tagsBehaviour=a)),
kindaLens(tracing)(a => _.copy(tracing=a))
kindaLens(authImplementation)(a => _.withAuthImplementation(a)),
kindaLens(customExtraction)(a => _.withCustomExtraction(a)),
kindaLens(tagsBehaviour)(a => _.withTagsBehaviour(a)),
kindaLens(tracing)(a => _.withTracing(a))
)

ArgsImpl.empty.copy(
defaults=defaults,
kind=kind,
specPath=specPath.map(_.getPath),
packageName=packageName.map(_.split('.').toList),
dtoPackage=dtoPackage.toList.flatMap(_.split('.').filterNot(_.isEmpty).toList),
imports=imports,
context=contextTransforms.foldLeft(
ContextImpl.empty.copy(
framework=framework,
modules=modules,
propertyRequirement=propertyRequirement
)
)({ case (acc, next) => next(acc) })
)
ArgsImpl.empty
.withDefaults(defaults)
.withKind(kind)
.withSpecPath(specPath.map(_.getPath))
.withPackageName(packageName.map(_.split('.').toList))
.withDtoPackage(dtoPackage.toList.flatMap(_.split('.').filterNot(_.isEmpty).toList))
.withImports(imports)
.withContext(contextTransforms.foldLeft(
ContextImpl.empty
.withFramework(framework)
.withModules(modules)
.withPropertyRequirement(propertyRequirement)
)({ case (acc, next) => next(acc) }))
}

sealed trait ClientServer {
Expand All @@ -83,7 +83,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin =>
encodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default,
decodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default,
customExtraction: Keys.GuardrailConfigValue[Boolean] = Keys.Default,
tagsBehaviour: Keys.GuardrailConfigValue[ContextImpl.TagsBehaviour] = Keys.Default,
tagsBehaviour: Keys.GuardrailConfigValue[TagsBehaviour] = Keys.Default,
authImplementation: Keys.GuardrailConfigValue[AuthImplementation] = Keys.Default,
): Types.Args = (language, impl(
kind = kind,
Expand Down Expand Up @@ -112,7 +112,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin =>
encodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default,
decodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default,
customExtraction: Keys.GuardrailConfigValue[Boolean] = Keys.Default,
tagsBehaviour: Keys.GuardrailConfigValue[ContextImpl.TagsBehaviour] = Keys.Default,
tagsBehaviour: Keys.GuardrailConfigValue[TagsBehaviour] = Keys.Default,
authImplementation: Keys.GuardrailConfigValue[AuthImplementation] = Keys.Default,

// Deprecated parameters
Expand Down Expand Up @@ -200,7 +200,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin =>
_ =>
GuardrailAnalysis(
BuildInfo.version,
Tasks.guardrailTask(guardrailRunner)(tasks, sources.head)
Tasks.guardrailTask(runner.guardrailRunner)(tasks, sources.head)
).products
}

Expand Down
6 changes: 3 additions & 3 deletions modules/core/src/main/scala/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.io.File
import _root_.sbt.{ SettingKey, TaskKey }
import scala.language.implicitConversions

import dev.guardrail.{AuthImplementation, Context}
import dev.guardrail.{AuthImplementation, Context, TagsBehaviour}
import dev.guardrail.terms.protocol.PropertyRequirement

sealed trait CodingConfig {
Expand Down Expand Up @@ -44,8 +44,8 @@ object Keys {
def codingOptional: CodingConfig = CodingConfig.Optional
def codingOptionalLegacy: CodingConfig = CodingConfig.OptionalLegacy

def tagsAreIgnored: Context.TagsBehaviour = Context.TagsAreIgnored
def tagsAsPackage: Context.TagsBehaviour = Context.PackageFromTags
def tagsAreIgnored: TagsBehaviour = TagsBehaviour.TagsAreIgnored
def tagsAsPackage: TagsBehaviour = TagsBehaviour.PackageFromTags

def authImplementationDisable: AuthImplementation = AuthImplementation.Disable
def authImplementationNative: AuthImplementation = AuthImplementation.Native
Expand Down
16 changes: 8 additions & 8 deletions modules/core/src/main/scala/Tasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.guardrail
package sbt

import _root_.sbt.{FeedbackProvidedException, WatchSource}
import cats.data.NonEmptyList
import cats.implicits._
import cats.~>
import dev.guardrail.{Args => ArgsImpl}
Expand All @@ -15,7 +14,7 @@ class CodegenFailedException extends FeedbackProvidedException

object Tasks {
def guardrailTask(
runner: Map[String,NonEmptyList[ArgsImpl]] => Target[List[Path]]
runner: (String, Array[ArgsImpl]) => Target[List[Path]]
)(tasks: List[Types.Args], sourceDir: File): Set[File] = {
// swagger-parser uses SPI to find extensions on the classpath (by default, only the OAPI2 -> OAPI3 converter)
// See https://github.com/swagger-api/swagger-parser#extensions
Expand All @@ -28,14 +27,15 @@ object Tasks {
Thread.currentThread().setContextClassLoader(classOf[SwaggerParserExtension].getClassLoader)

try {
val preppedTasks: Map[String, NonEmptyList[ArgsImpl]] = tasks.foldLeft(Map.empty[String, NonEmptyList[ArgsImpl]]) { case (acc, (language, args)) =>
val prepped = args.copy(outputPath=Some(sourceDir.getPath))
acc.updated(language, acc.get(language).fold(NonEmptyList.one(prepped))(_ :+ prepped))
val preppedTasks: List[(String, Array[ArgsImpl])] = {
tasks.foldLeft(Map.empty[String, List[ArgsImpl]])({ case (acc, (language, args)) =>
val prepped = args.withOutputPath(Some(sourceDir.getPath))
acc.updated(language, (acc.get(language).getOrElse(List.empty[ArgsImpl]) :+ prepped))
}).mapValues(_.toList.toArray).toList
}

val /*(logger,*/ paths/*)*/ =
runner
.apply(preppedTasks)
preppedTasks.toList.traverse(runner.tupled)
.fold[List[java.nio.file.Path]]({
case MissingArg(args, Error.ArgName(arg)) =>
println(s"${AnsiColor.RED}Missing argument:${AnsiColor.RESET} ${AnsiColor.BOLD}${arg}${AnsiColor.RESET} (In block ${args})")
Expand Down Expand Up @@ -83,7 +83,7 @@ object Tasks {
case UnusedModules(unused) =>
println(s"${AnsiColor.RED}Unused modules specified:${AnsiColor.RESET} ${unused.toList.mkString(", ")}")
throw new CodegenFailedException()
}, identity)
}, _.flatten.distinct)
//.runEmpty

paths.map(_.toFile).toSet
Expand Down

0 comments on commit 21bb434

Please sign in to comment.