yaml-language-server
Version:
33 lines • 1.46 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.
*--------------------------------------------------------------------------------------------*/
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