oav/test/semanticValidatorTests.ts

40 строки
1.6 KiB
TypeScript
Исходник Обычный вид История

2017-11-21 23:43:53 +03:00
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
2018-06-04 23:06:00 +03:00
/* tslint:disable:no-console */
import assert from "assert"
2019-01-09 02:03:51 +03:00
import * as constants from "../lib/util/constants"
import * as validate from "../lib/validate"
const testPath = __dirname
2018-06-04 23:06:00 +03:00
describe("Semantic validation", () => {
2018-06-09 02:35:55 +03:00
it("should validate correctly when the spec contains an x-ms-parameterized-host", async () => {
2019-01-09 02:03:51 +03:00
const specPath = `${testPath}/semanticValidation/specification/parameterizedhost/face.json`
2018-06-09 02:35:55 +03:00
const result = await validate.validateSpec(specPath, undefined)
// console.dir(result, { depth: null })
2018-06-09 02:35:55 +03:00
assert(
result.validityStatus === true,
`swagger "${specPath}" contains semantic validation errors.`
)
2018-06-04 23:06:00 +03:00
})
2018-06-09 02:35:55 +03:00
it("should validate correctly when the spec does not contain a definitions section", async () => {
2019-01-09 02:03:51 +03:00
const specPath = `${testPath}/semanticValidation/specification/definitions/definitions.json`
2018-06-09 02:35:55 +03:00
const result = await validate.validateSpec(specPath, undefined)
// console.dir(result, { depth: null })
2018-06-09 02:35:55 +03:00
assert(
result.validityStatus === true,
`swagger "${specPath}" contains semantic validation errors.`
)
2018-06-04 23:06:00 +03:00
})
it("should fail when validating a swagger with JSON errors", async () => {
2019-01-09 02:03:51 +03:00
const specPath = `${testPath}/semanticValidation/specification/invalid/invalid.json`
const result = await validate.validateSpec(specPath, undefined)
assert(result.validityStatus === false)
assert.strictEqual((result.resolveSpec as any).code, constants.ErrorCodes.JsonParsingError.name)
})
2018-06-04 23:06:00 +03:00
})