Previously we set nullability information on symbols coming out of KotlinSymbolProvider based on the underlying type
and whether a default value was provided. This meant things like List, String, Enum, etc were always considered nullable. This was based on IDL v1 semantics w.r.t `Primitive*" shapes being the only shapes that were non-nullable (since they had an implicit default).
This PR removes all notion of how we considered nullability previously to instead rely entirely on the NullableIndex
as the source of truth. The new mental model is that converting any old shape (in particular explicit member.target)
is not going to give you nullability information. Only member shapes will. This is because nullability is local to how
a target shape is used in the context of some container (e.g. structure) shape.
For operation inputs customers will now see a runtime exception for any @required member without a @default set.
This shouldn't affect anyone with a working application assuming services actually validated these fields as required.
For operation outputs any missing field will be corrected using client error correction introduced in #958 such that all non-nullable members of the output struct end up with a value instead of throwing an exception.
feat! (BREAKING): Add plugin setting to control nullability check mode and change the default to be CLIENT_CAREFUL.
We now generate structures with non-null members anywhere NullableIndex indicates a members is non-nullable. Previously this would have been only Primitive* shapes. We also update when we respect @default trait and only set a default in the builder (on the symbol) if NullableIndex indicates that it's non-nullable T
feat: Add plugin setting to control when default values are serialized. Previously we only serialized numbers and booleans when they were set to something other than the default or marked @required. The default settings is the same but can be updated to "always" which would serialize defaults even if they aren't different.
I've added this as a setting because the current smithy spec recommends to always serialize defaults. I had implemented this change but it causes some issues with S3 not accepting default values. Smithy team maintains this may be fixed with model updates but who knows when they will come. Instead I've opted to keep the current default value serialization semantics but allowed for easy toggling back and forth.
refactor: Improve struct serialization codegen to better handle nullability and reduce the number of generated warnings.
Issue \
n/a
Description of changes
Previously we set nullability information on symbols coming out of
KotlinSymbolProvider
based on the underlying type and whether a default value was provided. This meant things likeList
,String
,Enum
, etc were always considered nullable. This was based on IDL v1 semantics w.r.t `Primitive*" shapes being the only shapes that were non-nullable (since they had an implicit default).This PR removes all notion of how we considered nullability previously to instead rely entirely on the
NullableIndex
as the source of truth. The new mental model is that converting any old shape (in particular explicitmember.target
) is not going to give you nullability information. Only member shapes will. This is because nullability is local to how a target shape is used in the context of some container (e.g. structure) shape.For operation inputs customers will now see a runtime exception for any
@required
member without a@default
set. This shouldn't affect anyone with a working application assuming services actually validated these fields as required. For operation outputs any missing field will be corrected using client error correction introduced in #958 such that all non-nullable members of the output struct end up with a value instead of throwing an exception.CLIENT_CAREFUL
. We now generate structures with non-null members anywhereNullableIndex
indicates a members is non-nullable. Previously this would have been onlyPrimitive*
shapes. We also update when we respect@default
trait and only set a default in the builder (on the symbol) ifNullableIndex
indicates that it's non-nullableT
@required
. The default settings is the same but can be updated to "always" which would serialize defaults even if they aren't different.httpLabel
required checks introduced in https://github.com/awslabs/smithy-kotlin/pull/697 to the operation serializer.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.