forked from redhat-developer/yaml-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemaUrls.ts
More file actions
71 lines (65 loc) · 2.22 KB
/
schemaUrls.ts
File metadata and controls
71 lines (65 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { WorkspaceFolder } from 'vscode-languageserver-protocol';
import { URI } from 'vscode-uri';
import { Telemetry } from '../telemetry';
import { JSONSchema, JSONSchemaRef } from '../jsonSchema';
import { isBoolean } from './objects';
import { isRelativePath, relativeToAbsolutePath } from './paths';
export const BASE_KUBERNETES_SCHEMA_URL =
'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.32.1-standalone-strict/';
export const KUBERNETES_SCHEMA_URL = BASE_KUBERNETES_SCHEMA_URL + 'all.json';
export const JSON_SCHEMASTORE_URL = 'https://www.schemastore.org/api/json/catalog.json';
export const CRD_CATALOG_URL = 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main';
export function checkSchemaURI(
workspaceFolders: WorkspaceFolder[],
workspaceRoot: URI,
uri: string,
telemetry: Telemetry
): string {
if (uri.trim().toLowerCase() === 'kubernetes') {
telemetry.send({ name: 'yaml.schema.configured', properties: { kubernetes: true } });
return KUBERNETES_SCHEMA_URL;
} else if (isRelativePath(uri)) {
return relativeToAbsolutePath(workspaceFolders, workspaceRoot, uri);
} else {
return uri;
}
}
/**
* Collect all urls of sub schemas
* @param schema the root schema
* @returns map url to schema
*/
export function getSchemaUrls(schema: JSONSchema): Map<string, JSONSchema> {
const result = new Map<string, JSONSchema>();
if (!schema) {
return result;
}
if (schema.url) {
if (schema.url.startsWith('schemaservice://combinedSchema/')) {
addSchemasForOf(schema, result);
} else {
result.set(schema.url, schema);
}
} else {
addSchemasForOf(schema, result);
}
return result;
}
function addSchemasForOf(schema: JSONSchema, result: Map<string, JSONSchema>): void {
if (schema.allOf) {
addInnerSchemaUrls(schema.allOf, result);
}
if (schema.anyOf) {
addInnerSchemaUrls(schema.anyOf, result);
}
if (schema.oneOf) {
addInnerSchemaUrls(schema.oneOf, result);
}
}
function addInnerSchemaUrls(schemas: JSONSchemaRef[], result: Map<string, JSONSchema>): void {
for (const subSchema of schemas) {
if (!isBoolean(subSchema) && subSchema.url && !result.has(subSchema.url)) {
result.set(subSchema.url, subSchema);
}
}
}