@swagger-api/apidom-ast 0.92.0 → 0.93.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/cjs/Error.cjs +10 -13
- package/cjs/Literal.cjs +9 -11
- package/cjs/Node.cjs +23 -32
- package/cjs/ParseResult.cjs +5 -12
- package/cjs/Position.cjs +20 -32
- package/cjs/json/nodes/JsonArray.cjs +5 -11
- package/cjs/json/nodes/JsonDocument.cjs +5 -12
- package/cjs/json/nodes/JsonEscapeSequence.cjs +3 -6
- package/cjs/json/nodes/JsonFalse.cjs +3 -6
- package/cjs/json/nodes/JsonKey.cjs +3 -6
- package/cjs/json/nodes/JsonNode.cjs +1 -2
- package/cjs/json/nodes/JsonNull.cjs +3 -6
- package/cjs/json/nodes/JsonNumber.cjs +3 -6
- package/cjs/json/nodes/JsonObject.cjs +5 -11
- package/cjs/json/nodes/JsonProperty.cjs +8 -17
- package/cjs/json/nodes/JsonString.cjs +8 -16
- package/cjs/json/nodes/JsonStringContent.cjs +3 -6
- package/cjs/json/nodes/JsonTrue.cjs +3 -6
- package/cjs/json/nodes/JsonValue.cjs +10 -12
- package/cjs/json/nodes/predicates.cjs +24 -12
- package/cjs/predicates.cjs +9 -5
- package/cjs/yaml/nodes/YamlAlias.cjs +10 -12
- package/cjs/yaml/nodes/YamlAnchor.cjs +10 -12
- package/cjs/yaml/nodes/YamlCollection.cjs +1 -2
- package/cjs/yaml/nodes/YamlComment.cjs +10 -12
- package/cjs/yaml/nodes/YamlDirective.cjs +14 -17
- package/cjs/yaml/nodes/YamlDocument.cjs +3 -6
- package/cjs/yaml/nodes/YamlKeyValuePair.cjs +28 -27
- package/cjs/yaml/nodes/YamlMapping.cjs +7 -13
- package/cjs/yaml/nodes/YamlNode.cjs +12 -15
- package/cjs/yaml/nodes/YamlScalar.cjs +10 -12
- package/cjs/yaml/nodes/YamlSequence.cjs +10 -16
- package/cjs/yaml/nodes/YamlStream.cjs +7 -15
- package/cjs/yaml/nodes/YamlStyle.cjs +2 -11
- package/cjs/yaml/nodes/YamlTag.cjs +10 -13
- package/cjs/yaml/nodes/predicates.cjs +20 -10
- package/cjs/yaml/schemas/ScalarTag.cjs +23 -32
- package/cjs/yaml/schemas/Tag.cjs +16 -7
- package/cjs/yaml/schemas/failsafe/GenericMapping.cjs +7 -19
- package/cjs/yaml/schemas/failsafe/GenericSequence.cjs +7 -19
- package/cjs/yaml/schemas/failsafe/GenericString.cjs +3 -16
- package/cjs/yaml/schemas/failsafe/index.cjs +81 -87
- package/cjs/yaml/schemas/json/Boolean.cjs +13 -21
- package/cjs/yaml/schemas/json/FloatingPoint.cjs +13 -21
- package/cjs/yaml/schemas/json/Integer.cjs +13 -21
- package/cjs/yaml/schemas/json/Null.cjs +12 -20
- package/cjs/yaml/schemas/json/index.cjs +20 -26
- package/dist/apidom-ast.browser.js +577 -893
- package/dist/apidom-ast.browser.min.js +1 -1
- package/es/Error.mjs +10 -13
- package/es/Literal.mjs +9 -11
- package/es/Node.mjs +23 -31
- package/es/ParseResult.mjs +5 -12
- package/es/Position.mjs +19 -31
- package/es/json/nodes/JsonArray.mjs +5 -11
- package/es/json/nodes/JsonDocument.mjs +5 -12
- package/es/json/nodes/JsonEscapeSequence.mjs +3 -6
- package/es/json/nodes/JsonFalse.mjs +3 -6
- package/es/json/nodes/JsonKey.mjs +3 -6
- package/es/json/nodes/JsonNode.mjs +1 -2
- package/es/json/nodes/JsonNull.mjs +3 -6
- package/es/json/nodes/JsonNumber.mjs +3 -6
- package/es/json/nodes/JsonObject.mjs +5 -11
- package/es/json/nodes/JsonProperty.mjs +8 -17
- package/es/json/nodes/JsonString.mjs +8 -16
- package/es/json/nodes/JsonStringContent.mjs +3 -6
- package/es/json/nodes/JsonTrue.mjs +3 -6
- package/es/json/nodes/JsonValue.mjs +10 -12
- package/es/json/nodes/predicates.mjs +12 -12
- package/es/predicates.mjs +5 -5
- package/es/yaml/nodes/YamlAlias.mjs +10 -12
- package/es/yaml/nodes/YamlAnchor.mjs +10 -12
- package/es/yaml/nodes/YamlCollection.mjs +1 -2
- package/es/yaml/nodes/YamlComment.mjs +10 -12
- package/es/yaml/nodes/YamlDirective.mjs +14 -17
- package/es/yaml/nodes/YamlDocument.mjs +3 -6
- package/es/yaml/nodes/YamlKeyValuePair.mjs +28 -27
- package/es/yaml/nodes/YamlMapping.mjs +7 -13
- package/es/yaml/nodes/YamlNode.mjs +12 -15
- package/es/yaml/nodes/YamlScalar.mjs +10 -12
- package/es/yaml/nodes/YamlSequence.mjs +10 -16
- package/es/yaml/nodes/YamlStream.mjs +7 -15
- package/es/yaml/nodes/YamlStyle.mjs +1 -9
- package/es/yaml/nodes/YamlTag.mjs +10 -13
- package/es/yaml/nodes/predicates.mjs +10 -10
- package/es/yaml/schemas/ScalarTag.mjs +23 -31
- package/es/yaml/schemas/Tag.mjs +17 -6
- package/es/yaml/schemas/failsafe/GenericMapping.mjs +8 -19
- package/es/yaml/schemas/failsafe/GenericSequence.mjs +8 -19
- package/es/yaml/schemas/failsafe/GenericString.mjs +3 -16
- package/es/yaml/schemas/failsafe/index.mjs +84 -90
- package/es/yaml/schemas/json/Boolean.mjs +14 -21
- package/es/yaml/schemas/json/FloatingPoint.mjs +14 -21
- package/es/yaml/schemas/json/Integer.mjs +14 -21
- package/es/yaml/schemas/json/Null.mjs +13 -20
- package/es/yaml/schemas/json/index.mjs +24 -30
- package/package.json +3 -4
- package/types/dist.d.ts +222 -157
@@ -1,11 +1,11 @@
|
|
1
1
|
import { isNodeType } from "../../predicates.mjs";
|
2
|
-
export const isStream = isNodeType
|
3
|
-
export const isDocument = isNodeType
|
4
|
-
export const isMapping = isNodeType
|
5
|
-
export const isSequence = isNodeType
|
6
|
-
export const isKeyValuePair = isNodeType
|
7
|
-
export const isTag = isNodeType
|
8
|
-
export const isScalar = isNodeType
|
9
|
-
export const isAlias = isNodeType
|
10
|
-
export const isDirective = isNodeType
|
11
|
-
export const isComment = isNodeType
|
2
|
+
export const isStream = node => isNodeType('stream', node);
|
3
|
+
export const isDocument = node => isNodeType('document', node);
|
4
|
+
export const isMapping = node => isNodeType('mapping', node);
|
5
|
+
export const isSequence = node => isNodeType('sequence', node);
|
6
|
+
export const isKeyValuePair = node => isNodeType('keyValuePair', node);
|
7
|
+
export const isTag = node => isNodeType('tag', node);
|
8
|
+
export const isScalar = node => isNodeType('scalar', node);
|
9
|
+
export const isAlias = node => isNodeType('alias', node);
|
10
|
+
export const isDirective = node => isNodeType('directive', node);
|
11
|
+
export const isComment = node => isNodeType('comment', node);
|
@@ -1,37 +1,29 @@
|
|
1
|
-
import stampit from 'stampit';
|
2
1
|
import { formatFlowPlain, formatFlowSingleQuoted, formatFlowDoubleQuoted, formatBlockLiteral, formatBlockFolded } from "./canonical-format.mjs";
|
3
2
|
import { YamlStyle } from "../nodes/YamlStyle.mjs";
|
4
3
|
import { YamlNodeKind } from "../nodes/YamlTag.mjs";
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
} else if (node.style === YamlStyle.Literal) {
|
23
|
-
// @ts-ignore
|
24
|
-
canonicalForm = formatBlockLiteral(node.content);
|
25
|
-
} else if (node.style === YamlStyle.Folded) {
|
26
|
-
// @ts-ignore
|
27
|
-
canonicalForm = formatBlockFolded(node.content);
|
28
|
-
}
|
29
|
-
nodeClone.content = canonicalForm;
|
30
|
-
return nodeClone;
|
31
|
-
},
|
32
|
-
resolve(node) {
|
33
|
-
return node;
|
4
|
+
class ScalarTag {
|
5
|
+
static test(node) {
|
6
|
+
return node.tag.kind === YamlNodeKind.Scalar && typeof node.content === 'string';
|
7
|
+
}
|
8
|
+
static canonicalFormat(node) {
|
9
|
+
let canonicalForm = node.content;
|
10
|
+
const nodeClone = node.clone();
|
11
|
+
if (node.style === YamlStyle.Plain) {
|
12
|
+
canonicalForm = formatFlowPlain(node.content);
|
13
|
+
} else if (node.style === YamlStyle.SingleQuoted) {
|
14
|
+
canonicalForm = formatFlowSingleQuoted(node.content);
|
15
|
+
} else if (node.style === YamlStyle.DoubleQuoted) {
|
16
|
+
canonicalForm = formatFlowDoubleQuoted(node.content);
|
17
|
+
} else if (node.style === YamlStyle.Literal) {
|
18
|
+
canonicalForm = formatBlockLiteral(node.content);
|
19
|
+
} else if (node.style === YamlStyle.Folded) {
|
20
|
+
canonicalForm = formatBlockFolded(node.content);
|
34
21
|
}
|
22
|
+
nodeClone.content = canonicalForm;
|
23
|
+
return nodeClone;
|
24
|
+
}
|
25
|
+
static resolve(node) {
|
26
|
+
return node;
|
35
27
|
}
|
36
|
-
}
|
28
|
+
}
|
37
29
|
export default ScalarTag;
|
package/es/yaml/schemas/Tag.mjs
CHANGED
@@ -1,8 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
/* eslint-disable class-methods-use-this */
|
2
|
+
class Tag {
|
3
|
+
static uri = '';
|
4
|
+
tag = '';
|
5
|
+
constructor() {
|
6
|
+
this.tag = this.constructor.uri;
|
6
7
|
}
|
7
|
-
|
8
|
+
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
10
|
+
test(node) {
|
11
|
+
return true;
|
12
|
+
}
|
13
|
+
resolve(node) {
|
14
|
+
return node;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
/* eslint-enable class-methods-use-this */
|
18
|
+
|
8
19
|
export default Tag;
|
@@ -1,23 +1,12 @@
|
|
1
|
-
import stampit from 'stampit';
|
2
1
|
import Tag from "../Tag.mjs";
|
3
2
|
import { YamlNodeKind } from "../../nodes/YamlTag.mjs";
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
stamp
|
10
|
-
}) {
|
11
|
-
this.tag = stamp.uri;
|
12
|
-
},
|
13
|
-
methods: {
|
14
|
-
test(node) {
|
15
|
-
// @ts-ignore
|
16
|
-
return node.tag.kind === YamlNodeKind.Mapping;
|
17
|
-
},
|
18
|
-
resolve(node) {
|
19
|
-
return node;
|
20
|
-
}
|
3
|
+
/* eslint-disable class-methods-use-this */
|
4
|
+
class GenericMapping extends Tag {
|
5
|
+
static uri = 'tag:yaml.org,2002:map';
|
6
|
+
test(node) {
|
7
|
+
return node.tag.kind === YamlNodeKind.Mapping;
|
21
8
|
}
|
22
|
-
}
|
9
|
+
}
|
10
|
+
/* eslint-enable class-methods-use-this */
|
11
|
+
|
23
12
|
export default GenericMapping;
|
@@ -1,23 +1,12 @@
|
|
1
|
-
import stampit from 'stampit';
|
2
1
|
import Tag from "../Tag.mjs";
|
3
2
|
import { YamlNodeKind } from "../../nodes/YamlTag.mjs";
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
stamp
|
10
|
-
}) {
|
11
|
-
this.tag = stamp.uri;
|
12
|
-
},
|
13
|
-
methods: {
|
14
|
-
test(node) {
|
15
|
-
// @ts-ignore
|
16
|
-
return node.tag.kind === YamlNodeKind.Sequence;
|
17
|
-
},
|
18
|
-
resolve(node) {
|
19
|
-
return node;
|
20
|
-
}
|
3
|
+
/* eslint-disable class-methods-use-this */
|
4
|
+
class GenericSequence extends Tag {
|
5
|
+
static uri = 'tag:yaml.org,2002:seq';
|
6
|
+
test(node) {
|
7
|
+
return node.tag.kind === YamlNodeKind.Sequence;
|
21
8
|
}
|
22
|
-
}
|
9
|
+
}
|
10
|
+
/* eslint-enable class-methods-use-this */
|
11
|
+
|
23
12
|
export default GenericSequence;
|
@@ -1,18 +1,5 @@
|
|
1
|
-
import stampit from 'stampit';
|
2
1
|
import Tag from "../Tag.mjs";
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
},
|
7
|
-
init(args, {
|
8
|
-
stamp
|
9
|
-
}) {
|
10
|
-
this.tag = stamp.uri;
|
11
|
-
},
|
12
|
-
methods: {
|
13
|
-
resolve(node) {
|
14
|
-
return node;
|
15
|
-
}
|
16
|
-
}
|
17
|
-
});
|
2
|
+
class GenericString extends Tag {
|
3
|
+
static uri = 'tag:yaml.org,2002:str';
|
4
|
+
}
|
18
5
|
export default GenericString;
|
@@ -1,105 +1,99 @@
|
|
1
1
|
import { clone } from 'ramda';
|
2
|
-
import stampit from 'stampit';
|
3
2
|
import YamlTagError from "../../errors/YamlTagError.mjs";
|
4
3
|
import { YamlNodeKind } from "../../nodes/YamlTag.mjs";
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import
|
4
|
+
import GenericMappingTag from "./GenericMapping.mjs";
|
5
|
+
import GenericSequenceTag from "./GenericSequence.mjs";
|
6
|
+
import GenericStringTag from "./GenericString.mjs";
|
8
7
|
import ScalarTag from "../ScalarTag.mjs";
|
9
|
-
|
10
|
-
|
11
|
-
tags: [],
|
12
|
-
tagDirectives: []
|
13
|
-
},
|
14
|
-
init() {
|
8
|
+
class FailsafeSchema {
|
9
|
+
constructor() {
|
15
10
|
this.tags = [];
|
16
11
|
this.tagDirectives = [];
|
17
|
-
this.registerTag(
|
18
|
-
this.registerTag(
|
19
|
-
this.registerTag(
|
20
|
-
}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
// @ts-ignore
|
34
|
-
specificTagName = GenericMapping.uri;
|
35
|
-
}
|
36
|
-
} else if (node.tag.explicitName.startsWith('!<')) {
|
37
|
-
// verbatim form
|
38
|
-
specificTagName = node.tag.explicitName.replace(/^!</, '').replace(/>$/, '');
|
39
|
-
} else if (node.tag.explicitName.startsWith('!!')) {
|
40
|
-
// shorthand notation
|
41
|
-
specificTagName = `tag:yaml.org,2002:${node.tag.explicitName.replace(/^!!/, '')}`;
|
42
|
-
}
|
43
|
-
return specificTagName;
|
44
|
-
},
|
45
|
-
registerTagDirective(tagDirective) {
|
46
|
-
this.tagDirectives.push({
|
47
|
-
handle: tagDirective.parameters.handle,
|
48
|
-
prefix: tagDirective.parameters.prefix
|
49
|
-
});
|
50
|
-
},
|
51
|
-
registerTag(tag, beginning = false) {
|
52
|
-
if (beginning) {
|
53
|
-
this.tags.unshift(tag);
|
54
|
-
} else {
|
55
|
-
this.tags.push(tag);
|
12
|
+
this.registerTag(new GenericMappingTag());
|
13
|
+
this.registerTag(new GenericSequenceTag());
|
14
|
+
this.registerTag(new GenericStringTag());
|
15
|
+
}
|
16
|
+
|
17
|
+
// eslint-disable-next-line class-methods-use-this
|
18
|
+
toSpecificTagName(node) {
|
19
|
+
let specificTagName = node.tag.explicitName;
|
20
|
+
if (node.tag.explicitName === '!') {
|
21
|
+
// non-specific tag; we assume tag by kind
|
22
|
+
if (node.tag.kind === YamlNodeKind.Scalar) {
|
23
|
+
specificTagName = GenericStringTag.uri;
|
24
|
+
} else if (node.tag.kind === YamlNodeKind.Sequence) {
|
25
|
+
specificTagName = GenericSequenceTag.uri;
|
26
|
+
} else if (node.tag.kind === YamlNodeKind.Mapping) {
|
27
|
+
specificTagName = GenericMappingTag.uri;
|
56
28
|
}
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
29
|
+
} else if (node.tag.explicitName.startsWith('!<')) {
|
30
|
+
// verbatim form
|
31
|
+
specificTagName = node.tag.explicitName.replace(/^!</, '').replace(/>$/, '');
|
32
|
+
} else if (node.tag.explicitName.startsWith('!!')) {
|
33
|
+
// shorthand notation
|
34
|
+
specificTagName = `tag:yaml.org,2002:${node.tag.explicitName.replace(/^!!/, '')}`;
|
35
|
+
}
|
36
|
+
return specificTagName;
|
37
|
+
}
|
38
|
+
registerTagDirective(tagDirective) {
|
39
|
+
this.tagDirectives.push({
|
40
|
+
// @ts-ignore
|
41
|
+
handle: tagDirective.parameters.handle,
|
42
|
+
// @ts-ignore
|
43
|
+
prefix: tagDirective.parameters.prefix
|
44
|
+
});
|
45
|
+
}
|
46
|
+
registerTag(tag, beginning = false) {
|
47
|
+
if (beginning) {
|
48
|
+
this.tags.unshift(tag);
|
49
|
+
} else {
|
61
50
|
this.tags.push(tag);
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
51
|
+
}
|
52
|
+
return this;
|
53
|
+
}
|
54
|
+
overrideTag(tag) {
|
55
|
+
this.tags = this.tags.filter(itag => itag.tag === tag.tag);
|
56
|
+
this.tags.push(tag);
|
57
|
+
return this;
|
58
|
+
}
|
59
|
+
resolve(node) {
|
60
|
+
const specificTagName = this.toSpecificTagName(node);
|
66
61
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
// leave this node unresolved
|
63
|
+
if (specificTagName === '?') {
|
64
|
+
return node;
|
65
|
+
}
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
67
|
+
// turn scalar nodes into canonical format before resolving
|
68
|
+
let canonicalNode = node;
|
69
|
+
if (ScalarTag.test(node)) {
|
70
|
+
canonicalNode = ScalarTag.canonicalFormat(node);
|
71
|
+
}
|
72
|
+
const tag = this.tags.find(itag => (itag === null || itag === void 0 ? void 0 : itag.tag) === specificTagName);
|
78
73
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
74
|
+
// mechanism for resolving node (tag implementation) not found
|
75
|
+
if (typeof tag === 'undefined') {
|
76
|
+
throw new YamlTagError(`Tag "${specificTagName}" was not recognized.`, {
|
77
|
+
specificTagName,
|
78
|
+
explicitTagName: node.tag.explicitName,
|
79
|
+
tagKind: node.tag.kind,
|
80
|
+
tagPosition: clone(node.tag.position),
|
81
|
+
node: node.clone()
|
82
|
+
});
|
83
|
+
}
|
89
84
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}
|
101
|
-
return tag.resolve(canonicalNode);
|
85
|
+
// node content is not compatible with resolving mechanism (tag implementation)
|
86
|
+
if (!tag.test(canonicalNode)) {
|
87
|
+
throw new YamlTagError(`Node couldn't be resolved against the tag "${specificTagName}"`, {
|
88
|
+
specificTagName,
|
89
|
+
explicitTagName: node.tag.explicitName,
|
90
|
+
tagKind: node.tag.kind,
|
91
|
+
tagPosition: clone(node.tag.position),
|
92
|
+
nodeCanonicalContent: canonicalNode.content,
|
93
|
+
node: node.clone()
|
94
|
+
});
|
102
95
|
}
|
96
|
+
return tag.resolve(canonicalNode);
|
103
97
|
}
|
104
|
-
}
|
98
|
+
}
|
105
99
|
export default FailsafeSchema;
|
@@ -1,24 +1,17 @@
|
|
1
|
-
import stampit from 'stampit';
|
2
1
|
import Tag from "../Tag.mjs";
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
stamp
|
9
|
-
}) {
|
10
|
-
this.tag = stamp.uri;
|
11
|
-
},
|
12
|
-
methods: {
|
13
|
-
test(node) {
|
14
|
-
return /^(true|false)$/.test(node.content);
|
15
|
-
},
|
16
|
-
resolve(node) {
|
17
|
-
const content = node.content === 'true';
|
18
|
-
const nodeClone = node.clone();
|
19
|
-
nodeClone.content = content;
|
20
|
-
return nodeClone;
|
21
|
-
}
|
2
|
+
/* eslint-disable class-methods-use-this */
|
3
|
+
class Boolean extends Tag {
|
4
|
+
static uri = 'tag:yaml.org,2002:bool';
|
5
|
+
test(node) {
|
6
|
+
return /^(true|false)$/.test(node.content);
|
22
7
|
}
|
23
|
-
|
8
|
+
resolve(node) {
|
9
|
+
const content = node.content === 'true';
|
10
|
+
const nodeClone = node.clone();
|
11
|
+
nodeClone.content = content;
|
12
|
+
return nodeClone;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
/* eslint-enable class-methods-use-this */
|
16
|
+
|
24
17
|
export default Boolean;
|
@@ -1,24 +1,17 @@
|
|
1
|
-
import stampit from 'stampit';
|
2
1
|
import Tag from "../Tag.mjs";
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
stamp
|
9
|
-
}) {
|
10
|
-
this.tag = stamp.uri;
|
11
|
-
},
|
12
|
-
methods: {
|
13
|
-
test(node) {
|
14
|
-
return /^-?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][-+]?[0-9]+)?$/.test(node.content);
|
15
|
-
},
|
16
|
-
resolve(node) {
|
17
|
-
const content = parseFloat(node.content);
|
18
|
-
const nodeClone = node.clone();
|
19
|
-
nodeClone.content = content;
|
20
|
-
return nodeClone;
|
21
|
-
}
|
2
|
+
/* eslint-disable class-methods-use-this */
|
3
|
+
class FloatingPoint extends Tag {
|
4
|
+
static uri = 'tag:yaml.org,2002:float';
|
5
|
+
test(node) {
|
6
|
+
return /^-?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][-+]?[0-9]+)?$/.test(node.content);
|
22
7
|
}
|
23
|
-
|
8
|
+
resolve(node) {
|
9
|
+
const content = parseFloat(node.content);
|
10
|
+
const nodeClone = node.clone();
|
11
|
+
nodeClone.content = content;
|
12
|
+
return nodeClone;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
/* eslint-enable class-methods-use-this */
|
16
|
+
|
24
17
|
export default FloatingPoint;
|
@@ -1,24 +1,17 @@
|
|
1
|
-
import stampit from 'stampit';
|
2
1
|
import Tag from "../Tag.mjs";
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
stamp
|
9
|
-
}) {
|
10
|
-
this.tag = stamp.uri;
|
11
|
-
},
|
12
|
-
methods: {
|
13
|
-
test(node) {
|
14
|
-
return /^-?(0|[1-9][0-9]*)$/.test(node.content);
|
15
|
-
},
|
16
|
-
resolve(node) {
|
17
|
-
const content = parseInt(node.content, 10);
|
18
|
-
const nodeClone = node.clone();
|
19
|
-
nodeClone.content = content;
|
20
|
-
return nodeClone;
|
21
|
-
}
|
2
|
+
/* eslint-disable class-methods-use-this */
|
3
|
+
class Integer extends Tag {
|
4
|
+
static uri = 'tag:yaml.org,2002:int';
|
5
|
+
test(node) {
|
6
|
+
return /^-?(0|[1-9][0-9]*)$/.test(node.content);
|
22
7
|
}
|
23
|
-
|
8
|
+
resolve(node) {
|
9
|
+
const content = parseInt(node.content, 10);
|
10
|
+
const nodeClone = node.clone();
|
11
|
+
nodeClone.content = content;
|
12
|
+
return nodeClone;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
/* eslint-enable class-methods-use-this */
|
16
|
+
|
24
17
|
export default Integer;
|
@@ -1,23 +1,16 @@
|
|
1
|
-
import stampit from 'stampit';
|
2
1
|
import Tag from "../Tag.mjs";
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
stamp
|
9
|
-
}) {
|
10
|
-
this.tag = stamp.uri;
|
11
|
-
},
|
12
|
-
methods: {
|
13
|
-
test(node) {
|
14
|
-
return /^null$/.test(node.content);
|
15
|
-
},
|
16
|
-
resolve(node) {
|
17
|
-
const nodeClone = node.clone();
|
18
|
-
nodeClone.content = null;
|
19
|
-
return nodeClone;
|
20
|
-
}
|
2
|
+
/* eslint-disable class-methods-use-this */
|
3
|
+
class Null extends Tag {
|
4
|
+
static uri = 'tag:yaml.org,2002:null';
|
5
|
+
test(node) {
|
6
|
+
return /^null$/.test(node.content);
|
21
7
|
}
|
22
|
-
|
8
|
+
resolve(node) {
|
9
|
+
const nodeClone = node.clone();
|
10
|
+
nodeClone.content = null;
|
11
|
+
return nodeClone;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
/* eslint-enable class-methods-use-this */
|
15
|
+
|
23
16
|
export default Null;
|
@@ -1,41 +1,35 @@
|
|
1
|
-
import stampit from 'stampit';
|
2
1
|
import FailsafeSchema from "../failsafe/index.mjs";
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
2
|
+
import BooleanTag from "./Boolean.mjs";
|
3
|
+
import FloatingPointTag from "./FloatingPoint.mjs";
|
4
|
+
import IntegerTag from "./Integer.mjs";
|
5
|
+
import NullTag from "./Null.mjs";
|
7
6
|
import { YamlNodeKind } from "../../nodes/YamlTag.mjs";
|
8
7
|
import GenericSequence from "../failsafe/GenericSequence.mjs";
|
9
8
|
import GenericMapping from "../failsafe/GenericMapping.mjs";
|
10
|
-
|
11
|
-
|
9
|
+
class JsonSchema extends FailsafeSchema {
|
10
|
+
constructor() {
|
11
|
+
super();
|
12
12
|
/**
|
13
13
|
* We're registering more specific tags before more generic ones from Failsafe schema.
|
14
14
|
*/
|
15
|
-
this.registerTag(
|
16
|
-
this.registerTag(
|
17
|
-
this.registerTag(
|
18
|
-
this.registerTag(
|
19
|
-
}
|
20
|
-
|
21
|
-
toSpecificTagName(node)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
specificTagName = GenericMapping.uri;
|
31
|
-
} else if (node.tag.kind === YamlNodeKind.Scalar) {
|
32
|
-
// @ts-ignore
|
33
|
-
const foundTag = this.tags.find(tag => tag.test(node));
|
34
|
-
specificTagName = (foundTag === null || foundTag === void 0 ? void 0 : foundTag.tag) || '?';
|
35
|
-
}
|
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) || '?';
|
36
30
|
}
|
37
|
-
return specificTagName;
|
38
31
|
}
|
32
|
+
return specificTagName;
|
39
33
|
}
|
40
|
-
}
|
34
|
+
}
|
41
35
|
export default JsonSchema;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@swagger-api/apidom-ast",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.93.0",
|
4
4
|
"description": "Tools necessary for parsing stage of ApiDOM, specifically for syntactic analysis.",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public",
|
@@ -42,11 +42,10 @@
|
|
42
42
|
"homepage": "https://github.com/swagger-api/apidom#readme",
|
43
43
|
"dependencies": {
|
44
44
|
"@babel/runtime-corejs3": "^7.20.7",
|
45
|
-
"@swagger-api/apidom-error": "^0.
|
45
|
+
"@swagger-api/apidom-error": "^0.93.0",
|
46
46
|
"@types/ramda": "~0.29.6",
|
47
47
|
"ramda": "~0.29.1",
|
48
48
|
"ramda-adjunct": "^4.1.1",
|
49
|
-
"stampit": "^4.3.2",
|
50
49
|
"unraw": "^3.0.0"
|
51
50
|
},
|
52
51
|
"files": [
|
@@ -59,5 +58,5 @@
|
|
59
58
|
"README.md",
|
60
59
|
"CHANGELOG.md"
|
61
60
|
],
|
62
|
-
"gitHead": "
|
61
|
+
"gitHead": "65ea9068f5d8b144293c2f91eb5fe5ebacfd947c"
|
63
62
|
}
|