1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const lodash_1 = require("lodash");
|
4 | const graph_1 = require("../../graph");
|
5 | const KNOWN_JSON_SCHEMA_TYPES = [
|
6 | 'any',
|
7 | 'array',
|
8 | 'boolean',
|
9 | 'integer',
|
10 | 'null',
|
11 | 'number',
|
12 | 'object',
|
13 | 'string',
|
14 | ];
|
15 | const JSON_SCHEMA_COMBINERS = ['allOf', 'oneOf', 'anyOf'];
|
16 | const predicates = [
|
17 | parsed => typeof parsed.$schema === 'string' && /json-schema/.test(parsed.$schema),
|
18 | parsed => {
|
19 | if (typeof parsed.type === 'string') {
|
20 | return KNOWN_JSON_SCHEMA_TYPES.includes(parsed.type);
|
21 | }
|
22 | else if (Array.isArray(parsed.type)) {
|
23 | return parsed.type.some(item => typeof item === 'string' && KNOWN_JSON_SCHEMA_TYPES.includes(item));
|
24 | }
|
25 | return '$ref' in parsed;
|
26 | },
|
27 | (parsed) => JSON_SCHEMA_COMBINERS.some(combiner => Array.isArray(parsed[combiner])),
|
28 | ];
|
29 | exports.isJsonSchema = (parsed) => lodash_1.isObject(parsed) && predicates.some(predicate => predicate(parsed));
|
30 | exports.createJsonSchemaPlugin = () => {
|
31 | return {
|
32 | tasks: [],
|
33 | specProvider: {
|
34 | spec: graph_1.Specs.Json_Schema,
|
35 | content: parsed => (exports.isJsonSchema(parsed) ? 1 : 0),
|
36 | },
|
37 | };
|
38 | };
|
39 |
|
\ | No newline at end of file |