17
17
18
18
package org .openapitools .codegen .languages ;
19
19
20
- import io .swagger .v3 .oas .models .media .Schema ;
21
- import io .swagger .v3 .parser .util .SchemaTypeUtil ;
22
- import lombok .Getter ;
23
- import lombok .Setter ;
20
+ import java .io .File ;
21
+ import java .util .List ;
22
+ import java .util .Locale ;
23
+ import java .util .Map ;
24
+ import java .util .TreeSet ;
25
+
24
26
import org .apache .commons .lang3 .StringUtils ;
25
27
import org .openapitools .codegen .*;
26
28
import org .openapitools .codegen .meta .features .DocumentationFeature ;
30
32
import org .openapitools .codegen .model .OperationMap ;
31
33
import org .openapitools .codegen .model .OperationsMap ;
32
34
import org .openapitools .codegen .utils .ModelUtils ;
35
+ import org .slf4j .Logger ;
36
+ import org .slf4j .LoggerFactory ;
33
37
34
- import java .io .File ;
35
- import java .util .List ;
36
- import java .util .Locale ;
37
- import java .util .Map ;
38
- import java .util .TreeSet ;
38
+ import io .swagger .v3 .oas .models .OpenAPI ;
39
+ import io .swagger .v3 .oas .models .media .Schema ;
40
+ import io .swagger .v3 .oas .models .security .SecurityScheme ;
41
+ import io .swagger .v3 .parser .util .SchemaTypeUtil ;
42
+ import lombok .Getter ;
43
+ import lombok .Setter ;
39
44
40
45
public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodegen {
41
46
@@ -53,6 +58,8 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
53
58
public static final String AXIOS_VERSION = "axiosVersion" ;
54
59
public static final String DEFAULT_AXIOS_VERSION = "^1.6.1" ;
55
60
61
+ private final Logger LOGGER = LoggerFactory .getLogger (TypeScriptAxiosClientCodegen .class );
62
+
56
63
@ Getter @ Setter
57
64
protected String npmRepository = null ;
58
65
protected Boolean stringEnums = false ;
@@ -121,6 +128,76 @@ private static String getRelativeToRoot(String path) {
121
128
return sb .toString ();
122
129
}
123
130
131
+ @ Override
132
+ public void preprocessOpenAPI (OpenAPI openAPI ) {
133
+ super .preprocessOpenAPI (openAPI );
134
+
135
+ boolean hasAwsV4Signature = detectAwsV4Signature (openAPI );
136
+ additionalProperties .put ("withAWSV4Signature" , hasAwsV4Signature );
137
+ }
138
+
139
+ /**
140
+ * Detects if the OpenAPI specification uses AWS V4 signature authentication
141
+ * by checking for common patterns used in AWS API Gateway specifications.
142
+ */
143
+ private boolean detectAwsV4Signature (OpenAPI openAPI ) {
144
+ // Check security schemes for AWS V4 signature patterns
145
+ if (openAPI .getComponents () != null && openAPI .getComponents ().getSecuritySchemes () != null ) {
146
+ return openAPI .getComponents ().getSecuritySchemes ().entrySet ().stream ()
147
+ .anyMatch (entry -> isAwsV4SecurityScheme (entry .getKey (), entry .getValue (), openAPI ));
148
+ }
149
+
150
+ return false ;
151
+ }
152
+
153
+ /**
154
+ * Determines if a security scheme represents AWS V4 signature authentication
155
+ */
156
+ private boolean isAwsV4SecurityScheme (String schemeName , SecurityScheme scheme , OpenAPI openAPI ) {
157
+ if (scheme == null ) {
158
+ return false ;
159
+ }
160
+
161
+ // Pattern 1: Check for AWS-specific extension
162
+ if (scheme .getExtensions () != null ) {
163
+ Object authType = scheme .getExtensions ().get ("x-amazon-apigateway-authtype" );
164
+ if ("awsSigv4" .equals (authType )) {
165
+ return true ;
166
+ }
167
+ }
168
+
169
+ // Pattern 2: Check for common AWS V4 signature scheme names
170
+ String lowerSchemeName = schemeName .toLowerCase (Locale .ROOT );
171
+ if (lowerSchemeName .contains ("sigv4" ) ||
172
+ lowerSchemeName .contains ("aws" ) ||
173
+ lowerSchemeName .contains ("iam" )) {
174
+
175
+ // Additional validation: should be apiKey type with Authorization header
176
+ if (SecurityScheme .Type .APIKEY .equals (scheme .getType ()) &&
177
+ "Authorization" .equalsIgnoreCase (scheme .getName ()) &&
178
+ SecurityScheme .In .HEADER .equals (scheme .getIn ())) {
179
+ return true ;
180
+ }
181
+ }
182
+
183
+ // Pattern 3: Check for AWS API Gateway URL patterns in servers
184
+ if (openAPI .getServers () != null ) {
185
+ boolean hasAwsApiGatewayUrl = openAPI .getServers ().stream ()
186
+ .anyMatch (server -> server .getUrl () != null &&
187
+ (server .getUrl ().contains ("execute-api" ) && server .getUrl ().contains ("amazonaws.com" )));
188
+
189
+ // If we have AWS API Gateway URL and an Authorization header scheme, likely AWS V4
190
+ if (hasAwsApiGatewayUrl &&
191
+ SecurityScheme .Type .APIKEY .equals (scheme .getType ()) &&
192
+ "Authorization" .equalsIgnoreCase (scheme .getName ()) &&
193
+ SecurityScheme .In .HEADER .equals (scheme .getIn ())) {
194
+ return true ;
195
+ }
196
+ }
197
+
198
+ return false ;
199
+ }
200
+
124
201
@ Override
125
202
public void processOpts () {
126
203
super .processOpts ();
@@ -182,7 +259,6 @@ public void processOpts() {
182
259
setAxiosVersion (additionalProperties .get (AXIOS_VERSION ).toString ());
183
260
}
184
261
additionalProperties .put ("axiosVersion" , getAxiosVersion ());
185
-
186
262
}
187
263
188
264
@ Override
@@ -363,4 +439,22 @@ protected void addImport(Schema composed, Schema childSchema, CodegenModel model
363
439
// import everything (including child schema of a composed schema)
364
440
addImport (model , modelName );
365
441
}
442
+
443
+ @ Override
444
+ public List <CodegenSecurity > fromSecurity (Map <String , SecurityScheme > securitySchemeMap ) {
445
+ List <CodegenSecurity > securities = super .fromSecurity (securitySchemeMap );
446
+
447
+ // Post-process security schemes to detect AWS V4 signature
448
+ for (CodegenSecurity security : securities ) {
449
+ if (securitySchemeMap .containsKey (security .name )) {
450
+ SecurityScheme scheme = securitySchemeMap .get (security .name );
451
+ if (isAwsV4SecurityScheme (security .name , scheme , this .openAPI )) {
452
+ security .isAWSV4Signature = true ;
453
+ LOGGER .info ("Detected AWS V4 signature security scheme: {}" , security .name );
454
+ }
455
+ }
456
+ }
457
+
458
+ return securities ;
459
+ }
366
460
}
0 commit comments