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
This commit is contained in:
Родитель
b6dab0f577
Коммит
b41b253b1b
|
@ -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.
|
||||
|
|
|
@ -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<unknown>
|
||||
jsonUrl?: string
|
||||
jsonPosition?: FilePosition
|
||||
}
|
||||
|
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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<unknown>
|
||||
|
||||
|
@ -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`)
|
||||
|
|
|
@ -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<SemanticValidationResult> {
|
|||
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<SemanticValidationResult> {
|
|||
`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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oav",
|
||||
"version": "0.5.12",
|
||||
"version": "0.5.13",
|
||||
"author": {
|
||||
"name": "Microsoft Corporation",
|
||||
"email": "azsdkteam@microsoft.com",
|
||||
|
|
Загрузка…
Ссылка в новой задаче