Skip to content

Commit 58cf08a

Browse files
kubukozBaccata
authored andcommitted
Memoize default values in Schema, not Field
1 parent d9d20f7 commit 58cf08a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

modules/core/src/smithy4s/schema/Field.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final case class Field[S, A](
4141
@deprecated("use .schema instead", since = "0.18.0")
4242
final def instance: Schema[A] = schema
4343

44-
lazy val getDefaultValue: Option[A] =
44+
def getDefaultValue: Option[A] =
4545
schema.getDefaultValue
4646

4747
def isDefaultValue(a: A): Boolean = getDefaultValue.contains(a)

modules/core/src/smithy4s/schema/Schema.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,15 @@ sealed trait Schema[A]{
104104
final def getDefault: Option[Document] =
105105
this.hints.get(smithy.api.Default).map(_.value)
106106

107-
final def getDefaultValue: Option[A] = {
107+
private final lazy val defaultValue: Option[A] = {
108108
val maybeDefault = getDefault.flatMap[A] {
109109
case Document.DNull => this.compile(DefaultValueSchemaVisitor)
110110
case document => Document.Decoder.fromSchema(this).decode(document).toOption
111111
}
112112
maybeDefault.orElse(this.compile(OptionDefaultVisitor))
113113
}
114114

115+
final def getDefaultValue: Option[A] = defaultValue
115116

116117
/**
117118
* When applied on a structure schema, creates a schema that, when compiled into

0 commit comments

Comments
 (0)