Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffmaelite committed May 15, 2023
1 parent 05a6335 commit f3af63b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +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.scheme = scheme;
filteredSecurity.isBasic = isBasic;
filteredSecurity.isBasicBasic = isBasicBasic;
filteredSecurity.isHttpSignature = isHttpSignature;
filteredSecurity.bearerFormat = bearerFormat;
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 @@ -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,35 +405,17 @@ class ExtendedCodegenSecurity extends CodegenSecurity {
public String tokenIntrospectUrl;

public ExtendedCodegenSecurity(CodegenSecurity cm) {
super();

this.name = cm.name;
this.description = cm.description;
this.type = cm.type;
this.scheme = cm.scheme;
this.isBasic = cm.isBasic;
this.isOAuth = cm.isOAuth;
this.isApiKey = cm.isApiKey;
this.isOpenId = cm.isOpenId;
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.openIdConnectUrl = cm.openIdConnectUrl;
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

0 comments on commit f3af63b

Please sign in to comment.