yaml-language-server
Version:
43 lines • 1.97 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "../parser/yamlParser07", "../parser/jsonDocument"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDollarSchema = getDollarSchema;
const yamlParser07_1 = require("../parser/yamlParser07");
const jsonDocument_1 = require("../parser/jsonDocument");
/**
* Retrieve schema if declared by `$schema`.
* Public for testing purpose, not part of the API.
* @param doc
*/
function getDollarSchema(doc) {
if ((doc instanceof yamlParser07_1.SingleYAMLDocument || doc instanceof jsonDocument_1.JSONDocument) && doc.root?.type === 'object') {
let dollarSchema = undefined;
for (const property of doc.root.properties) {
if (property.keyNode?.value === '$schema' && typeof property.valueNode?.value === 'string') {
dollarSchema = property.valueNode?.value;
break;
}
}
if (typeof dollarSchema === 'string') {
return dollarSchema;
}
if (dollarSchema) {
console.log('The $schema attribute is not a string, and will be ignored');
}
}
return undefined;
}
});
//# sourceMappingURL=dollarUtils.js.map