Skip to content

Commit f1932e3

Browse files
move validator construction into validator function
1 parent bf21d5e commit f1932e3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructureGenerator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,15 @@ private void renderStructureNamespace(StructuredMemberWriter structuredMemberWri
211211
return;
212212
}
213213

214-
structuredMemberWriter.writeMemberValidators(writer);
215-
216214
writer.addImport("ValidationFailure", "__ValidationFailure", "@aws-smithy/server-common");
217215
writer.openBlock("export const validate = ($L: $L): __ValidationFailure[] => {", "}",
218216
objectParam, symbol.getName(),
219217
() -> {
218+
// TODO: move this somewhere so it only gets run once.
219+
// Putting it at the top of the namespace can result in runtime errors when
220+
// you have mutually recursive structures because the validator of one will
221+
// be defined before the validator of the other exists at all.
222+
structuredMemberWriter.writeMemberValidators(writer);
220223
structuredMemberWriter.writeValidate(writer, objectParam);
221224
}
222225
);

0 commit comments

Comments
 (0)