Search in sources :

Example 1 with PositionInfo

use of com.reprezen.jsonoverlay.PositionInfo in project KaiZen-OpenAPI-Editor by RepreZen.

the class OpenApi3Validator method validate.

@Override
public Set<SwaggerError> validate(JsonDocument document, URI baseURI) {
    final Set<SwaggerError> errors = super.validate(document, baseURI);
    final long nbOfErrors = errors.stream().filter(e -> e.getLevel() == SEVERITY_ERROR).count();
    // and option in UI is enable.
    if (isAdvancedValidation() && nbOfErrors == 0) {
        try {
            OpenApi3 result = new OpenApi3Parser().parse(document.get(), baseURI.toURL(), true);
            for (ValidationItem item : result.getValidationResults().getItems()) {
                PositionInfo pos = item.getPositionInfo();
                int line = pos != null ? pos.getLine() : 1;
                errors.add(new SwaggerError(line, getSeverity(item.getSeverity()), item.getMsg()));
            }
        } catch (Exception e) {
            Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage()));
        }
    }
    return errors;
}
Also used : Arrays(java.util.Arrays) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) JsonDocument(com.reprezen.swagedit.core.editor.JsonDocument) OpenApi3(com.reprezen.kaizen.oasparser.model3.OpenApi3) Model(com.reprezen.swagedit.core.model.Model) OpenApi3Schema(com.reprezen.swagedit.openapi3.schema.OpenApi3Schema) ValidationItem(com.reprezen.kaizen.oasparser.val.ValidationResults.ValidationItem) ArrayList(java.util.ArrayList) ArrayNode(com.reprezen.swagedit.core.model.ArrayNode) JsonPointer(com.fasterxml.jackson.core.JsonPointer) PositionInfo(com.reprezen.jsonoverlay.PositionInfo) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) IMarker(org.eclipse.core.resources.IMarker) OpenApi3Parser(com.reprezen.kaizen.oasparser.OpenApi3Parser) Iterator(java.util.Iterator) JsonReferenceValidator(com.reprezen.swagedit.core.json.references.JsonReferenceValidator) Severity(com.reprezen.kaizen.oasparser.val.ValidationResults.Severity) Activator(com.reprezen.swagedit.openapi3.Activator) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) Objects(java.util.Objects) List(java.util.List) Messages(com.reprezen.swagedit.core.validation.Messages) Validator(com.reprezen.swagedit.core.validation.Validator) ADVANCED_VALIDATION(com.reprezen.swagedit.openapi3.preferences.OpenApi3PreferenceConstants.ADVANCED_VALIDATION) SwaggerError(com.reprezen.swagedit.core.validation.SwaggerError) JsonSchemaValidator(com.reprezen.swagedit.core.validation.JsonSchemaValidator) SEVERITY_ERROR(org.eclipse.core.resources.IMarker.SEVERITY_ERROR) Status(org.eclipse.core.runtime.Status) SwaggerError(com.reprezen.swagedit.core.validation.SwaggerError) PositionInfo(com.reprezen.jsonoverlay.PositionInfo) ValidationItem(com.reprezen.kaizen.oasparser.val.ValidationResults.ValidationItem) OpenApi3Parser(com.reprezen.kaizen.oasparser.OpenApi3Parser) OpenApi3(com.reprezen.kaizen.oasparser.model3.OpenApi3)

Aggregations

JsonPointer (com.fasterxml.jackson.core.JsonPointer)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 PositionInfo (com.reprezen.jsonoverlay.PositionInfo)1 OpenApi3Parser (com.reprezen.kaizen.oasparser.OpenApi3Parser)1 OpenApi3 (com.reprezen.kaizen.oasparser.model3.OpenApi3)1 Severity (com.reprezen.kaizen.oasparser.val.ValidationResults.Severity)1 ValidationItem (com.reprezen.kaizen.oasparser.val.ValidationResults.ValidationItem)1 JsonDocument (com.reprezen.swagedit.core.editor.JsonDocument)1 JsonReferenceValidator (com.reprezen.swagedit.core.json.references.JsonReferenceValidator)1 AbstractNode (com.reprezen.swagedit.core.model.AbstractNode)1 ArrayNode (com.reprezen.swagedit.core.model.ArrayNode)1 Model (com.reprezen.swagedit.core.model.Model)1 JsonSchemaValidator (com.reprezen.swagedit.core.validation.JsonSchemaValidator)1 Messages (com.reprezen.swagedit.core.validation.Messages)1 SwaggerError (com.reprezen.swagedit.core.validation.SwaggerError)1 Validator (com.reprezen.swagedit.core.validation.Validator)1 Activator (com.reprezen.swagedit.openapi3.Activator)1 ADVANCED_VALIDATION (com.reprezen.swagedit.openapi3.preferences.OpenApi3PreferenceConstants.ADVANCED_VALIDATION)1 OpenApi3Schema (com.reprezen.swagedit.openapi3.schema.OpenApi3Schema)1 URI (java.net.URI)1