1 | import FailsafeSchema from "../failsafe/index.mjs";
|
---|
2 | import BooleanTag from "./Boolean.mjs";
|
---|
3 | import FloatingPointTag from "./FloatingPoint.mjs";
|
---|
4 | import IntegerTag from "./Integer.mjs";
|
---|
5 | import NullTag from "./Null.mjs";
|
---|
6 | import { YamlNodeKind } from "../../nodes/YamlTag.mjs";
|
---|
7 | import GenericSequence from "../failsafe/GenericSequence.mjs";
|
---|
8 | import GenericMapping from "../failsafe/GenericMapping.mjs";
|
---|
9 | class JsonSchema extends FailsafeSchema {
|
---|
10 | constructor() {
|
---|
11 | super();
|
---|
12 | /**
|
---|
13 | * We're registering more specific tags before more generic ones from Failsafe schema.
|
---|
14 | */
|
---|
15 | this.registerTag(new BooleanTag(), true);
|
---|
16 | this.registerTag(new FloatingPointTag(), true);
|
---|
17 | this.registerTag(new IntegerTag(), true);
|
---|
18 | this.registerTag(new NullTag(), true);
|
---|
19 | }
|
---|
20 | toSpecificTagName(node) {
|
---|
21 | let specificTagName = super.toSpecificTagName(node);
|
---|
22 | if (specificTagName === '?') {
|
---|
23 | if (node.tag.vkind === YamlNodeKind.Sequence) {
|
---|
24 | specificTagName = GenericSequence.uri;
|
---|
25 | } else if (node.tag.kind === YamlNodeKind.Mapping) {
|
---|
26 | specificTagName = GenericMapping.uri;
|
---|
27 | } else if (node.tag.kind === YamlNodeKind.Scalar) {
|
---|
28 | const foundTag = this.tags.find(tag => tag.test(node));
|
---|
29 | specificTagName = (foundTag === null || foundTag === void 0 ? void 0 : foundTag.tag) || '?';
|
---|
30 | }
|
---|
31 | }
|
---|
32 | return specificTagName;
|
---|
33 | }
|
---|
34 | }
|
---|
35 | export default JsonSchema; |
---|