[Ada] [Java] fix Codegen copies (#15513)

* fix incomplete codegensecurity copies

* refactoring
This commit is contained in:
Tiffany Marrel 2023-05-20 14:12:18 +02:00 committed by GitHub
parent 3e10c5dbcf
commit 89e4b24295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 85 deletions

View File

@ -46,36 +46,49 @@ public class CodegenSecurity {
// OpenId specific
public String openIdConnectUrl;
// Return a copy of the security object, filtering out any scopes from the passed-in list.
public CodegenSecurity filterByScopeNames(List<String> filterScopes) {
CodegenSecurity filteredSecurity = new CodegenSecurity();
// Copy all fields except the scopes.
filteredSecurity.name = name;
filteredSecurity.description = description;
filteredSecurity.type = type;
filteredSecurity.isBasic = isBasic;
filteredSecurity.isBasicBasic = isBasicBasic;
filteredSecurity.isHttpSignature = isHttpSignature;
filteredSecurity.isBasicBearer = isBasicBearer;
filteredSecurity.isApiKey = isApiKey;
filteredSecurity.isOAuth = isOAuth;
filteredSecurity.isOpenId = isOpenId;
filteredSecurity.keyParamName = keyParamName;
filteredSecurity.isCode = isCode;
filteredSecurity.isImplicit = isImplicit;
filteredSecurity.isApplication = isApplication;
filteredSecurity.isPassword = isPassword;
filteredSecurity.isKeyInCookie = isKeyInCookie;
filteredSecurity.isKeyInHeader = isKeyInHeader;
filteredSecurity.isKeyInQuery = isKeyInQuery;
filteredSecurity.flow = flow;
filteredSecurity.tokenUrl = tokenUrl;
filteredSecurity.authorizationUrl = authorizationUrl;
filteredSecurity.refreshUrl = refreshUrl;
filteredSecurity.openIdConnectUrl = openIdConnectUrl;
public CodegenSecurity () {
}
public CodegenSecurity (CodegenSecurity original) {
this.name = original.name;
this.description = original.description;
this.type = original.type;
this.scheme = original.scheme;
this.isBasic = original.isBasic;
this.isBasicBasic = original.isBasicBasic;
this.isHttpSignature = original.isHttpSignature;
this.bearerFormat = original.bearerFormat;
this.isBasicBearer = original.isBasicBearer;
this.isApiKey = original.isApiKey;
this.isOAuth = original.isOAuth;
this.isOpenId = original.isOpenId;
this.keyParamName = original.keyParamName;
this.isCode = original.isCode;
this.isImplicit = original.isImplicit;
this.isApplication = original.isApplication;
this.isPassword = original.isPassword;
this.isKeyInCookie = original.isKeyInCookie;
this.isKeyInHeader = original.isKeyInHeader;
this.isKeyInQuery = original.isKeyInQuery;
this.flow = original.flow;
this.tokenUrl = original.tokenUrl;
this.authorizationUrl = original.authorizationUrl;
this.refreshUrl = original.refreshUrl;
this.openIdConnectUrl = original.openIdConnectUrl;
// It is not possible to deep copy the extensions, as we have no idea what types they are.
// So the filtered method *will* refer to the original extensions, if any.
filteredSecurity.vendorExtensions = new HashMap<String, Object>(vendorExtensions);
this.vendorExtensions = original.vendorExtensions == null ? null : new HashMap<String, Object>(original.vendorExtensions);
// It is not possible to deep copy the extensions, as we have no idea what type their values are.
// So the filtered method *will* refer to the original scopes, if any.
this.scopes = original.scopes == null ? null : new ArrayList<Map<String, Object>>(original.scopes);
}
// Return a copy of the security object, filtering out any scopes from the passed-in list.
public CodegenSecurity filterByScopeNames(List<String> filterScopes) {
CodegenSecurity filteredSecurity = new CodegenSecurity(this);
List<Map<String, Object>> returnedScopes = new ArrayList<Map<String, Object>>();
Map<String, Object> lastScope = null;
for (String filterScopeName : filterScopes) {

View File

@ -829,27 +829,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
List<String> opScopes = (scopes == null) ? null : scopes.get(authMethod.name);
authMethod.name = camelize(sanitizeName(authMethod.name), LOWERCASE_FIRST_LETTER);
if (opScopes != null) {
CodegenSecurity opSecurity = new CodegenSecurity();
opSecurity.name = authMethod.name;
opSecurity.type = authMethod.type;
opSecurity.isBasic = authMethod.isBasic;
opSecurity.isApiKey = authMethod.isApiKey;
opSecurity.isKeyInCookie = authMethod.isKeyInCookie;
opSecurity.isKeyInHeader = authMethod.isKeyInHeader;
opSecurity.isKeyInQuery = authMethod.isKeyInQuery;
opSecurity.flow = authMethod.flow;
opSecurity.tokenUrl = authMethod.tokenUrl;
List<Map<String, Object>> opAuthScopes = new ArrayList<>();
for (String opScopeName : opScopes) {
for (Map<String, Object> scope : authMethod.scopes) {
String name = (String) scope.get("scope");
if (opScopeName.equals(name)) {
opAuthScopes.add(scope);
break;
}
}
}
opSecurity.scopes = opAuthScopes;
CodegenSecurity opSecurity = authMethod.filterByScopeNames(opScopes);
result.add(opSecurity);
}
}

View File

@ -393,17 +393,6 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
for (CodegenSecurity codegenSecurity : securities) {
ExtendedCodegenSecurity extendedCodegenSecurity = new ExtendedCodegenSecurity(codegenSecurity);
Object jwksUrl = extendedCodegenSecurity.vendorExtensions.get(X_JWKS_URL);
if (jwksUrl instanceof String) {
extendedCodegenSecurity.jwksUrl = (String) jwksUrl;
}
Object tokenIntrospectUrl = extendedCodegenSecurity.vendorExtensions.get(X_TOKEN_INTROSPECT_URL);
if (tokenIntrospectUrl instanceof String) {
extendedCodegenSecurity.tokenIntrospectUrl = (String) tokenIntrospectUrl;
}
extendedSecurities.add(extendedCodegenSecurity);
}
@ -416,32 +405,17 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
public String tokenIntrospectUrl;
public ExtendedCodegenSecurity(CodegenSecurity cm) {
super();
super(cm);
this.name = cm.name;
this.type = cm.type;
this.scheme = cm.scheme;
this.isBasic = cm.isBasic;
this.isOAuth = cm.isOAuth;
this.isApiKey = cm.isApiKey;
this.isBasicBasic = cm.isBasicBasic;
this.isBasicBearer = cm.isBasicBearer;
this.isHttpSignature = cm.isHttpSignature;
this.bearerFormat = cm.bearerFormat;
this.vendorExtensions = new HashMap<String, Object>(cm.vendorExtensions);
this.keyParamName = cm.keyParamName;
this.isKeyInQuery = cm.isKeyInQuery;
this.isKeyInHeader = cm.isKeyInHeader;
this.isKeyInCookie = cm.isKeyInCookie;
this.flow = cm.flow;
this.authorizationUrl = cm.authorizationUrl;
this.tokenUrl = cm.tokenUrl;
this.refreshUrl = cm.refreshUrl;
this.scopes = cm.scopes;
this.isCode = cm.isCode;
this.isPassword = cm.isPassword;
this.isApplication = cm.isApplication;
this.isImplicit = cm.isImplicit;
Object cmJwksUrl = cm.vendorExtensions.get(X_JWKS_URL);
if (cmJwksUrl instanceof String) {
this.jwksUrl = (String) cmJwksUrl;
}
Object cmTokenIntrospectUrl = cm.vendorExtensions.get(X_TOKEN_INTROSPECT_URL);
if (cmTokenIntrospectUrl instanceof String) {
this.tokenIntrospectUrl = (String) cmTokenIntrospectUrl;
}
}
@Override