|
29 | 29 | import software.amazon.smithy.model.shapes.Shape;
|
30 | 30 | import software.amazon.smithy.model.shapes.StructureShape;
|
31 | 31 | import software.amazon.smithy.model.shapes.UnionShape;
|
| 32 | +import software.amazon.smithy.model.traits.MediaTypeTrait; |
32 | 33 | import software.amazon.smithy.model.traits.SparseTrait;
|
33 | 34 | import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
|
34 | 35 | import software.amazon.smithy.model.traits.XmlFlattenedTrait;
|
35 | 36 | import software.amazon.smithy.model.traits.XmlNameTrait;
|
| 37 | +import software.amazon.smithy.typescript.codegen.CodegenUtils; |
36 | 38 | import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
|
37 | 39 | import software.amazon.smithy.typescript.codegen.integration.DocumentMemberDeserVisitor;
|
38 | 40 | import software.amazon.smithy.typescript.codegen.integration.DocumentShapeDeserVisitor;
|
@@ -78,7 +80,8 @@ protected void deserializeCollection(GenerationContext context, CollectionShape
|
78 | 80 | writer.write("if (entry === null) { return null as any; }");
|
79 | 81 |
|
80 | 82 | String dataSource = getUnnamedTargetWrapper(context, target, "entry");
|
81 |
| - writer.write("return $L;", target.accept(getMemberVisitor(dataSource))); |
| 83 | + writer.write("return $L$L;", target.accept(getMemberVisitor(dataSource)), |
| 84 | + usesExpect(target) ? " as any" : ""); |
82 | 85 | });
|
83 | 86 | }
|
84 | 87 |
|
@@ -133,7 +136,8 @@ protected void deserializeMap(GenerationContext context, MapShape shape) {
|
133 | 136 | writer.openBlock("return {", "};", () -> {
|
134 | 137 | writer.write("...acc,");
|
135 | 138 | // Dispatch to the output value provider for any additional handling.
|
136 |
| - writer.write("[pair[$S]]: $L", keyLocation, target.accept(getMemberVisitor(dataSource))); |
| 139 | + writer.write("[pair[$S]]: $L$L", keyLocation, target.accept(getMemberVisitor(dataSource)), |
| 140 | + usesExpect(target) ? " as any" : ""); |
137 | 141 | });
|
138 | 142 | });
|
139 | 143 | }
|
@@ -269,12 +273,22 @@ protected void deserializeUnion(GenerationContext context, UnionShape shape) {
|
269 | 273 | deserializeNamedMember(context, memberName, memberShape, "output", (dataSource, visitor) -> {
|
270 | 274 | writer.openBlock("return {", "};", () -> {
|
271 | 275 | // Dispatch to the output value provider for any additional handling.
|
272 |
| - writer.write("$L: $L", memberName, target.accept(visitor)); |
| 276 | + writer.write("$L: $L$L", memberName, target.accept(visitor), usesExpect(target) ? " as any" : ""); |
273 | 277 | });
|
274 | 278 | });
|
275 | 279 | });
|
276 | 280 |
|
277 | 281 | // Or write output element to the unknown member.
|
278 | 282 | writer.write("return { $$unknown: Object.entries(output)[0] };");
|
279 | 283 | }
|
| 284 | + |
| 285 | + private boolean usesExpect(Shape shape) { |
| 286 | + if (shape.isStringShape()) { |
| 287 | + if (shape.hasTrait(MediaTypeTrait.class)) { |
| 288 | + return !CodegenUtils.isJsonMediaType(shape.expectTrait(MediaTypeTrait.class).getValue()); |
| 289 | + } |
| 290 | + return true; |
| 291 | + } |
| 292 | + return false; |
| 293 | + } |
280 | 294 | }
|
0 commit comments