use of io.swagger.v3.parser.util.RefUtils.computeDefinitionName in project swagger-parser by swagger-api.
the class SchemaProcessor method changeDiscriminatorMapping.
private void changeDiscriminatorMapping(ComposedSchema composedSchema, String oldRef, String newRef) {
Discriminator discriminator = composedSchema.getDiscriminator();
if (!oldRef.equals(newRef) && discriminator != null) {
String oldName = RefUtils.computeDefinitionName(oldRef);
String newName = RefUtils.computeDefinitionName(newRef);
String mappingName = null;
if (discriminator.getMapping() != null) {
for (String name : discriminator.getMapping().keySet()) {
if (oldRef.equals(discriminator.getMapping().get(name))) {
mappingName = name;
break;
}
}
if (mappingName != null) {
discriminator.getMapping().put(mappingName, newRef);
}
}
if (mappingName == null && !oldName.equals(newName)) {
if (discriminator.getMapping() == null) {
discriminator.setMapping(new HashMap());
}
discriminator.getMapping().put(oldName, newRef);
}
}
}
Aggregations