Search in sources :

Example 1 with IValidationSeverityRegistry

use of io.apicurio.datamodels.core.validation.IValidationSeverityRegistry in project apicurio-data-models by Apicurio.

the class Library method validateDocument.

/**
 * Called to validate a data model node.  All validation rules will be evaluated and reported.  The list
 * of validation problems found during validation is returned.  In addition, validation problems will be
 * reported on the individual nodes themselves.  Validation problem severity is determined by checking
 * with the included severity registry.  If the severity registry is null, a default registry is used.
 * Custom validators can be passed to provide additional validation rules beyond what this Library offers out of the box.
 *
 * @param node The document to be validated
 * @param severityRegistry Supply a custom severity registry. If nothing is passed, the default severity registry will be used
 * @param extensions Supply an optional list of validation extensions, enabling the use of 3rd-party validators or custom validation rules
 * @return full list of the validation problems found in the document
 */
public static CompletableFuture<List<ValidationProblem>> validateDocument(Node node, IValidationSeverityRegistry severityRegistry, List<IDocumentValidatorExtension> extensions) {
    List<ValidationProblem> totalValidationProblems = Library.validate(node, severityRegistry);
    if (extensions != null && !extensions.isEmpty()) {
        for (IDocumentValidatorExtension extension : extensions) {
            CompletableFuture<List<ValidationProblem>> extensionValidationProblems = extension.validateDocument(node);
            extensionValidationProblems.thenAccept(problems -> problems.forEach(p -> {
                totalValidationProblems.add(p);
                node.ownerDocument().addValidationProblem(p.errorCode, p.nodePath, p.property, p.message, p.severity);
            }));
        }
    }
    return CompletableFuture.completedFuture(totalValidationProblems);
}
Also used : IDocumentValidatorExtension(io.apicurio.datamodels.core.validation.IDocumentValidatorExtension) IVisitor(io.apicurio.datamodels.core.visitors.IVisitor) Dereferencer(io.apicurio.datamodels.openapi.visitors.dereference.Dereferencer) DefaultSeverityRegistry(io.apicurio.datamodels.core.validation.DefaultSeverityRegistry) IReferenceResolver(io.apicurio.datamodels.core.util.IReferenceResolver) CompletableFuture(java.util.concurrent.CompletableFuture) NodePathUtil(io.apicurio.datamodels.core.util.NodePathUtil) Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) DocumentType(io.apicurio.datamodels.core.models.DocumentType) Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) DataModelReader(io.apicurio.datamodels.core.io.DataModelReader) IDocumentValidatorExtension(io.apicurio.datamodels.core.validation.IDocumentValidatorExtension) TraverserDirection(io.apicurio.datamodels.core.visitors.TraverserDirection) IValidationSeverityRegistry(io.apicurio.datamodels.core.validation.IValidationSeverityRegistry) ValidationProblemsResetVisitor(io.apicurio.datamodels.core.validation.ValidationProblemsResetVisitor) VisitorFactory(io.apicurio.datamodels.core.factories.VisitorFactory) Document(io.apicurio.datamodels.core.models.Document) VisitorUtil(io.apicurio.datamodels.core.util.VisitorUtil) NodePath(io.apicurio.datamodels.core.models.NodePath) DataModelWriter(io.apicurio.datamodels.core.io.DataModelWriter) JsonCompat(io.apicurio.datamodels.compat.JsonCompat) Node(io.apicurio.datamodels.core.models.Node) ValidationProblem(io.apicurio.datamodels.core.models.ValidationProblem) Oas20to30TransformationVisitor(io.apicurio.datamodels.openapi.visitors.transform.Oas20to30TransformationVisitor) List(java.util.List) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation) ReferenceResolverChain(io.apicurio.datamodels.core.util.ReferenceResolverChain) DataModelReaderDispatcher(io.apicurio.datamodels.core.io.DataModelReaderDispatcher) ValidationVisitor(io.apicurio.datamodels.core.validation.ValidationVisitor) DocumentFactory(io.apicurio.datamodels.core.factories.DocumentFactory) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Constants(io.apicurio.datamodels.core.Constants) ValidationProblem(io.apicurio.datamodels.core.models.ValidationProblem) List(java.util.List)

Aggregations

Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)1 JsonCompat (io.apicurio.datamodels.compat.JsonCompat)1 Constants (io.apicurio.datamodels.core.Constants)1 DocumentFactory (io.apicurio.datamodels.core.factories.DocumentFactory)1 VisitorFactory (io.apicurio.datamodels.core.factories.VisitorFactory)1 DataModelReader (io.apicurio.datamodels.core.io.DataModelReader)1 DataModelReaderDispatcher (io.apicurio.datamodels.core.io.DataModelReaderDispatcher)1 DataModelWriter (io.apicurio.datamodels.core.io.DataModelWriter)1 Document (io.apicurio.datamodels.core.models.Document)1 DocumentType (io.apicurio.datamodels.core.models.DocumentType)1 Node (io.apicurio.datamodels.core.models.Node)1 NodePath (io.apicurio.datamodels.core.models.NodePath)1 ValidationProblem (io.apicurio.datamodels.core.models.ValidationProblem)1 IReferenceResolver (io.apicurio.datamodels.core.util.IReferenceResolver)1 NodePathUtil (io.apicurio.datamodels.core.util.NodePathUtil)1 ReferenceResolverChain (io.apicurio.datamodels.core.util.ReferenceResolverChain)1 VisitorUtil (io.apicurio.datamodels.core.util.VisitorUtil)1 DefaultSeverityRegistry (io.apicurio.datamodels.core.validation.DefaultSeverityRegistry)1 IDocumentValidatorExtension (io.apicurio.datamodels.core.validation.IDocumentValidatorExtension)1 IValidationSeverityRegistry (io.apicurio.datamodels.core.validation.IValidationSeverityRegistry)1