Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ada] [Java] fix Codegen copies #15513

Merged
merged 2 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,27 +829,7 @@ private List<CodegenSecurity> postProcessAuthMethod(List<CodegenSecurity> authMe
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,6 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> securitySc

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);
}

Expand All @@ -416,32 +405,17 @@ class ExtendedCodegenSecurity extends CodegenSecurity {
public String tokenIntrospectUrl;

public ExtendedCodegenSecurity(CodegenSecurity cm) {
super();

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;
super(cm);

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
Expand Down