From ca2a77f1f847e934e19b749dcdffc02f340d5108 Mon Sep 17 00:00:00 2001 From: Steven Yuan Date: Wed, 13 Sep 2023 12:08:37 -0700 Subject: [PATCH] Update `HttpAuthSchemeProviderGenerator` to use new interfaces --- .../http/HttpAuthSchemeProviderGenerator.java | 60 ++++++++++--------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/http/HttpAuthSchemeProviderGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/http/HttpAuthSchemeProviderGenerator.java index eb2157ee638..c41dc51a1ee 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/http/HttpAuthSchemeProviderGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/http/HttpAuthSchemeProviderGenerator.java @@ -85,20 +85,24 @@ public void run() { } /* - export interface WeatherHttpAuthSchemeParameters { - operation?: string; + import { HttpAuthSchemeParameters } from "@smithy/types"; + + // ... + + export interface WeatherHttpAuthSchemeParameters extends HttpAuthSchemeParameters { } */ private void generateHttpAuthSchemeParametersInterface() { delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> { + w.addDependency(TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH); + w.addImport("HttpAuthSchemeParameters", null, TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH); w.openBlock(""" /** * @internal */ - export interface $LHttpAuthSchemeParameters {""", "}", + export interface $LHttpAuthSchemeParameters extends HttpAuthSchemeParameters {""", "}", serviceName, () -> { - w.write("operation?: string;"); for (HttpAuthScheme authScheme : authIndex.getSupportedHttpAuthSchemes().values()) { for (HttpAuthSchemeParameter parameter : authScheme.getHttpAuthSchemeParameters()) { w.write("$L?: $C;", parameter.name(), parameter.type()); @@ -110,32 +114,31 @@ export interface $LHttpAuthSchemeParameters {""", "}", /* import { WeatherClientResolvedConfig } from "../WeatherClient"; - import { HandlerExecutionContext } from "@smithy/types"; + import { HttpAuthSchemeParametersProvider } from "@smithy/types"; // ... - export async function defaultWeatherHttpAuthSchemeParametersProvider( - config: WeatherClientResolvedConfig, - context: HandlerExecutionContext - ): Promise { - return { - operation: context.commandName, - }; + export const defaultWeatherHttpAuthSchemeParametersProvider: + HttpAuthSchemeParametersProvider = + async (config, context) => { + return { + operation: context.commandName, + }; }; */ private void generateDefaultHttpAuthSchemeParametersProviderFunction() { delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> { w.addRelativeImport(serviceSymbol.getName() + "ResolvedConfig", null, Paths.get(".", serviceSymbol.getNamespace())); - w.addImport("HandlerExecutionContext", null, TypeScriptDependency.SMITHY_TYPES); + w.addDependency(TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH); + w.addImport("HttpAuthSchemeParametersProvider", null, TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH); w.openBlock(""" /** * @internal */ - export async function default$LHttpAuthSchemeParametersProvider( - config: $LResolvedConfig, - context: HandlerExecutionContext - ): Promise<$LHttpAuthSchemeParameters> {""", "};", + export const default$LHttpAuthSchemeParametersProvider: \ + HttpAuthSchemeParametersProvider<$LResolvedConfig, $LHttpAuthSchemeParameters> = \ + async (config, context) => {""", "};", serviceName, serviceSymbol.getName(), serviceName, () -> { w.openBlock("return {", "};", () -> { @@ -223,26 +226,28 @@ private static String normalizeAuthSchemeName(ShapeId shapeId) { } /* - export interface WeatherHttpAuthSchemeProvider { - (authParameters: WeatherHttpAuthSchemeParameters): HttpAuthOption[]; - } + import { HttpAuthSchemeProvider } from "@smithy/types"; + + // ... + + export interface WeatherHttpAuthSchemeProvider extends HttpAuthSchemeProvider {} */ private void generateHttpAuthSchemeProviderInterface() { delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> { + w.addDependency(TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH); + w.addImport("HttpAuthSchemeProvider", null, TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH); w.write(""" /** * @internal */ - export interface $LHttpAuthSchemeProvider { - (authParameters: $LHttpAuthSchemeParameters): HttpAuthOption[]; - } + export interface $LHttpAuthSchemeProvider extends HttpAuthSchemeProvider<$LHttpAuthSchemeParameters> {} """, serviceName, serviceName); }); } /* - export function defaultWeatherHttpAuthSchemeProvider(authParameters: WeatherHttpAuthSchemeParameters): - HttpAuthOption[] { + export const defaultWeatherHttpAuthSchemeProvider: WeatherHttpAuthSchemeProvider = + (authParameters) => { const options: HttpAuthOption[] = []; switch (authParameters.operation) { default: { @@ -258,8 +263,9 @@ private void generateHttpAuthSchemeProviderDefaultFunction() { /** * @internal */ - export function default$LHttpAuthSchemeProvider(authParameters: $LHttpAuthSchemeParameters): \ - HttpAuthOption[] {""", "};", serviceName, serviceName, () -> { + export const default$LHttpAuthSchemeProvider: $LHttpAuthSchemeProvider = \ + (authParameters) => {""", "};", + serviceName, serviceName, () -> { w.write("const options: HttpAuthOption[] = [];"); w.openBlock("switch (authParameters.operation) {", "};", () -> { var serviceAuthSchemes = serviceIndex.getEffectiveAuthSchemes(