Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to_s #211

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions codegen/projections/rails_json/lib/rails_json/types.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 62 additions & 66 deletions codegen/projections/white_label/lib/white_label/types.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codegen/smithy-ruby-codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased Changes
------------------

* Issue - Add `to_s` to `Structure`.
* Issue - Remove `Struct` from generated Types, Config, and other places to allow for better RBS typing as well as less reserved words.
* Feature - Add support for stringArray Endpoint parameters + operationContextParams binding.
* Issue - Update reserved member names for new Struct methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,29 @@ private void renderToSMethod(RubyCodeWriter writer) {

writer
.openBlock("\ndef to_s")
.write("\"#<$L \"\\", fullQualifiedShapeName)
.write("'#<$L ' \\", fullQualifiedShapeName)
.indent();

while (iterator.hasNext()) {
MemberShape memberShape = iterator.next();
String key = symbolProvider.toMemberName(memberShape);
String value = "#{" + key + " || 'nil'}";
boolean memberLiteral = false;

if (memberShape.isBlobShape() || memberShape.isStringShape()) {
// Strings are wrapped in quotes
value = "\"" + value + "\"";
memberLiteral = true;
} else if (memberShape.getMemberTrait(model, SensitiveTrait.class).isPresent()) {
value = "\\\"[SENSITIVE]\\\"";
value = "[SENSITIVE]";
memberLiteral = true;
}

String quote = memberLiteral ? "'" : "\"";
if (iterator.hasNext()) {
writer.write("\"$L=$L, \"\\", key, value);
writer.write("$3L$1L=$2L, $3L \\", key, value, quote);
} else {
writer.write("\"$L=$L>\"", key, value);
writer.write("$3L$1L=$2L>$3L", key, value, quote);
}
}
writer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,17 @@ public void render() {
}

private void renderUnionToSMethod(RubyCodeWriter writer, MemberShape memberShape) {
String fullQualifiedShapeName = settings.getModule() + "::Types::"
+ symbolProvider.toMemberName(memberShape);

writer.write("")
.openBlock("def to_s");

if (memberShape.getMemberTrait(model, SensitiveTrait.class).isPresent()) {
writer.write("\"#<$L [SENSITIVE]>\"", fullQualifiedShapeName);
} else {
writer.write("\"#<$L #{__getobj__ || 'nil'}>\"", fullQualifiedShapeName);
if (!memberShape.getMemberTrait(model, SensitiveTrait.class).isPresent()) {
return;
}

writer.closeBlock("end");
String fullQualifiedShapeName = settings.getModule() + "::Types::"
+ symbolProvider.toMemberName(memberShape);
writer
.write("")
.openBlock("def to_s")
.write("\"#<$L [SENSITIVE]>\"", fullQualifiedShapeName)
.closeBlock("end");
}

private class UnionToHValueRbsVisitor extends ShapeVisitor.Default<String> {
Expand Down
Loading
Loading