diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java index 0f4011f1966..c171a450066 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java @@ -56,6 +56,7 @@ import software.amazon.smithy.typescript.codegen.sections.CommandBodyExtraCodeSection; import software.amazon.smithy.typescript.codegen.sections.CommandConstructorCodeSection; import software.amazon.smithy.typescript.codegen.sections.CommandPropertiesCodeSection; +import software.amazon.smithy.typescript.codegen.sections.PreCommandClassCodeSection; import software.amazon.smithy.typescript.codegen.sections.SmithyContextCodeSection; import software.amazon.smithy.typescript.codegen.validation.SensitiveDataFinder; import software.amazon.smithy.utils.SmithyInternalApi; @@ -154,6 +155,17 @@ private void generateClientCommand() { ); } + // Section of items like TypeScript @ts-ignore + writer.injectSection(PreCommandClassCodeSection.builder() + .settings(settings) + .model(model) + .service(service) + .operation(operation) + .symbolProvider(symbolProvider) + .runtimeClientPlugins(runtimePlugins) + .protocolGenerator(protocolGenerator) + .applicationProtocol(applicationProtocol) + .build()); writer.openBlock( "export class $L extends $$Command.classBuilder<$T, $T, $L, ServiceInputTypes, ServiceOutputTypes>()", ".build() {", // class open bracket. diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/sections/PreCommandClassCodeSection.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/sections/PreCommandClassCodeSection.java new file mode 100644 index 00000000000..06b3aa6317f --- /dev/null +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/sections/PreCommandClassCodeSection.java @@ -0,0 +1,135 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.typescript.codegen.sections; + +import java.util.List; +import java.util.Optional; +import software.amazon.smithy.codegen.core.SymbolProvider; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.shapes.OperationShape; +import software.amazon.smithy.model.shapes.ServiceShape; +import software.amazon.smithy.typescript.codegen.ApplicationProtocol; +import software.amazon.smithy.typescript.codegen.TypeScriptSettings; +import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator; +import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin; +import software.amazon.smithy.utils.CodeSection; +import software.amazon.smithy.utils.SmithyBuilder; +import software.amazon.smithy.utils.SmithyUnstableApi; + +@SmithyUnstableApi +public final class PreCommandClassCodeSection implements CodeSection { + private final TypeScriptSettings settings; + private final Model model; + private final ServiceShape service; + private final OperationShape operation; + private final SymbolProvider symbolProvider; + private final List runtimeClientPlugins; + private final ProtocolGenerator protocolGenerator; + private final ApplicationProtocol applicationProtocol; + + private PreCommandClassCodeSection(Builder builder) { + settings = SmithyBuilder.requiredState("settings", builder.settings); + model = SmithyBuilder.requiredState("model", builder.model); + service = SmithyBuilder.requiredState("service", builder.service); + operation = SmithyBuilder.requiredState("operation", builder.operation); + symbolProvider = SmithyBuilder.requiredState("symbolProvider", builder.symbolProvider); + runtimeClientPlugins = SmithyBuilder.requiredState("runtimeClientPlugins", builder.runtimeClientPlugins); + protocolGenerator = builder.protocolGenerator; + applicationProtocol = SmithyBuilder.requiredState("applicationProtocol", builder.applicationProtocol); + } + + public static Builder builder() { + return new Builder(); + } + + public TypeScriptSettings getSettings() { + return settings; + } + + public Model getModel() { + return model; + } + + public ServiceShape getService() { + return service; + } + + public OperationShape getOperation() { + return operation; + } + + public SymbolProvider getSymbolProvider() { + return symbolProvider; + } + + public List getRuntimeClientPlugins() { + return runtimeClientPlugins; + } + + public Optional getProtocolGenerator() { + return Optional.ofNullable(protocolGenerator); + } + + public ApplicationProtocol getApplicationProtocol() { + return applicationProtocol; + } + + public static class Builder implements SmithyBuilder { + private TypeScriptSettings settings; + private Model model; + private ServiceShape service; + private OperationShape operation; + private SymbolProvider symbolProvider; + private List runtimeClientPlugins; + private ProtocolGenerator protocolGenerator; + private ApplicationProtocol applicationProtocol; + + @Override + public PreCommandClassCodeSection build() { + return new PreCommandClassCodeSection(this); + } + + public Builder settings(TypeScriptSettings settings) { + this.settings = settings; + return this; + } + + public Builder model(Model model) { + this.model = model; + return this; + } + + public Builder service(ServiceShape service) { + this.service = service; + return this; + } + + public Builder operation(OperationShape operation) { + this.operation = operation; + return this; + } + + public Builder symbolProvider(SymbolProvider symbolProvider) { + this.symbolProvider = symbolProvider; + return this; + } + + public Builder runtimeClientPlugins(List runtimeClientPlugins) { + this.runtimeClientPlugins = runtimeClientPlugins; + return this; + } + + public Builder protocolGenerator(ProtocolGenerator protocolGenerator) { + this.protocolGenerator = protocolGenerator; + return this; + } + + public Builder applicationProtocol(ApplicationProtocol applicationProtocol) { + this.applicationProtocol = applicationProtocol; + return this; + } + } +}