smithy-lang / smithy-kotlin

Smithy code generator for Kotlin (in development)
Apache License 2.0
76 stars 26 forks source link

feat(codegen): improve nullability of generated types #968

Closed aajtodd closed 9 months ago

aajtodd commented 9 months ago

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 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.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

sonarcloud[bot] commented 9 months ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 23 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication