-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic support for declaring schema with inline
$schema
- Loading branch information
Showing
2 changed files
with
64 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { SingleYAMLDocument } from '../parser/yamlParser07'; | ||
import { JSONDocument } from '../parser/jsonParser07'; | ||
|
||
/** | ||
* Retrieve schema if declared by `$schema`. | ||
* Public for testing purpose, not part of the API. | ||
* @param doc | ||
*/ | ||
export function getDollarSchema(doc: SingleYAMLDocument | JSONDocument): string | undefined { | ||
if (doc instanceof SingleYAMLDocument && doc.root.type === 'object') { | ||
let dollarSchema = doc.root.properties['$schema']; | ||
dollarSchema = typeof dollarSchema === 'string' ? dollarSchema.trim() : undefined; | ||
if (typeof dollarSchema === 'string') { | ||
return dollarSchema.trim(); | ||
} | ||
if (dollarSchema) { | ||
console.log('The $schema attribute is not a string, and will be ignored'); | ||
} | ||
} | ||
return undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters