From b41b253b1b76dce8a211c54c85aed67b4dcfa07a Mon Sep 17 00:00:00 2001 From: Veronica Giaudrone Date: Fri, 21 Sep 2018 16:42:46 -0700 Subject: [PATCH] Fix semantic result in validate spec instead of editing afterwards (#318) * Adding reference documentation for oav model validation * correcting where url and position get added in the error result * adding changelog and updating oav version --- ChangeLog.md | 4 ++++ lib/util/commonError.ts | 4 ++++ lib/util/validationResponse.ts | 9 +++++++++ lib/validate.ts | 4 ---- lib/validators/semanticValidator.ts | 3 +++ package-lock.json | 8 ++++---- package.json | 2 +- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index eae7d9cf..7d2b5791 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # Changelog +### 09/21/2018 0.5.13 + +- Correcting where we add url and position information to semantic validation errors. + ### 09/19/2018 0.5.12 - Adding url and position to source where issue occurs for semantic validation errors. diff --git a/lib/util/commonError.ts b/lib/util/commonError.ts index d29f2259..99b2beed 100644 --- a/lib/util/commonError.ts +++ b/lib/util/commonError.ts @@ -1,3 +1,5 @@ +import { FilePosition } from '@ts-common/source-map'; + // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -12,4 +14,6 @@ export interface CommonError { in?: unknown name?: string params?: Array + jsonUrl?: string + jsonPosition?: FilePosition } diff --git a/lib/util/validationResponse.ts b/lib/util/validationResponse.ts index 9083bab4..54ad6ce9 100644 --- a/lib/util/validationResponse.ts +++ b/lib/util/validationResponse.ts @@ -4,6 +4,7 @@ import * as pointer from "json-pointer" import { CommonError } from "./commonError" import { StringMap } from "@ts-common/string-map" +import { FilePosition } from "@ts-common/source-map" interface ValidationError { validationCategory: string @@ -15,6 +16,8 @@ interface ValidationError { message?: string jsonref?: string "json-path"?: string + jsonUrl?: string + jsonPosition?: FilePosition } interface Warning { @@ -71,6 +74,12 @@ export class ValidateResponse { e.jsonref = jsonpath e["json-path"] = pointer.unescape(jsonpath) } + if (error.jsonUrl && error.jsonUrl.length) { + e.jsonUrl = error.jsonUrl + } + if (error.jsonPosition) { + e.jsonPosition = error.jsonPosition + } return e }) } diff --git a/lib/validate.ts b/lib/validate.ts index e4c76cd8..f03b45a3 100644 --- a/lib/validate.ts +++ b/lib/validate.ts @@ -18,7 +18,6 @@ import { getErrorsFromModelValidation } from "./util/getErrorsFromModelValidatio import { SemanticValidator } from "./validators/semanticValidator" import { ModelValidator } from "./validators/modelValidator" import { MutableStringMap, StringMap } from "@ts-common/string-map" -import { errorsAddFileInfo } from "./util/errorFileInfo" type FinalValidationResult = MutableStringMap @@ -106,11 +105,8 @@ export async function validateSpec( await validator.initialize() log.info(`Semantically validating ${specPath}:\n`) const validationResults = await validator.validateSpec() - errorsAddFileInfo(validationResults.errors) - errorsAddFileInfo(validationResults.warnings) updateEndResultOfSingleValidation(validator) logDetailedInfo(validator) - logDetailedInfo(validator) if (o.pretty) { /* tslint:disable-next-line:no-console no-string-literal */ console.log(`Semantically validating ${specPath}:\n`) diff --git a/lib/validators/semanticValidator.ts b/lib/validators/semanticValidator.ts index d90b5b34..743a4a23 100644 --- a/lib/validators/semanticValidator.ts +++ b/lib/validators/semanticValidator.ts @@ -10,6 +10,7 @@ import * as C from "../util/constants" import * as util from "util" import { CommonError } from "../util/commonError" import { keys } from "@ts-common/string-map" +import { errorsAddFileInfo } from '../util/errorFileInfo'; export interface Result { isValid?: unknown @@ -48,6 +49,7 @@ export class SemanticValidator extends SpecValidator { if (validationResult) { if (validationResult.errors && validationResult.errors.length) { this.specValidationResult.validateSpec.isValid = false + errorsAddFileInfo(validationResult.errors) const e = this.constructErrorObject( ErrorCodes.SemanticValidationError, `The spec ${this.specPath} has semantic validation errors.`, @@ -63,6 +65,7 @@ export class SemanticValidator extends SpecValidator { `The spec ${this.specPath} is semantically valid.` } if (validationResult.warnings && validationResult.warnings.length > 0) { + errorsAddFileInfo(validationResult.warnings) const warnings = validateResponse.sanitizeWarnings(validationResult.warnings) if (warnings && warnings.length) { this.specValidationResult.validateSpec.warnings = warnings diff --git a/package-lock.json b/package-lock.json index d14f827e..b39d232d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "oav", - "version": "0.5.12", + "version": "0.5.13", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -247,7 +247,7 @@ "dependencies": { "acorn": { "version": "3.3.0", - "resolved": "http://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=" } } @@ -973,7 +973,7 @@ }, "eslint": { "version": "4.19.1", - "resolved": "http://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz", "integrity": "sha512-bT3/1x1EbZB7phzYu7vCr1v3ONuzDtX8WjuM9c0iYxe+cq+pwcKEoQjl7zd3RpC6YOLgnSy3cTN58M2jcoPDIQ==", "requires": { "ajv": "^5.3.0", @@ -1131,7 +1131,7 @@ }, "external-editor": { "version": "2.2.0", - "resolved": "http://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==", "requires": { "chardet": "^0.4.0", diff --git a/package.json b/package.json index f8835ee4..3b035911 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oav", - "version": "0.5.12", + "version": "0.5.13", "author": { "name": "Microsoft Corporation", "email": "azsdkteam@microsoft.com",