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
|
|
|
|
2019-03-09 02:38:37 +03:00
|
|
|
import * as constants from "../lib/util/constants"
|
|
|
|
import * as validate from "../lib/validate"
|
|
|
|
|
2019-03-20 20:46:05 +03:00
|
|
|
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)
|
2018-11-16 04:04:07 +03:00
|
|
|
// console.dir(result, { depth: null })
|
2018-06-09 02:35:55 +03:00
|
|
|
assert(
|
2019-03-09 02:38:37 +03:00
|
|
|
result.validityStatus === true,
|
2019-03-20 03:14:21 +03:00
|
|
|
`swagger "${specPath}" contains semantic validation errors.`
|
2019-03-09 02:38:37 +03:00
|
|
|
)
|
2018-06-04 23:06:00 +03:00
|
|
|
})
|
2018-01-12 04:17:09 +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)
|
2018-11-16 04:04:07 +03:00
|
|
|
// console.dir(result, { depth: null })
|
2018-06-09 02:35:55 +03:00
|
|
|
assert(
|
2019-03-09 02:38:37 +03:00
|
|
|
result.validityStatus === true,
|
2019-03-20 03:14:21 +03:00
|
|
|
`swagger "${specPath}" contains semantic validation errors.`
|
2019-03-09 02:38:37 +03:00
|
|
|
)
|
2018-06-04 23:06:00 +03:00
|
|
|
})
|
2018-12-03 22:15:31 +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`
|
2018-12-03 22:15:31 +03:00
|
|
|
const result = await validate.validateSpec(specPath, undefined)
|
|
|
|
assert(result.validityStatus === false)
|
2019-03-09 02:38:37 +03:00
|
|
|
assert.strictEqual((result.resolveSpec as any).code, constants.ErrorCodes.JsonParsingError.name)
|
2018-12-03 22:15:31 +03:00
|
|
|
})
|
2018-06-04 23:06:00 +03:00
|
|
|
})
|