Skip to content

Commit c090d8b

Browse files
committed
fix: set context in schema codegen
1 parent f884df7 commit c090d8b

File tree

1 file changed

+21
-21
lines changed
  • smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/schema

1 file changed

+21
-21
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/schema/SchemaGenerator.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
public class SchemaGenerator implements Runnable {
5050
public static final String SCHEMAS_FOLDER = "schemas";
5151
private final SchemaReferenceIndex elision;
52-
private final ShapeGroupingIndex treeOrganizer;
52+
private final ShapeGroupingIndex groupingIndex;
5353
private final TypeScriptSettings settings;
5454
private final SymbolProvider symbolProvider;
5555
private final Model model;
@@ -90,7 +90,7 @@ public SchemaGenerator(Model model,
9090
elision = SchemaReferenceIndex.of(model);
9191
this.settings = settings;
9292
this.symbolProvider = symbolProvider;
93-
treeOrganizer = ShapeGroupingIndex.of(model);
93+
groupingIndex = ShapeGroupingIndex.of(model);
9494
}
9595

9696
/**
@@ -154,7 +154,7 @@ public void run() {
154154
* @return writer corresponding to the file that will hold the shape's schema.
155155
*/
156156
private TypeScriptWriter getWriter(ShapeId shape) {
157-
return writers.computeIfAbsent(treeOrganizer.getGroup(shape), k -> {
157+
return writers.computeIfAbsent(groupingIndex.getGroup(shape), k -> {
158158
TypeScriptWriter typeScriptWriter = new TypeScriptWriter("");
159159
typeScriptWriter.write("""
160160
/* eslint no-var: 0 */
@@ -277,7 +277,7 @@ private void writeSimpleSchema(Shape shape) {
277277
getShapeVariableName(shape),
278278
checkImportString(shape, shape.getId().getNamespace(), "n"),
279279
checkImportString(shape, shape.getId().getName()),
280-
resolveSimpleSchema(shape)
280+
resolveSimpleSchema(shape, shape)
281281
);
282282
writeTraits(shape);
283283
writer.write(");");
@@ -515,7 +515,7 @@ private void writeTraits(Shape shape) {
515515
*/
516516
private void writeTraitsInContext(Shape context, Shape shape) {
517517
TypeScriptWriter writer = getWriter(context.getId());
518-
boolean useImportedStrings = !treeOrganizer.isBaseGroup(context);
518+
boolean useImportedStrings = !groupingIndex.isBaseGroup(context);
519519

520520
writer.write(
521521
new SchemaTraitWriter(
@@ -567,7 +567,7 @@ private String resolveSchema(Shape context, Shape shape) {
567567

568568
if (!hasTraits) {
569569
try {
570-
return resolveSimpleSchema(memberShape != null ? memberShape : shape);
570+
return resolveSimpleSchema(context, memberShape != null ? memberShape : shape);
571571
} catch (IllegalArgumentException ignored) {
572572
//
573573
}
@@ -584,7 +584,7 @@ private String resolveSchema(Shape context, Shape shape) {
584584
* @return a sentinel value representing a preconfigured schema type.
585585
* @throws IllegalArgumentException when no sentinel value exists, e.g. a non-simple schema was passed in.
586586
*/
587-
private String resolveSimpleSchema(Shape shape) {
587+
private String resolveSimpleSchema(Shape context, Shape shape) {
588588
MemberShape memberShape = null;
589589
if (shape instanceof MemberShape ms) {
590590
memberShape = ms;
@@ -631,8 +631,8 @@ private String resolveSimpleSchema(Shape shape) {
631631
return "19";
632632
}
633633
case LIST, SET, MAP -> {
634-
TypeScriptWriter writer = getWriter(shape.getId());
635-
return resolveSimpleSchemaNestedContainer(shape, writer);
634+
TypeScriptWriter writer = getWriter(context.getId());
635+
return resolveSimpleSchemaNestedContainer(context, shape, writer);
636636
}
637637
default -> {
638638
//
@@ -649,7 +649,7 @@ private String resolveSimpleSchema(Shape shape) {
649649
*
650650
* @return the container bit modifier attached to the schema numeric value.
651651
*/
652-
private String resolveSimpleSchemaNestedContainer(Shape shape, TypeScriptWriter writer) {
652+
private String resolveSimpleSchemaNestedContainer(Shape context, Shape shape, TypeScriptWriter writer) {
653653
Shape contained;
654654
String factory;
655655
String sentinel;
@@ -664,7 +664,7 @@ private String resolveSimpleSchemaNestedContainer(Shape shape, TypeScriptWriter
664664
case MAP -> {
665665
contained = shape.asMapShape().get().getValue();
666666
factory = "map";
667-
keyMemberSchema = this.resolveSimpleSchema(shape.asMapShape().get().getKey()) + ", ";
667+
keyMemberSchema = this.resolveSimpleSchema(context, shape.asMapShape().get().getKey()) + ", ";
668668
sentinel = "128";
669669
}
670670
default -> {
@@ -679,29 +679,29 @@ private String resolveSimpleSchemaNestedContainer(Shape shape, TypeScriptWriter
679679

680680
if (contained.isListShape()) {
681681
writer.addImportSubmodule(factory, factory, TypeScriptDependency.SMITHY_CORE, "/schema");
682-
String schemaVarName = checkImportString(shape, shape.getId().getName());
682+
String schemaVarName = checkImportString(context, shape.getId().getName());
683683
return factory + "("
684-
+ checkImportString(shape, shape.getId().getNamespace(), "n") + ", " + schemaVarName + ", 0, "
684+
+ checkImportString(context, shape.getId().getNamespace(), "n") + ", " + schemaVarName + ", 0, "
685685
+ keyMemberSchema
686-
+ this.resolveSimpleSchema(contained) + ")";
686+
+ this.resolveSimpleSchema(context, contained) + ")";
687687
} else if (contained.isMapShape()) {
688688
writer.addImportSubmodule(factory, factory, TypeScriptDependency.SMITHY_CORE, "/schema");
689-
String schemaVarName = checkImportString(shape, shape.getId().getName());
689+
String schemaVarName = checkImportString(context, shape.getId().getName());
690690
return factory + "("
691-
+ checkImportString(shape, shape.getId().getNamespace(), "n") + ", " + schemaVarName + ", 0, "
691+
+ checkImportString(context, shape.getId().getNamespace(), "n") + ", " + schemaVarName + ", 0, "
692692
+ keyMemberSchema
693-
+ this.resolveSimpleSchema(contained) + ")";
693+
+ this.resolveSimpleSchema(context, contained) + ")";
694694
} else {
695-
return sentinel + "|" + this.resolveSimpleSchema(contained);
695+
return sentinel + "|" + this.resolveSimpleSchema(context, contained);
696696
}
697697
}
698698

699699
/**
700700
* Imports the shape's schema from another file if the context group differs from the shape group.
701701
*/
702702
private void checkImportSchema(Shape context, Shape shape) {
703-
String shapeGroup = treeOrganizer.getGroup(shape.getId());
704-
if (treeOrganizer.different(context, shape)) {
703+
String shapeGroup = groupingIndex.getGroup(shape.getId());
704+
if (groupingIndex.different(context, shape)) {
705705
getWriter(context.getId()).addRelativeImport(
706706
getShapeVariableName(shape), null, Path.of("./", shapeGroup)
707707
);
@@ -717,7 +717,7 @@ private String checkImportString(Shape context, String fullString) {
717717
*/
718718
private String checkImportString(Shape context, String fullString, String prefix) {
719719
String var = prefix != null ? store.var(fullString, prefix) : store.var(fullString);
720-
if (!treeOrganizer.isBaseGroup(context)) {
720+
if (!groupingIndex.isBaseGroup(context)) {
721721
getWriter(context.getId()).addRelativeImport(
722722
var,
723723
null,

0 commit comments

Comments
 (0)