forked from loafle/openapi-generator-original
[Ada] [Java] fix Codegen copies (#15513)
* fix incomplete codegensecurity copies * refactoring
This commit is contained in:
parent
3e10c5dbcf
commit
89e4b24295
@ -46,36 +46,49 @@ public class CodegenSecurity {
|
|||||||
// OpenId specific
|
// OpenId specific
|
||||||
public String openIdConnectUrl;
|
public String openIdConnectUrl;
|
||||||
|
|
||||||
// Return a copy of the security object, filtering out any scopes from the passed-in list.
|
public CodegenSecurity () {
|
||||||
public CodegenSecurity filterByScopeNames(List<String> filterScopes) {
|
}
|
||||||
CodegenSecurity filteredSecurity = new CodegenSecurity();
|
|
||||||
// Copy all fields except the scopes.
|
public CodegenSecurity (CodegenSecurity original) {
|
||||||
filteredSecurity.name = name;
|
this.name = original.name;
|
||||||
filteredSecurity.description = description;
|
this.description = original.description;
|
||||||
filteredSecurity.type = type;
|
this.type = original.type;
|
||||||
filteredSecurity.isBasic = isBasic;
|
this.scheme = original.scheme;
|
||||||
filteredSecurity.isBasicBasic = isBasicBasic;
|
this.isBasic = original.isBasic;
|
||||||
filteredSecurity.isHttpSignature = isHttpSignature;
|
this.isBasicBasic = original.isBasicBasic;
|
||||||
filteredSecurity.isBasicBearer = isBasicBearer;
|
this.isHttpSignature = original.isHttpSignature;
|
||||||
filteredSecurity.isApiKey = isApiKey;
|
this.bearerFormat = original.bearerFormat;
|
||||||
filteredSecurity.isOAuth = isOAuth;
|
this.isBasicBearer = original.isBasicBearer;
|
||||||
filteredSecurity.isOpenId = isOpenId;
|
this.isApiKey = original.isApiKey;
|
||||||
filteredSecurity.keyParamName = keyParamName;
|
this.isOAuth = original.isOAuth;
|
||||||
filteredSecurity.isCode = isCode;
|
this.isOpenId = original.isOpenId;
|
||||||
filteredSecurity.isImplicit = isImplicit;
|
this.keyParamName = original.keyParamName;
|
||||||
filteredSecurity.isApplication = isApplication;
|
this.isCode = original.isCode;
|
||||||
filteredSecurity.isPassword = isPassword;
|
this.isImplicit = original.isImplicit;
|
||||||
filteredSecurity.isKeyInCookie = isKeyInCookie;
|
this.isApplication = original.isApplication;
|
||||||
filteredSecurity.isKeyInHeader = isKeyInHeader;
|
this.isPassword = original.isPassword;
|
||||||
filteredSecurity.isKeyInQuery = isKeyInQuery;
|
this.isKeyInCookie = original.isKeyInCookie;
|
||||||
filteredSecurity.flow = flow;
|
this.isKeyInHeader = original.isKeyInHeader;
|
||||||
filteredSecurity.tokenUrl = tokenUrl;
|
this.isKeyInQuery = original.isKeyInQuery;
|
||||||
filteredSecurity.authorizationUrl = authorizationUrl;
|
this.flow = original.flow;
|
||||||
filteredSecurity.refreshUrl = refreshUrl;
|
this.tokenUrl = original.tokenUrl;
|
||||||
filteredSecurity.openIdConnectUrl = openIdConnectUrl;
|
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.
|
// 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.
|
// 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>>();
|
List<Map<String, Object>> returnedScopes = new ArrayList<Map<String, Object>>();
|
||||||
Map<String, Object> lastScope = null;
|
Map<String, Object> lastScope = null;
|
||||||
for (String filterScopeName : filterScopes) {
|
for (String filterScopeName : filterScopes) {
|
||||||
|
@ -829,27 +829,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
|||||||
List<String> opScopes = (scopes == null) ? null : scopes.get(authMethod.name);
|
List<String> opScopes = (scopes == null) ? null : scopes.get(authMethod.name);
|
||||||
authMethod.name = camelize(sanitizeName(authMethod.name), LOWERCASE_FIRST_LETTER);
|
authMethod.name = camelize(sanitizeName(authMethod.name), LOWERCASE_FIRST_LETTER);
|
||||||
if (opScopes != null) {
|
if (opScopes != null) {
|
||||||
CodegenSecurity opSecurity = new CodegenSecurity();
|
CodegenSecurity opSecurity = authMethod.filterByScopeNames(opScopes);
|
||||||
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;
|
|
||||||
result.add(opSecurity);
|
result.add(opSecurity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -393,17 +393,6 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
|||||||
|
|
||||||
for (CodegenSecurity codegenSecurity : securities) {
|
for (CodegenSecurity codegenSecurity : securities) {
|
||||||
ExtendedCodegenSecurity extendedCodegenSecurity = new ExtendedCodegenSecurity(codegenSecurity);
|
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);
|
extendedSecurities.add(extendedCodegenSecurity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,32 +405,17 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
|||||||
public String tokenIntrospectUrl;
|
public String tokenIntrospectUrl;
|
||||||
|
|
||||||
public ExtendedCodegenSecurity(CodegenSecurity cm) {
|
public ExtendedCodegenSecurity(CodegenSecurity cm) {
|
||||||
super();
|
super(cm);
|
||||||
|
|
||||||
this.name = cm.name;
|
Object cmJwksUrl = cm.vendorExtensions.get(X_JWKS_URL);
|
||||||
this.type = cm.type;
|
if (cmJwksUrl instanceof String) {
|
||||||
this.scheme = cm.scheme;
|
this.jwksUrl = (String) cmJwksUrl;
|
||||||
this.isBasic = cm.isBasic;
|
}
|
||||||
this.isOAuth = cm.isOAuth;
|
|
||||||
this.isApiKey = cm.isApiKey;
|
Object cmTokenIntrospectUrl = cm.vendorExtensions.get(X_TOKEN_INTROSPECT_URL);
|
||||||
this.isBasicBasic = cm.isBasicBasic;
|
if (cmTokenIntrospectUrl instanceof String) {
|
||||||
this.isBasicBearer = cm.isBasicBearer;
|
this.tokenIntrospectUrl = (String) cmTokenIntrospectUrl;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user