All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.commercetools.rmf.validators.ModulesValidator.kt Maven / Gradle / Ivy

Go to download

RAML API client code generators based on the REST Modeling Framework. https://github.com/vrapio/rest-modeling-framework

There is a newer version: 1.0.0-20241120142200
Show newest version
package com.commercetools.rmf.validators

import io.vrap.rmf.raml.model.modules.util.ModulesSwitch
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 ModulesValidator(private val validators: List>> = emptyList()) : AbstractRamlValidator(), RamlValidator {
    override fun validate(
        eClass: EClass?,
        eObject: EObject?,
        diagnostics: DiagnosticChain,
        context: MutableMap?
    ): Boolean {
        val validationResults = validators.stream()
            .flatMap { validator: ModulesSwitch> ->
                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()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy