forked from loafle/openapi-generator-original
Fix hasMore field and order consistency of authMethods (#5516)
The hasMore field of the global authMethods was broken due to sorting after setting that field. The sort order for per-operation authMethods was not guaranteed to be consistent across runs because it didn't do sorting. This change fixes those issues by always sorting and setting the hasMore field post-sort.
This commit is contained in:
parent
1a25b308cc
commit
c2a1720972
@ -48,6 +48,7 @@ import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
import io.swagger.models.properties.UUIDProperty;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
@ -2689,9 +2690,23 @@ public class DefaultCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
sec.hasMore = it.hasNext();
|
||||
secs.add(sec);
|
||||
}
|
||||
|
||||
// sort auth methods to maintain the same order
|
||||
Collections.sort(secs, new Comparator<CodegenSecurity>() {
|
||||
@Override
|
||||
public int compare(CodegenSecurity one, CodegenSecurity another) {
|
||||
return ObjectUtils.compare(one.name, another.name);
|
||||
}
|
||||
});
|
||||
// set 'hasMore'
|
||||
Iterator<CodegenSecurity> it = secs.iterator();
|
||||
while (it.hasNext()) {
|
||||
final CodegenSecurity security = it.next();
|
||||
security.hasMore = it.hasNext();
|
||||
}
|
||||
|
||||
return secs;
|
||||
}
|
||||
|
||||
|
@ -625,13 +625,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
bundle.put("modelPackage", config.modelPackage());
|
||||
List<CodegenSecurity> authMethods = config.fromSecurity(swagger.getSecurityDefinitions());
|
||||
if (authMethods != null && !authMethods.isEmpty()) {
|
||||
// sort auth methods to maintain the same order
|
||||
Collections.sort(authMethods, new Comparator<CodegenSecurity>() {
|
||||
@Override
|
||||
public int compare(CodegenSecurity one, CodegenSecurity another) {
|
||||
return ObjectUtils.compare(one.name, another.name);
|
||||
}
|
||||
});
|
||||
bundle.put("authMethods", authMethods);
|
||||
bundle.put("hasAuthMethods", true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user