Skip to content
New issue

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

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

Already on GitHub? # to your account

Osztos a feature/java interface discriminator helper #12309

Merged
merged 3 commits into from
Dec 14, 2023
Merged
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 @@ -4,7 +4,6 @@
import io.swagger.v3.oas.models.media.Discriminator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -509,4 +508,26 @@ public boolean getIsComposedModel() {
public void setIsComposedModel(boolean isComposedModel) {
this.isComposedModel = isComposedModel;
}

/**
* Get the subtype name from the interface model
* @return name : the name assigned to the class by the discriminator mapping or classname if mapping not found
*/
public String getSubtypeName() {
if (getInterfaceModels()!=null) {
for (CodegenModel interfaceModel : getInterfaceModels()) {
if (interfaceModel.getDiscriminator() != null && interfaceModel.getDiscriminator().getMapping() != null) {
String subTypeName = interfaceModel.getDiscriminator().getMapping().get(classname);
if (subTypeName!=null) {
return subTypeName;
}
}
}
}
if (getParentModel()!=null && getParentModel().getDiscriminator()!=null && getParentModel().getDiscriminator().getMapping()!=null) {
String subTypeName = getParentModel().getDiscriminator().getMapping().get(classname);
return subTypeName!=null?subTypeName:name;
}
return name;
}
}
Loading