Skip to content

Commit

Permalink
mitigated a bug (#13786)
Browse files Browse the repository at this point in the history
  • Loading branch information
devhl-labs authored Nov 20, 2022
1 parent 9039c83 commit 8e98bff
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,15 @@ public ModelsMap postProcessModels(ModelsMap objs) {
@Override
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
final Map<String, ModelsMap> processed = super.postProcessAllModels(objs);

// TODO: move the logic of these three methods into patchProperty so all CodegenProperty instances get the same treatment
postProcessEnumRefs(processed);
updateValueTypeProperty(processed);
updateNullableTypeProperty(processed);

for (Map.Entry<String, ModelsMap> entry : objs.entrySet()) {
CodegenModel model = ModelUtils.getModelByName(entry.getKey(), objs);
removeCircularReferencesInComposedSchemas(model);

// https://github.com/OpenAPITools/openapi-generator/issues/12324
// TODO: why do these collections contain different instances?
Expand Down Expand Up @@ -534,6 +537,31 @@ private void patchProperty(CodegenModel model, CodegenProperty property){
}
}

/** Mitigates https://github.com/OpenAPITools/openapi-generator/issues/13709 */
private void removeCircularReferencesInComposedSchemas(CodegenModel cm) {
cm.anyOf.removeIf(anyOf -> anyOf.equals(cm.classname));
cm.oneOf.removeIf(oneOf -> oneOf.equals(cm.classname));
cm.allOf.removeIf(allOf -> allOf.equals(cm.classname));

CodegenComposedSchemas composedSchemas = cm.getComposedSchemas();
if (composedSchemas != null){
List<CodegenProperty> anyOf = composedSchemas.getAnyOf();
if (anyOf != null) {
anyOf.removeIf(p -> p.dataType.equals(cm.classname));
}

List<CodegenProperty> oneOf = composedSchemas.getOneOf();
if (oneOf != null){
oneOf.removeIf(p -> p.dataType.equals(cm.classname));
}

List<CodegenProperty> allOf = composedSchemas.getAllOf();
if (allOf != null){
allOf.removeIf(p -> p.dataType.equals(cm.classname));
}
}
}

@Override
protected List<Map<String, Object>> buildEnumVars(List<Object> values, String dataType) {
List<Map<String, Object>> enumVars = super.buildEnumVars(values, dataType);
Expand Down

0 comments on commit 8e98bff

Please sign in to comment.