UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const lodash_1 = require("lodash");
4const graph_1 = require("../../graph");
5const KNOWN_JSON_SCHEMA_TYPES = [
6 'any',
7 'array',
8 'boolean',
9 'integer',
10 'null',
11 'number',
12 'object',
13 'string',
14];
15const JSON_SCHEMA_COMBINERS = ['allOf', 'oneOf', 'anyOf'];
16const 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];
29exports.isJsonSchema = (parsed) => lodash_1.isObject(parsed) && predicates.some(predicate => predicate(parsed));
30exports.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//# sourceMappingURL=index.js.map
\No newline at end of file