io.swagger.parser.processors.PropertyProcessor Maven / Gradle / Ivy
package io.swagger.parser.processors;
import io.swagger.models.Swagger;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.RefProperty;
import io.swagger.parser.ResolverCache;
import static io.swagger.parser.util.RefUtils.isAnExternalRefFormat;
public class PropertyProcessor {
private final ExternalRefProcessor externalRefProcessor;
public PropertyProcessor(ResolverCache cache, Swagger swagger) {
externalRefProcessor = new ExternalRefProcessor(cache, swagger);
}
public void processProperty(Property property) {
if (property instanceof RefProperty) {
processRefProperty((RefProperty) property);
} else if (property instanceof ArrayProperty) {
processArrayProperty((ArrayProperty) property);
} else if (property instanceof MapProperty) {
processMapProperty((MapProperty) property);
}
}
private void processRefProperty(RefProperty refProperty) {
if (isAnExternalRefFormat(refProperty.getRefFormat())) {
final String newRef = externalRefProcessor.processRefToExternalDefinition(refProperty.get$ref(), refProperty.getRefFormat());
if (newRef != null) {
refProperty.set$ref(newRef);
}
}
}
private void processMapProperty(MapProperty property) {
final Property additionalProperties = property.getAdditionalProperties();
if (additionalProperties != null) {
processProperty(additionalProperties);
}
}
private void processArrayProperty(ArrayProperty property) {
final Property items = property.getItems();
if (items != null) {
processProperty(items);
}
}
}