Skip to content

Commit

Permalink
Reproduce #1592
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Sep 26, 2024
1 parent b828a13 commit 7ad944d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package smithy4s.example

import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.struct

final case class DefaultNotCapitalized(name: Username = smithy4s.example.username("hello"))

object DefaultNotCapitalized extends ShapeTag.Companion[DefaultNotCapitalized] {
val id: ShapeId = ShapeId("smithy4s.example", "DefaultNotCapitalized")

val hints: Hints = Hints.empty

// constructor using the original order from the spec
private def make(name: Username): DefaultNotCapitalized = DefaultNotCapitalized(name)

implicit val schema: Schema[DefaultNotCapitalized] = struct(
Username.schema.required[DefaultNotCapitalized]("name", _.name).addHints(smithy.api.Default(smithy4s.Document.fromString("hello"))),
)(make).withId(id).addHints(hints)
}
15 changes: 15 additions & 0 deletions modules/bootstrapped/src/generated/smithy4s/example/Username.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package smithy4s.example

import smithy4s.Hints
import smithy4s.Newtype
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.schema.Schema.bijection
import smithy4s.schema.Schema.string

object Username extends Newtype[String] {
val id: ShapeId = ShapeId("smithy4s.example", "username")
val hints: Hints = Hints.empty
val underlyingSchema: Schema[String] = string.withId(id).addHints(hints)
implicit val schema: Schema[Username] = bijection(underlyingSchema, asBijection)
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ package object example {
type UVIndex = smithy4s.example.UVIndex.Type
type UnicodeRegexString = smithy4s.example.UnicodeRegexString.Type
type UnwrappedFancyList = smithy4s.example.UnwrappedFancyList.Type
type Username = smithy4s.example.Username.Type
type ValidatedString = smithy4s.example.ValidatedString.Type

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private[codegen] object ModelLoader {
val modelsInJars = deps.flatMap { file =>
Using.resource(
// Note: On JDK13+, the second parameter is redundant.
FileSystems.newFileSystem(file.toPath(), null)
FileSystems.newFileSystem(file.toPath(), null: ClassLoader)
) { jarFS =>
val p = jarFS.getPath("META-INF", "smithy", "manifest")

Expand Down
7 changes: 7 additions & 0 deletions sampleSpecs/defaults.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,10 @@ structure DefaultVariants {
}

structure DefaultInMixinUsageTest with [DefaultInMixinTest] {}

structure DefaultNotCapitalized {
@required
name: username = "hello"
}

string username

0 comments on commit 7ad944d

Please sign in to comment.