-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimentalIdentityAndAuth): update code generation
Make code generation changes for `experimentalIdentityAndAuth`. Bug fixes: - fix misused service name when importing the default auth scheme provider - add generic type to resolve config function input and output Updates: - add remove methods to `HttpAuthScheme` builder - update code generation for `ConfigField` (and more code sections) - update `customizeSupportedHttpAuthSchemes()` to include model and settings - add resolve functions codegen for `HttpAuthScheme`s - update various `String` parameters to take `Symbol` instead
- Loading branch information
Showing
25 changed files
with
1,491 additions
and
406 deletions.
There are no files selected for viewing
103 changes: 0 additions & 103 deletions
103
...pescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ConfigField.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
...odegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/http/ConfigField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.typescript.codegen.auth.http; | ||
|
||
import java.util.Optional; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
import software.amazon.smithy.codegen.core.Symbol; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptDependency; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptWriter; | ||
import software.amazon.smithy.utils.SmithyBuilder; | ||
import software.amazon.smithy.utils.SmithyInternalApi; | ||
import software.amazon.smithy.utils.SmithyUnstableApi; | ||
import software.amazon.smithy.utils.ToSmithyBuilder; | ||
|
||
/** | ||
* Definition of a Config field. | ||
* | ||
* Currently used to populate the ClientDefaults interface in `experimentalIdentityAndAuth`. | ||
* | ||
* @param name name of the config field | ||
* @param type whether the config field is main or auxiliary | ||
* @param inputType writer for the input type of the config field | ||
* @param resolvedType writer for the resolved type of the config field | ||
* @param docs writer for the docs of the config field | ||
*/ | ||
@SmithyUnstableApi | ||
public final record ConfigField( | ||
String name, | ||
Type type, | ||
Symbol inputType, | ||
Symbol resolvedType, | ||
BiConsumer<TypeScriptWriter, ConfigField> configFieldWriter, | ||
Optional<Consumer<TypeScriptWriter>> docs | ||
) implements ToSmithyBuilder<ConfigField> { | ||
|
||
/** | ||
* Defines the type of the config field. | ||
*/ | ||
@SmithyUnstableApi | ||
public enum Type { | ||
/** | ||
* Specifies the property is important, e.g. {@code apiKey} for {@code @httpApiKeyAuth} | ||
*/ | ||
MAIN, | ||
/** | ||
* Specifies the property is auxiliary, e.g. {@code region} for {@code @aws.auth#sigv4} | ||
*/ | ||
AUXILIARY | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
@Override | ||
public Builder toBuilder() { | ||
return builder() | ||
.name(name) | ||
.type(type) | ||
.inputType(inputType) | ||
.resolvedType(resolvedType) | ||
.configFieldWriter(configFieldWriter) | ||
.docs(docs.orElse(null)); | ||
} | ||
|
||
public static final class Builder implements SmithyBuilder<ConfigField> { | ||
private String name; | ||
private Type type; | ||
private Symbol inputType; | ||
private Symbol resolvedType; | ||
private Consumer<TypeScriptWriter> docs; | ||
private BiConsumer<TypeScriptWriter, ConfigField> configFieldWriter; | ||
|
||
@Override | ||
public ConfigField build() { | ||
if (configFieldWriter == null) { | ||
configFieldWriter = type.equals(Type.MAIN) | ||
? ConfigField::defaultMainConfigFieldWriter | ||
: ConfigField::defaultAuxiliaryConfigFieldWriter; | ||
} | ||
return new ConfigField( | ||
SmithyBuilder.requiredState("name", name), | ||
SmithyBuilder.requiredState("type", type), | ||
SmithyBuilder.requiredState("inputType", inputType), | ||
SmithyBuilder.requiredState("resolvedType", resolvedType), | ||
SmithyBuilder.requiredState("configFieldWriter", configFieldWriter), | ||
Optional.ofNullable(docs)); | ||
} | ||
|
||
public Builder name(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Builder type(Type type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
public Builder inputType(Symbol inputType) { | ||
this.inputType = inputType; | ||
return this; | ||
} | ||
|
||
public Builder resolvedType(Symbol resolvedType) { | ||
this.resolvedType = resolvedType; | ||
return this; | ||
} | ||
|
||
public Builder docs(Consumer<TypeScriptWriter> docs) { | ||
this.docs = docs; | ||
return this; | ||
} | ||
|
||
public Builder configFieldWriter(BiConsumer<TypeScriptWriter, ConfigField> configFieldWriter) { | ||
this.configFieldWriter = configFieldWriter; | ||
return this; | ||
} | ||
} | ||
|
||
@SmithyInternalApi | ||
public static void defaultMainConfigFieldWriter( | ||
TypeScriptWriter w, | ||
ConfigField configField | ||
) { | ||
w.addDependency(TypeScriptDependency.SMITHY_CORE); | ||
w.addImport("memoizeIdentityProvider", null, | ||
TypeScriptDependency.SMITHY_CORE); | ||
w.addImport("isIdentityExpired", null, | ||
TypeScriptDependency.SMITHY_CORE); | ||
w.addImport("doesIdentityRequireRefresh", null, | ||
TypeScriptDependency.SMITHY_CORE); | ||
w.write(""" | ||
const $L = memoizeIdentityProvider(config.$L, isIdentityExpired, \ | ||
doesIdentityRequireRefresh);""", | ||
configField.name(), | ||
configField.name()); | ||
} | ||
|
||
@SmithyInternalApi | ||
public static void defaultAuxiliaryConfigFieldWriter( | ||
TypeScriptWriter w, | ||
ConfigField configField | ||
) { | ||
w.addDependency(TypeScriptDependency.UTIL_MIDDLEWARE); | ||
w.addImport("normalizeProvider", null, TypeScriptDependency.UTIL_MIDDLEWARE); | ||
w.write("const $L = config.$L ? normalizeProvider(config.$L) : undefined;", | ||
configField.name(), | ||
configField.name(), | ||
configField.name()); | ||
} | ||
} |
Oops, something went wrong.