44
44
@ SmithyInternalApi
45
45
public final class AddHttpApiKeyAuthPlugin implements TypeScriptIntegration {
46
46
47
+ public static final String INTEGRATION_NAME = "HttpApiKeyAuth" ;
48
+
47
49
/**
48
50
* Plug into code generation for the client.
49
51
*
@@ -62,15 +64,15 @@ public List<RuntimeClientPlugin> getClientPlugins() {
62
64
// Add the config if the service uses HTTP API key authorization.
63
65
RuntimeClientPlugin .builder ()
64
66
.inputConfig (Symbol .builder ()
65
- .namespace ("./" + CodegenUtils .SOURCE_FOLDER + "/middleware/HttpApiKeyAuth" , "/" )
67
+ .namespace ("./" + CodegenUtils .SOURCE_FOLDER + "/middleware/" + INTEGRATION_NAME , "/" )
66
68
.name ("HttpApiKeyAuthInputConfig" )
67
69
.build ())
68
70
.resolvedConfig (Symbol .builder ()
69
- .namespace ("./" + CodegenUtils .SOURCE_FOLDER + "/middleware/HttpApiKeyAuth" , "/" )
71
+ .namespace ("./" + CodegenUtils .SOURCE_FOLDER + "/middleware/" + INTEGRATION_NAME , "/" )
70
72
.name ("HttpApiKeyAuthResolvedConfig" )
71
73
.build ())
72
74
.resolveFunction (Symbol .builder ()
73
- .namespace ("./" + CodegenUtils .SOURCE_FOLDER + "/middleware/HttpApiKeyAuth" , "/" )
75
+ .namespace ("./" + CodegenUtils .SOURCE_FOLDER + "/middleware/" + INTEGRATION_NAME , "/" )
74
76
.name ("resolveHttpApiKeyAuthConfig" )
75
77
.build ())
76
78
.servicePredicate ((m , s ) -> hasEffectiveHttpApiKeyAuthTrait (m , s ))
@@ -79,7 +81,7 @@ public List<RuntimeClientPlugin> getClientPlugins() {
79
81
// Add the middleware to operations that use HTTP API key authorization.
80
82
RuntimeClientPlugin .builder ()
81
83
.pluginFunction (Symbol .builder ()
82
- .namespace ("./" + CodegenUtils .SOURCE_FOLDER + "/middleware/HttpApiKeyAuth" , "/" )
84
+ .namespace ("./" + CodegenUtils .SOURCE_FOLDER + "/middleware/" + INTEGRATION_NAME , "/" )
83
85
.name ("getHttpApiKeyAuthPlugin" )
84
86
.build ())
85
87
.additionalPluginFunctionParamsSupplier ((m , s , o ) -> new HashMap <String , Object >() {{
@@ -119,7 +121,7 @@ public void writeAdditionalFiles(
119
121
120
122
// Write the middleware source.
121
123
writerFactory .accept (
122
- Paths .get (CodegenUtils .SOURCE_FOLDER , "middleware" , "HttpApiKeyAuth" , "index.ts" ).toString (),
124
+ Paths .get (CodegenUtils .SOURCE_FOLDER , "middleware" , INTEGRATION_NAME , "index.ts" ).toString (),
123
125
writer -> {
124
126
String source = IoUtils .readUtf8Resource (getClass (), "http-api-key-auth.ts" );
125
127
writer .write ("$L$L" , noTouchNoticePrefix , "http-api-key-auth.ts" );
@@ -128,7 +130,7 @@ public void writeAdditionalFiles(
128
130
129
131
// Write the middleware tests.
130
132
writerFactory .accept (
131
- Paths .get (CodegenUtils .SOURCE_FOLDER , "middleware" , "HttpApiKeyAuth" , "index.spec.ts" ).toString (),
133
+ Paths .get (CodegenUtils .SOURCE_FOLDER , "middleware" , INTEGRATION_NAME , "index.spec.ts" ).toString (),
132
134
writer -> {
133
135
writer .addDependency (SymbolDependency .builder ()
134
136
.dependencyType ("devDependencies" )
@@ -142,6 +144,20 @@ public void writeAdditionalFiles(
142
144
});
143
145
}
144
146
147
+ @ Override
148
+ public void writeAdditionalExports (
149
+ TypeScriptSettings settings ,
150
+ Model model ,
151
+ SymbolProvider symbolProvider ,
152
+ TypeScriptWriter writer
153
+ ) {
154
+ boolean isClientSdk = settings .generateClient ();
155
+ ServiceShape service = settings .getService (model );
156
+ if (isClientSdk && hasEffectiveHttpApiKeyAuthTrait (model , service )) {
157
+ writer .write ("export * from \" ./middleware/$1L\" ;" , INTEGRATION_NAME );
158
+ }
159
+ }
160
+
145
161
// The service has the effective trait if it's in the "effective auth schemes" response
146
162
// AND if not all of the operations have the optional auth trait.
147
163
private static boolean hasEffectiveHttpApiKeyAuthTrait (Model model , ServiceShape service ) {
0 commit comments