Skip to content
Closed
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 @@ -50,6 +50,7 @@
import software.amazon.smithy.typescript.codegen.endpointsV2.RuleSetParameterFinder;
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator;
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin;
import software.amazon.smithy.typescript.codegen.sections.SmithyContextCodeSection;
import software.amazon.smithy.typescript.codegen.validation.SensitiveDataFinder;
import software.amazon.smithy.utils.OptionalUtils;
import software.amazon.smithy.utils.SmithyInternalApi;
Expand Down Expand Up @@ -361,6 +362,10 @@ private void generateCommandMiddlewareResolver(String configType) {
writer.openBlock("[SMITHY_CONTEXT_KEY]: {", "},", () -> {
writer.write("service: $S,", service.toShapeId().getName());
writer.write("operation: $S,", operation.toShapeId().getName());
writer.injectSection(SmithyContextCodeSection.builder()
.service(service)
.operation(operation)
.build());
});
});
writer.write("const { requestHandler } = configuration;");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

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

import java.util.List;
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
import software.amazon.smithy.typescript.codegen.TypeScriptCodegenContext;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
import software.amazon.smithy.typescript.codegen.sections.SmithyContextCodeSection;
import software.amazon.smithy.utils.CodeInterceptor;
import software.amazon.smithy.utils.CodeSection;
import software.amazon.smithy.utils.SmithyInternalApi;

@SmithyInternalApi
public class AddEndpointRuleSetIntegration implements TypeScriptIntegration {
@Override
public List<? extends CodeInterceptor<? extends CodeSection, TypeScriptWriter>> interceptors(
TypeScriptCodegenContext codegenContext
) {
return List.of(CodeInterceptor.appender(SmithyContextCodeSection.class, (w, s) -> {
if (s.getService().hasTrait(EndpointRuleSetTrait.ID)) {
w.openBlock("endpointRuleSet: {", "},", () -> {
w.write("getEndpointParameterInstructions: $T.getEndpointParameterInstructions,",
codegenContext.symbolProvider().toSymbol(s.getOperation()));
});
}
}));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.typescript.codegen.sections;

import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.utils.CodeSection;
import software.amazon.smithy.utils.SmithyBuilder;
import software.amazon.smithy.utils.SmithyUnstableApi;

@SmithyUnstableApi
public class SmithyContextCodeSection implements CodeSection {
private final ServiceShape service;
private final OperationShape operation;

private SmithyContextCodeSection(Builder builder) {
service = SmithyBuilder.requiredState("service", builder.service);
operation = SmithyBuilder.requiredState("operation", builder.operation);
}

public ServiceShape getService() {
return service;
}

public OperationShape getOperation() {
return operation;
}

public static Builder builder() {
return new Builder();
}

public static class Builder implements SmithyBuilder<SmithyContextCodeSection>{
private ServiceShape service;
private OperationShape operation;

@Override
public SmithyContextCodeSection build() {
return new SmithyContextCodeSection(this);
}

public Builder service(ServiceShape service) {
this.service = service;
return this;
}

public Builder operation(OperationShape operation) {
this.operation = operation;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ software.amazon.smithy.typescript.codegen.integration.AddHttpApiKeyAuthPlugin
software.amazon.smithy.typescript.codegen.integration.AddBaseServiceExceptionClass
software.amazon.smithy.typescript.codegen.integration.AddSdkStreamMixinDependency
software.amazon.smithy.typescript.codegen.integration.DefaultReadmeGenerator
software.amazon.smithy.typescript.codegen.integration.AddEndpointRuleSetIntegration