-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for @nullable trait in order to support MergePatch usecases #1408
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
65e5ed1
Add nullable support to JSON parsing
astridej 87ca4c9
Adjust codegen code to handle Nullable
astridej 8a64977
Add nullable sample spec and smoke tests
astridej 8edf430
Inexplicable hint reorderings that happened on compilation
astridej 62e4ca8
Minor refactor
astridej 2e177fe
Scalafmt
astridej 388b45e
Rework get message to be safer until I can test it
astridej 67c06bc
Remove commented out code + cleanup
astridej 41fb310
Update modules/core/src/smithy4s/Nullable.scala
astridej 5062108
Add refinement schema to expanded .isOption logic
astridej 8b42288
Add tests for error messages
astridej e4b86e9
Revert "Inexplicable hint reorderings that happened on compilation"
astridej 119aabf
Use Option ordering for Nullable fold
astridej 092eab6
Remove unneeded TODO comment
astridej e387b94
Add cats instances for Nullable
astridej ef98fc2
Add test and refactor for getUnlessDefault
astridej 388c1fc
Scalafmt
astridej eacf966
Revert refactor of getUnlessDefault
astridej 95abbc4
Additional tests for getUnlessDefault
astridej ee44174
Remove comment because it's probably misleading
astridej c6be356
Add support for Nullable in dynamic module
astridej 2dbb0bb
Scalafmt
astridej d0926e8
Fix trait reference in dynamic module
astridej 8344e40
Revert extra handling of default in dynamic module
astridej b2ae9d7
Add docs for @nullable
astridej 67ae7ba
Scalafmt, redux
astridej b3f7996
Fix wrong copyright on new header
astridej 85da837
Update changelog to include nullable
astridej c268f7c
Correction to the documented code
astridej 7c44617
Update modules/docs/markdown/04-codegen/01-customisation/13-nullable-…
astridej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
modules/bootstrapped/src/generated/smithy4s/example/CustomErrorMessageType.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 CustomErrorMessageType extends Newtype[String] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "CustomErrorMessageType") | ||
val hints: Hints = Hints.empty | ||
val underlyingSchema: Schema[String] = string.withId(id).addHints(hints) | ||
implicit val schema: Schema[CustomErrorMessageType] = bijection(underlyingSchema, asBijection) | ||
} |
26 changes: 26 additions & 0 deletions
26
modules/bootstrapped/src/generated/smithy4s/example/ErrorCustomTypeMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.Smithy4sThrowable | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class ErrorCustomTypeMessage(message: Option[CustomErrorMessageType] = None) extends Smithy4sThrowable { | ||
override def getMessage(): String = message.map(_.value).orNull | ||
} | ||
|
||
object ErrorCustomTypeMessage extends ShapeTag.Companion[ErrorCustomTypeMessage] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "ErrorCustomTypeMessage") | ||
|
||
val hints: Hints = Hints( | ||
smithy.api.Error.SERVER.widen, | ||
).lazily | ||
|
||
implicit val schema: Schema[ErrorCustomTypeMessage] = struct( | ||
CustomErrorMessageType.schema.optional[ErrorCustomTypeMessage]("message", _.message), | ||
){ | ||
ErrorCustomTypeMessage.apply | ||
}.withId(id).addHints(hints) | ||
} |
26 changes: 26 additions & 0 deletions
26
modules/bootstrapped/src/generated/smithy4s/example/ErrorCustomTypeRequiredMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.Smithy4sThrowable | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class ErrorCustomTypeRequiredMessage(message: CustomErrorMessageType) extends Smithy4sThrowable { | ||
override def getMessage(): String = message.value | ||
} | ||
|
||
object ErrorCustomTypeRequiredMessage extends ShapeTag.Companion[ErrorCustomTypeRequiredMessage] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "ErrorCustomTypeRequiredMessage") | ||
|
||
val hints: Hints = Hints( | ||
smithy.api.Error.SERVER.widen, | ||
).lazily | ||
|
||
implicit val schema: Schema[ErrorCustomTypeRequiredMessage] = struct( | ||
CustomErrorMessageType.schema.required[ErrorCustomTypeRequiredMessage]("message", _.message), | ||
){ | ||
ErrorCustomTypeRequiredMessage.apply | ||
}.withId(id).addHints(hints) | ||
} |
27 changes: 27 additions & 0 deletions
27
modules/bootstrapped/src/generated/smithy4s/example/ErrorNullableCustomTypeMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Nullable | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.Smithy4sThrowable | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class ErrorNullableCustomTypeMessage(message: Option[Nullable[CustomErrorMessageType]] = None) extends Smithy4sThrowable { | ||
override def getMessage(): String = message.flatMap(_.toOption).map(_.value).orNull | ||
} | ||
|
||
object ErrorNullableCustomTypeMessage extends ShapeTag.Companion[ErrorNullableCustomTypeMessage] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "ErrorNullableCustomTypeMessage") | ||
|
||
val hints: Hints = Hints( | ||
smithy.api.Error.SERVER.widen, | ||
).lazily | ||
|
||
implicit val schema: Schema[ErrorNullableCustomTypeMessage] = struct( | ||
CustomErrorMessageType.schema.nullable.optional[ErrorNullableCustomTypeMessage]("message", _.message), | ||
){ | ||
ErrorNullableCustomTypeMessage.apply | ||
}.withId(id).addHints(hints) | ||
} |
27 changes: 27 additions & 0 deletions
27
.../bootstrapped/src/generated/smithy4s/example/ErrorNullableCustomTypeRequiredMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Nullable | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.Smithy4sThrowable | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class ErrorNullableCustomTypeRequiredMessage(message: Nullable[CustomErrorMessageType]) extends Smithy4sThrowable { | ||
override def getMessage(): String = message.toOption.map(_.value).orNull | ||
} | ||
|
||
object ErrorNullableCustomTypeRequiredMessage extends ShapeTag.Companion[ErrorNullableCustomTypeRequiredMessage] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "ErrorNullableCustomTypeRequiredMessage") | ||
|
||
val hints: Hints = Hints( | ||
smithy.api.Error.SERVER.widen, | ||
).lazily | ||
|
||
implicit val schema: Schema[ErrorNullableCustomTypeRequiredMessage] = struct( | ||
CustomErrorMessageType.schema.nullable.required[ErrorNullableCustomTypeRequiredMessage]("message", _.message), | ||
){ | ||
ErrorNullableCustomTypeRequiredMessage.apply | ||
}.withId(id).addHints(hints) | ||
} |
28 changes: 28 additions & 0 deletions
28
modules/bootstrapped/src/generated/smithy4s/example/ErrorNullableMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Nullable | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.Smithy4sThrowable | ||
import smithy4s.schema.Schema.string | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class ErrorNullableMessage(message: Option[Nullable[String]] = None) extends Smithy4sThrowable { | ||
override def getMessage(): String = message.flatMap(_.toOption).orNull | ||
} | ||
|
||
object ErrorNullableMessage extends ShapeTag.Companion[ErrorNullableMessage] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "ErrorNullableMessage") | ||
|
||
val hints: Hints = Hints( | ||
smithy.api.Error.CLIENT.widen, | ||
).lazily | ||
|
||
implicit val schema: Schema[ErrorNullableMessage] = struct( | ||
string.nullable.optional[ErrorNullableMessage]("message", _.message), | ||
){ | ||
ErrorNullableMessage.apply | ||
}.withId(id).addHints(hints) | ||
} |
28 changes: 28 additions & 0 deletions
28
modules/bootstrapped/src/generated/smithy4s/example/ErrorNullableRequiredMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Nullable | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.Smithy4sThrowable | ||
import smithy4s.schema.Schema.string | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class ErrorNullableRequiredMessage(message: Nullable[String]) extends Smithy4sThrowable { | ||
override def getMessage(): String = message.toOption.orNull | ||
} | ||
|
||
object ErrorNullableRequiredMessage extends ShapeTag.Companion[ErrorNullableRequiredMessage] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "ErrorNullableRequiredMessage") | ||
|
||
val hints: Hints = Hints( | ||
smithy.api.Error.SERVER.widen, | ||
).lazily | ||
|
||
implicit val schema: Schema[ErrorNullableRequiredMessage] = struct( | ||
string.nullable.required[ErrorNullableRequiredMessage]("message", _.message), | ||
){ | ||
ErrorNullableRequiredMessage.apply | ||
}.withId(id).addHints(hints) | ||
} |
27 changes: 27 additions & 0 deletions
27
modules/bootstrapped/src/generated/smithy4s/example/ErrorRequiredMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.Smithy4sThrowable | ||
import smithy4s.schema.Schema.string | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class ErrorRequiredMessage(message: String) extends Smithy4sThrowable { | ||
override def getMessage(): String = message | ||
} | ||
|
||
object ErrorRequiredMessage extends ShapeTag.Companion[ErrorRequiredMessage] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "ErrorRequiredMessage") | ||
|
||
val hints: Hints = Hints( | ||
smithy.api.Error.CLIENT.widen, | ||
).lazily | ||
|
||
implicit val schema: Schema[ErrorRequiredMessage] = struct( | ||
string.required[ErrorRequiredMessage]("message", _.message), | ||
){ | ||
ErrorRequiredMessage.apply | ||
}.withId(id).addHints(hints) | ||
} |
23 changes: 23 additions & 0 deletions
23
modules/bootstrapped/src/generated/smithy4s/example/Patchable.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Nullable | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.int | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class Patchable(allowExplicitNull: Option[Nullable[Int]] = None) | ||
|
||
object Patchable extends ShapeTag.Companion[Patchable] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "Patchable") | ||
|
||
val hints: Hints = Hints.empty | ||
|
||
implicit val schema: Schema[Patchable] = struct( | ||
int.nullable.optional[Patchable]("allowExplicitNull", _.allowExplicitNull), | ||
){ | ||
Patchable.apply | ||
}.withId(id).addHints(hints) | ||
} |
28 changes: 28 additions & 0 deletions
28
modules/bootstrapped/src/generated/smithy4s/example/PatchableEdgeCases.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Nullable | ||
import smithy4s.Nullable.Null | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.int | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class PatchableEdgeCases(required: Nullable[Int], requiredDefaultValue: Nullable[Int] = smithy4s.Nullable.Value(3), requiredDefaultNull: Nullable[Int] = Null, defaultValue: Nullable[Int] = smithy4s.Nullable.Value(5), defaultNull: Nullable[Int] = Null) | ||
|
||
object PatchableEdgeCases extends ShapeTag.Companion[PatchableEdgeCases] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "PatchableEdgeCases") | ||
|
||
val hints: Hints = Hints.empty | ||
|
||
implicit val schema: Schema[PatchableEdgeCases] = struct( | ||
int.nullable.required[PatchableEdgeCases]("required", _.required), | ||
int.nullable.required[PatchableEdgeCases]("requiredDefaultValue", _.requiredDefaultValue).addHints(smithy.api.Default(smithy4s.Document.fromDouble(3.0d))), | ||
int.nullable.required[PatchableEdgeCases]("requiredDefaultNull", _.requiredDefaultNull).addHints(smithy.api.Box(), smithy.api.Default(smithy4s.Document.nullDoc)), | ||
int.nullable.field[PatchableEdgeCases]("defaultValue", _.defaultValue).addHints(smithy.api.Default(smithy4s.Document.fromDouble(5.0d))), | ||
int.nullable.field[PatchableEdgeCases]("defaultNull", _.defaultNull).addHints(smithy.api.Box(), smithy.api.Default(smithy4s.Document.nullDoc)), | ||
){ | ||
PatchableEdgeCases.apply | ||
}.withId(id).addHints(hints) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great, thank you !