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

feat: add client config passthrough to waiter opts #500

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,21 @@ public static Writable goDocTemplate(String contents) {
* @return writer for formatted docs.
*/
public static Writable autoDocTemplate(String contents) {
return GoWriter.ChainWritable.of(
Arrays.stream(contents.split("\n\n"))
.map(it -> docParagraphWriter(it.replace("\n", " ")))
.toList()
).compose(false);
var paragraphs = contents.split("\n\n");
var chain = new GoWriter.ChainWritable();
for (int i = 0; i < paragraphs.length; ++i) {
chain.add(docParagraphWriter(paragraphs[i], i < paragraphs.length - 1));
}
return chain.compose(false);
}

private static GoWriter.Writable docParagraphWriter(String paragraph) {
return writer -> writer.writeDocs(paragraph).writeDocs("");
private static GoWriter.Writable docParagraphWriter(String paragraph, boolean writeNewline) {
return writer -> {
writer.writeDocs(paragraph);
if (writeNewline) {
writer.writeDocs("");
}
};
}

@SafeVarargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@

package software.amazon.smithy.go.codegen.integration;

import static software.amazon.smithy.go.codegen.GoWriter.autoDocTemplate;
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate;

import java.util.Map;
import java.util.Optional;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.go.codegen.ClientOptions;
import software.amazon.smithy.go.codegen.GoDelegator;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.GoWriter;
Expand Down Expand Up @@ -139,15 +143,31 @@ private void generateWaiterOptions(
writer.addUseImports(SmithyGoDependency.TIME);

writer.write("");
writer.writeDocs(
"Set of options to modify how an operation is invoked. These apply to all operations "
+ "invoked for this client. Use functional options on operation call to modify "
+ "this list for per operation behavior."
);
var apiOptionsDocs = autoDocTemplate("""
Set of options to modify how an operation is invoked. These apply to all operations invoked
for this client. Use functional options on operation call to modify this list for per
operation behavior.

Passing options here is functionally equivalent to passing values to this config's
ClientOptions field that extend the inner client's APIOptions directly.""");
Symbol stackSymbol = SymbolUtils.createPointableSymbolBuilder("Stack",
SmithyGoDependency.SMITHY_MIDDLEWARE)
.build();
writer.write("APIOptions []func($P) error", stackSymbol);
writer.write(goTemplate("""
$W
APIOptions []func($P) error
""", apiOptionsDocs, stackSymbol));

var clientOptionsDocs = autoDocTemplate("""
Functional options to be passed to all operations invoked by this client.

Function values that modify the inner APIOptions are applied after the waiter config's own
APIOptions modifiers.""");
writer.write("");
writer.write(goTemplate("""
$W
ClientOptions []func(*$L)
""", clientOptionsDocs, ClientOptions.NAME));

writer.write("");
writer.writeDocs(
Expand Down Expand Up @@ -423,6 +443,10 @@ private void generateWaiterInvokerWithOutput(
writer.openBlock("out, err := w.client.$T(ctx, params, func (o *Options) { ", "})",
operationSymbol, () -> {
writer.write("o.APIOptions = append(o.APIOptions, apiOptions...)");
writer.write("""
for _, opt := range options.ClientOptions {
opt(o)
}""");
});
writer.write("");

Expand Down
Loading