|
32 | 32 | import software.amazon.smithy.model.traits.SparseTrait;
|
33 | 33 | import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
|
34 | 34 | import software.amazon.smithy.typescript.codegen.CodegenUtils;
|
| 35 | +import software.amazon.smithy.typescript.codegen.TypeScriptSettings.ArtifactType; |
35 | 36 | import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
|
36 | 37 | import software.amazon.smithy.typescript.codegen.integration.DocumentMemberDeserVisitor;
|
37 | 38 | import software.amazon.smithy.typescript.codegen.integration.DocumentShapeDeserVisitor;
|
@@ -62,16 +63,25 @@ private DocumentMemberDeserVisitor getMemberVisitor(MemberShape memberShape, Str
|
62 | 63 | protected void deserializeCollection(GenerationContext context, CollectionShape shape) {
|
63 | 64 | TypeScriptWriter writer = context.getWriter();
|
64 | 65 | Shape target = context.getModel().expectShape(shape.getMember().getTarget());
|
| 66 | + ArtifactType artifactType = context.getSettings().getArtifactType(); |
65 | 67 |
|
66 | 68 | // Filter out null entries if we don't have the sparse trait.
|
67 | 69 | String potentialFilter = "";
|
68 |
| - if (!shape.hasTrait(SparseTrait.ID)) { |
| 70 | + if (!shape.hasTrait(SparseTrait.ID) && !artifactType.equals(ArtifactType.SSDK)) { |
69 | 71 | potentialFilter = ".filter((e: any) => e != null)";
|
70 | 72 | }
|
71 | 73 |
|
72 | 74 | writer.openBlock("return (output || [])$L.map((entry: any) => {", "});", potentialFilter, () -> {
|
73 | 75 | // Short circuit null values from serialization.
|
74 |
| - writer.write("if (entry === null) { return null as any; }"); |
| 76 | + writer.openBlock("if (entry === null) {", "}", () -> { |
| 77 | + // In the SSDK we want to be very strict about not accepting nulls in non-sparse lists. |
| 78 | + if (!shape.hasTrait(SparseTrait.ID) && artifactType.equals(ArtifactType.SSDK)) { |
| 79 | + writer.write("throw new TypeError('All elements of the non-sparse list $S must be non-null.');", |
| 80 | + shape.getId()); |
| 81 | + } else { |
| 82 | + writer.write("return null as any;"); |
| 83 | + } |
| 84 | + }); |
75 | 85 |
|
76 | 86 | // Dispatch to the output value provider for any additional handling.
|
77 | 87 | writer.write("return $L$L;",
|
|
0 commit comments