Skip to content

Commit

Permalink
Fix codegen cli compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
msosnicki committed Feb 11, 2025
1 parent 12c9507 commit 93bc0bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ import smithy4s.codegen.CodegenArgs
import smithy4s.codegen.FileType

import Options._
import smithy4s.codegen.NamespacePattern
import com.monovore.decline.Argument

object CodegenCommand {

private implicit val namespacePatternArg: Argument[NamespacePattern] =
Argument.readString.map(NamespacePattern.fromString)

val outputOpt =
Opts
.option[os.Path](
Expand Down Expand Up @@ -75,18 +80,18 @@ object CodegenCommand {
)
.orFalse

val allowedNSOpt: Opts[Option[Set[String]]] =
val allowedNSOpt: Opts[Option[Set[NamespacePattern]]] =
Opts
.option[List[String]](
.option[List[NamespacePattern]](
"allowed-ns",
"Comma-delimited list of namespaces that should not be processed. If unset, all namespaces are processed (except stdlib ones)"
)
.map(_.toSet)
.orNone

val excludedNSOpt: Opts[Option[Set[String]]] =
val excludedNSOpt: Opts[Option[Set[NamespacePattern]]] =
Opts
.option[List[String]](
.option[List[NamespacePattern]](
"excluded-ns",
"Comma-delimited list of namespaces that should not be processed. If unset, all namespaces are processed (except stdlib ones)"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import smithy4s.codegen.FileType
import weaver._

import Defaults.defaultDependencies
import smithy4s.codegen.NamespacePattern

object CommandParsingSpec extends FunSuite {

Expand Down Expand Up @@ -89,7 +90,7 @@ object CommandParsingSpec extends FunSuite {
resourceOutput = os.pwd / "target" / "openapi",
skip = Set(FileType.Openapi, FileType.Scala),
discoverModels = false,
allowedNS = Some(Set("name1", "name2")),
allowedNS = Some(Set("name1", "name2").map(NamespacePattern.fromString)),
excludedNS = None,
repositories = List("repo1", "repo2"),
dependencies = defaultDependencies ++ List("dep1", "dep2"),
Expand Down
2 changes: 1 addition & 1 deletion modules/codegen/src/smithy4s/codegen/CodegenArgs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object FileType {
val values = List(Scala, Openapi, Resource)
}

final class NamespacePattern(pattern: String) {
final case class NamespacePattern private (pattern: String) {
import NamespacePattern._
private val regexPattern =
new Regex(
Expand Down
13 changes: 6 additions & 7 deletions modules/codegen/src/smithy4s/codegen/internals/CodegenImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,19 @@ private[codegen] object CodegenImpl { self =>
.map(_.config)
.getOrElse(new OpenApiConfig())

val allNamespaces =
model.getShapeIds().asScala.map(_.getNamespace()).toSet
val isAllowed: String => Boolean = str =>
args.allowedNS.map(_.exists(_.matches(str))).getOrElse(true)
val notExcluded: String => Boolean = str =>
!args.excludedNS.getOrElse(Set.empty).exists(_.matches(str))
val openApiNamespaces = model
.getShapeIds()
.asScala
.map(_.getNamespace())
.toSet
.filter(namespace => isAllowed(namespace) && notExcluded(namespace))
val openApiNamespaces = allNamespaces.filter(namespace =>
isAllowed(namespace) && notExcluded(namespace)
)
alloy.openapi
.convertWithConfig(
model,
Some(openApiNamespaces),
Some(openApiNamespaces).filter(_ != allNamespaces),
openApiConfig,
classloader
)
Expand Down

0 comments on commit 93bc0bd

Please sign in to comment.