com.commercetools.rmf.validators.ResourcesValidator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ctp-validators Show documentation
Show all versions of ctp-validators Show documentation
RAML API client code generators based on the REST Modeling Framework. https://github.com/vrapio/rest-modeling-framework
package com.commercetools.rmf.validators
import io.vrap.rmf.raml.model.resources.util.ResourcesSwitch
import io.vrap.rmf.raml.model.types.AnnotationsFacet
import io.vrap.rmf.raml.model.types.ArrayInstance
import io.vrap.rmf.raml.validation.AbstractRamlValidator
import io.vrap.rmf.raml.validation.RamlValidator
import org.eclipse.emf.common.util.Diagnostic
import org.eclipse.emf.common.util.DiagnosticChain
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EObject
import java.util.function.Consumer
import java.util.stream.Collectors
class ResourcesValidator(private val validators: List>> = emptyList()) : AbstractRamlValidator(), RamlValidator {
override fun validate(
eClass: EClass,
eObject: EObject,
diagnostics: DiagnosticChain,
context: Map
): Boolean {
val validationResults = validators.stream()
.flatMap { validator: ResourcesSwitch> ->
return@flatMap if (eObject is AnnotationsFacet && eObject.getAnnotation("ignoreValidators") != null && (eObject.getAnnotation("ignoreValidators").value as ArrayInstance).value.any { it.value == validator.javaClass.simpleName } ) {
emptyList().stream()
} else {
validator.doSwitch(eObject).stream()
}
}
.collect(Collectors.toList())
validationResults.forEach(Consumer { diagnostic: Diagnostic? -> diagnostics.add(diagnostic) })
return validationResults.isEmpty()
}
}