Skip to content
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 @@ -116,6 +116,9 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
// A cache to efficiently lookup schema `toModelName()` based on the schema Key
private final Map<String, String> schemaKeyToModelNameCache = new HashMap<>();

// A cache to efficiently lookup CodegenModel `fromModel(codegenModelName, parentModelSchema)` based on the pair of model name and schema
private final Map<Map.Entry<String, Schema>, CodegenModel> codegenModelNameAndSchemaKeyToCodegenModelCache = new HashMap<>();

public AbstractCSharpCodegen() {
super();

Expand Down Expand Up @@ -1703,6 +1706,17 @@ public String toModelTestFilename(String name) {
return toModelName(name) + "Tests";
}

protected CodegenModel getCodegenModel(String codegenModelName, Schema schema){
var key = new AbstractMap.SimpleEntry<>(codegenModelName, schema);
if(codegenModelNameAndSchemaKeyToCodegenModelCache.containsKey(key)){
return codegenModelNameAndSchemaKeyToCodegenModelCache.get(key);
}

CodegenModel model = super.fromModel(codegenModelName, schema);
codegenModelNameAndSchemaKeyToCodegenModelCache.put(key, model);
return model;
}

public void setNullableReferenceTypes(final Boolean nullReferenceTypesFlag) {
this.nullReferenceTypesFlag = nullReferenceTypesFlag;
additionalProperties.put("nullableReferenceTypes", nullReferenceTypesFlag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public CodegenModel fromModel(String name, Schema model) {
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
final Schema<?> parentModel = allDefinitions.get(toModelName(codegenModel.parent));
if (parentModel != null) {
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
final CodegenModel parentCodegenModel = getCodegenModel(codegenModel.parent, parentModel);
if (codegenModel.hasEnums) {
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public CodegenModel fromModel(String name, Schema model) {
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null) {
final Schema parentModel = allDefinitions.get(toModelName(codegenModel.parent));
if (parentModel != null) {
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
final CodegenModel parentCodegenModel = getCodegenModel(codegenModel.parent, parentModel);
if (codegenModel.hasEnums) {
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
}
Expand Down
Loading