34
34
import software .amazon .smithy .model .shapes .SimpleShape ;
35
35
import software .amazon .smithy .model .shapes .StringShape ;
36
36
import software .amazon .smithy .model .shapes .StructureShape ;
37
+ import software .amazon .smithy .model .traits .EnumDefinition ;
37
38
import software .amazon .smithy .model .traits .EnumTrait ;
39
+ import software .amazon .smithy .model .traits .EnumValueTrait ;
38
40
import software .amazon .smithy .model .traits .ErrorTrait ;
39
41
import software .amazon .smithy .model .traits .IdempotencyTokenTrait ;
42
+ import software .amazon .smithy .model .traits .InternalTrait ;
40
43
import software .amazon .smithy .model .traits .LengthTrait ;
41
44
import software .amazon .smithy .model .traits .MediaTypeTrait ;
42
45
import software .amazon .smithy .model .traits .PatternTrait ;
@@ -503,6 +506,22 @@ private void writeShapeValidator(TypeScriptWriter writer,
503
506
});
504
507
}
505
508
509
+ if (shape .isEnumShape ()) {
510
+ writer .addImport ("EnumValidator" , "__EnumValidator" , "@aws-smithy/server-common" );
511
+ Collection <MemberShape > enumValues = shape .asEnumShape ().get ().getAllMembers ().values ();
512
+ writer .openBlock ("new __EnumValidator([" , "])," , () -> {
513
+ for (MemberShape member : enumValues ) {
514
+ writer .write ("$S," , member .expectTrait (EnumValueTrait .class ).expectStringValue ());
515
+ }
516
+ writer .write ("], [" );
517
+ for (MemberShape member : shape .asEnumShape ().get ().getAllMembers ().values ()) {
518
+ if (!member .hasTrait ((InternalTrait .class )) && !member .hasTag ("internal" )) {
519
+ writer .write ("$S," , member .expectTrait (EnumValueTrait .class ).expectStringValue ());
520
+ }
521
+ }
522
+ });
523
+ }
524
+
506
525
for (Trait t : constraints ) {
507
526
writeSingleConstraintValidator (writer , t );
508
527
}
@@ -517,12 +536,18 @@ private void writeSingleConstraintValidator(TypeScriptWriter writer, Trait trait
517
536
if (trait instanceof RequiredTrait ) {
518
537
writer .addImport ("RequiredValidator" , "__RequiredValidator" , "@aws-smithy/server-common" );
519
538
writer .write ("new __RequiredValidator()," );
520
- } else if (trait instanceof EnumTrait ) {
539
+ } else if (trait instanceof EnumTrait && ! trait . isSynthetic () ) {
521
540
writer .addImport ("EnumValidator" , "__EnumValidator" , "@aws-smithy/server-common" );
522
541
writer .openBlock ("new __EnumValidator([" , "])," , () -> {
523
542
for (String e : ((EnumTrait ) trait ).getEnumDefinitionValues ()) {
524
543
writer .write ("$S," , e );
525
544
}
545
+ writer .write ("], [" );
546
+ for (EnumDefinition enumDefinition : ((EnumTrait ) trait ).getValues ()) {
547
+ if (!enumDefinition .hasTag ("internal" )) {
548
+ writer .write ("$S, " , enumDefinition .getValue ());
549
+ }
550
+ }
526
551
});
527
552
} else if (trait instanceof LengthTrait ) {
528
553
LengthTrait lengthTrait = (LengthTrait ) trait ;
0 commit comments