Skip to content

[csharp][default] Fix handling of nested inheritance properties #8875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -3017,6 +3017,11 @@ protected void addProperties(Map<String, Schema> properties, List<String> requir
required.addAll(schema.getRequired());
}

// Composed Schemas may have properties defined on themselves as well in case of nested inheritance this is rather important
if (schema.getProperties() != null) {
properties.putAll(schema.getProperties());
}

if (composedSchema.getOneOf() != null) {
for (Schema component : composedSchema.getOneOf()) {
addProperties(properties, required, component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,11 @@ public CodegenModel fromModel(String name, Schema model) {
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
CodegenModel codegenModel = super.fromModel(name, 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);
Schema currentParentModel = allDefinitions.get(codegenModel.parentSchema);
// We need to iterate through the whole inheritance structure and check whether we need to inherit properties
while (currentParentModel != null) {
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, currentParentModel);

if (codegenModel.hasEnums) {
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
}
Expand All @@ -610,6 +612,8 @@ public CodegenModel fromModel(String name, Schema model) {
}

CodegenProperty last = null;

// Add properties of parent to child if child does not contain the same property (which overrides)
for (final CodegenProperty property : parentCodegenModel.vars) {
// helper list of parentVars simplifies templating
if (!propertyHash.containsKey(property.name)) {
Expand All @@ -620,6 +624,9 @@ public CodegenModel fromModel(String name, Schema model) {
codegenModel.parentVars.add(parentVar);
}
}

// Find parent of current parent if it exists. In inheritance its important to take the whole tree into account
currentParentModel = allDefinitions.get(parentCodegenModel.parentSchema);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,12 @@ public CodegenModel fromModel(String name, Schema model) {
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
CodegenModel codegenModel = super.fromModel(name, 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);
Schema currentParentModel = allDefinitions.get(codegenModel.parentSchema);
// We need to iterate through the whole inheritance structure and check whether we need to inherit properties
while (currentParentModel != null) {
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, currentParentModel);


if (codegenModel.hasEnums) {
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
}
Expand All @@ -356,6 +359,9 @@ public CodegenModel fromModel(String name, Schema model) {
codegenModel.parentVars.add(parentVar);
}
}

// Find parent of current parent if it exists. In inheritance its important to take the whole tree into account
currentParentModel = allDefinitions.get(parentCodegenModel.parentSchema);
}
}

Expand Down