Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
rishav-karanjit committed Nov 4, 2024
1 parent eb1534c commit 830563c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ public void renderStructure(Runnable runnable, boolean isInputStructure) {
.expectShape(refShape.getReferentId())
.hasTrait(ServiceTrait.class)
) {
writer.addImport(SmithyNameResolver.getGoModuleNameForSdkNamespace(
refShape.getReferentId().getNamespace()
));
writer.addImport(
SmithyNameResolver.getGoModuleNameForSdkNamespace(
refShape.getReferentId().getNamespace()
)
);
}
}
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ public Symbol mapShape(MapShape shape) {
private Symbol.Builder symbolBuilderFor(Shape shape, String typeName) {
final String namespace;
if (shape.hasTrait(ServiceTrait.class)) {
namespace = SmithyNameResolver.smithyTypesNamespaceAws(shape.expectTrait(ServiceTrait.class), false);
namespace =
SmithyNameResolver.smithyTypesNamespaceAws(
shape.expectTrait(ServiceTrait.class),
false
);
} else {
namespace = SmithyNameResolver.smithyTypesNamespace(shape);
}
Expand Down Expand Up @@ -582,13 +586,12 @@ public Symbol structureShape(StructureShape shape) {
);
var isResource = !shape.expectTrait(ReferenceTrait.class).isService();
if (isResource || referredShape.hasTrait(ServiceTrait.class)) {
final var typeName = referredShape.hasTrait(ServiceTrait.class) ? getDefaultShapeName(referredShape) : "I".concat(getDefaultShapeName(referredShape)) ;
final var typeName = referredShape.hasTrait(ServiceTrait.class)
? getDefaultShapeName(referredShape)
: "I".concat(getDefaultShapeName(referredShape));
builder.putProperty(
"Referred",
symbolBuilderFor(
referredShape,
typeName
)
symbolBuilderFor(referredShape, typeName)
.putProperty(SymbolUtils.POINTABLE, false)
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,17 +1035,21 @@ private void handleDepErrorSerializer(
.expectTrait(ServiceTrait.class)
.getSdkId()
.concat("Error");
sdkOpaqueErrHandler.append("""
if (err.(*smithy.OperationError).Service() == "%s") {
%s := %s.Error_ToDafny(err)
return %s.Create_%s_(%s)
}
""".formatted(depShape
.expectTrait(ServiceTrait.class)
.getSdkId(), sdkDepErrorVar,
SmithyNameResolver.shapeNamespace(depShape),DafnyNameResolver.getDafnyErrorCompanion(serviceShape),
DafnyNameResolver.dafnyNamespace(depShape),
sdkDepErrorVar));
sdkOpaqueErrHandler.append(
"""
if (err.(*smithy.OperationError).Service() == "%s") {
%s := %s.Error_ToDafny(err)
return %s.Create_%s_(%s)
}
""".formatted(
depShape.expectTrait(ServiceTrait.class).getSdkId(),
sdkDepErrorVar,
SmithyNameResolver.shapeNamespace(depShape),
DafnyNameResolver.getDafnyErrorCompanion(serviceShape),
DafnyNameResolver.dafnyNamespace(depShape),
sdkDepErrorVar
)
);
sdkErrHandler.append(
"""
%s := %s.Error_ToDafny(err)
Expand Down Expand Up @@ -1076,7 +1080,8 @@ private void handleDepErrorSerializer(
}
}
if (sdkDepFound) {
final var createOpaqueError = """
final var createOpaqueError =
"""
return %s.Companion_Error_.Create_Opaque_(err, dafny.SeqOfChars([]dafny.Char(err.Error())...))
""".formatted(DafnyNameResolver.dafnyTypesNamespace(serviceShape));
sdkErrHandler.append(createOpaqueError);
Expand Down Expand Up @@ -1469,7 +1474,9 @@ private void generateDeserializerFunctions(
if (resourceOrService.isServiceShape()) {
if (resourceOrService.hasTrait(ServiceTrait.class)) {
outputType =
SmithyNameResolver.getAwsServiceClient(resourceOrService.expectTrait(ServiceTrait.class));
SmithyNameResolver.getAwsServiceClient(
resourceOrService.expectTrait(ServiceTrait.class)
);
} else {
final var namespace = SmithyNameResolver
.shapeNamespace(resourceOrService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,17 @@ protected String referenceStructureShape(final StructureShape shape) {
DafnyNameResolver.dafnyTypesNamespace(serviceShape)
);
return """
shim, ok := %1$s.(*%2$swrapped.Shim)
if !ok {
panic("Not able to convert client to native")
}
return *shim.Client
""".formatted(dataSource, DafnyNameResolver.dafnyNamespace(
shim, ok := %1$s.(*%2$swrapped.Shim)
if !ok {
panic("Not able to convert client to native")
}
return *shim.Client
""".formatted(
dataSource,
DafnyNameResolver.dafnyNamespace(
resourceOrService.expectTrait(ServiceTrait.class)
));
)
);
} else {
return "return %1$s{%2$s}".formatted(
namespace.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,20 @@ protected String referenceStructureShape(final StructureShape shape) {
}

if (resourceOrService.asServiceShape().isPresent()) {
var clientConversion = dataSource;
var clientConversion = dataSource;
if (resourceOrService.hasTrait(ServiceTrait.class)) {
writer.addImportFromModule(
SmithyNameResolver.getGoModuleNameForSmithyNamespace(
resourceOrService.toShapeId().getNamespace()
SmithyNameResolver.getGoModuleNameForSmithyNamespace(
resourceOrService.toShapeId().getNamespace()
),
DafnyNameResolver.dafnyTypesNamespace(resourceOrService)
);
final var shim = "%swrapped.Shim".formatted(
DafnyNameResolver.dafnyNamespace(
resourceOrService.expectTrait(ServiceTrait.class)
)
);
final var shim =
"%swrapped.Shim".formatted(
DafnyNameResolver.dafnyNamespace(
resourceOrService.expectTrait(ServiceTrait.class)
)
);
clientConversion = "&%s{Client: &%s}".formatted(shim, dataSource);
}
if (!this.isOptional) {
Expand Down

0 comments on commit 830563c

Please sign in to comment.