@swagger-api/apidom-parser-adapter-yaml-1-2 0.93.0 → 0.95.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 +12 -0
- package/cjs/syntactic-analysis/TreeCursorIterator.cjs +1 -0
- package/cjs/syntactic-analysis/TreeCursorSyntaxNode.cjs +10 -0
- package/cjs/syntactic-analysis/indirect/index.cjs +3 -1
- package/cjs/syntactic-analysis/indirect/visitors/CstVisitor.cjs +114 -87
- package/cjs/syntactic-analysis/indirect/visitors/YamlAstVisitor.cjs +2 -0
- package/dist/apidom-parser-adapter-yaml-1-2.browser.js +1771 -1610
- package/dist/apidom-parser-adapter-yaml1-2.browser.min.js +1 -1
- package/es/syntactic-analysis/TreeCursorIterator.mjs +1 -0
- package/es/syntactic-analysis/TreeCursorSyntaxNode.mjs +10 -0
- package/es/syntactic-analysis/indirect/index.mjs +4 -2
- package/es/syntactic-analysis/indirect/visitors/CstVisitor.mjs +115 -88
- package/es/syntactic-analysis/indirect/visitors/YamlAstVisitor.mjs +2 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.95.0](https://github.com/swagger-api/apidom/compare/v0.94.0...v0.95.0) (2024-02-09)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **parser-adapter-yaml-1-2:** fix canonical formatting of quoted scalars ([#3792](https://github.com/swagger-api/apidom/issues/3792)) ([3d9ff9f](https://github.com/swagger-api/apidom/commit/3d9ff9fd990f1ec0dd9618b6d3b135ccdb00a9ba)), closes [#3788](https://github.com/swagger-api/apidom/issues/3788)
|
|
11
|
+
|
|
12
|
+
# [0.94.0](https://github.com/swagger-api/apidom/compare/v0.93.0...v0.94.0) (2024-02-05)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- **parser-adapter-yaml-1-2:** add syntactic analysis for YAML aliases ([#3785](https://github.com/swagger-api/apidom/issues/3785)) ([e975718](https://github.com/swagger-api/apidom/commit/e97571823d1d3154fe3b13936260ed13230cf573)), closes [#3703](https://github.com/swagger-api/apidom/issues/3703)
|
|
17
|
+
|
|
6
18
|
# [0.93.0](https://github.com/swagger-api/apidom/compare/v0.92.0...v0.93.0) (2024-01-23)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @swagger-api/apidom-parser-adapter-yaml-1-2
|
|
@@ -3,8 +3,18 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
5
|
class TreeCursorSyntaxNode {
|
|
6
|
+
type;
|
|
7
|
+
startPosition;
|
|
8
|
+
endPosition;
|
|
9
|
+
startIndex;
|
|
10
|
+
endIndex;
|
|
11
|
+
text;
|
|
12
|
+
isNamed;
|
|
13
|
+
isMissing;
|
|
14
|
+
fieldName;
|
|
6
15
|
hasError = false;
|
|
7
16
|
children = [];
|
|
17
|
+
previousSibling;
|
|
8
18
|
constructor(cursor) {
|
|
9
19
|
this.type = cursor.nodeType;
|
|
10
20
|
this.startPosition = cursor.startPosition;
|
|
@@ -22,13 +22,15 @@ const analyze = (cst, {
|
|
|
22
22
|
const cstVisitor = new _CstVisitor.default();
|
|
23
23
|
const astVisitor = new _YamlAstVisitor.default();
|
|
24
24
|
const schema = new _apidomAst.YamlJsonSchema();
|
|
25
|
+
const referenceManager = new _apidomAst.YamlReferenceManager();
|
|
25
26
|
const yamlAst = (0, _apidomAst.visit)(rootNode, cstVisitor, {
|
|
26
27
|
// @ts-ignore
|
|
27
28
|
keyMap: _CstVisitor.keyMap,
|
|
28
29
|
nodePredicate: _CstVisitor.isNode,
|
|
29
30
|
state: {
|
|
30
31
|
schema,
|
|
31
|
-
sourceMap
|
|
32
|
+
sourceMap,
|
|
33
|
+
referenceManager
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
return (0, _apidomAst.visit)(yamlAst.rootNode, astVisitor, {
|
|
@@ -40,6 +40,16 @@ class CstVisitor {
|
|
|
40
40
|
end
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
+
static kindNodeToYamlAnchor(node) {
|
|
44
|
+
const {
|
|
45
|
+
anchor: anchorNode
|
|
46
|
+
} = node;
|
|
47
|
+
if (typeof anchorNode === 'undefined') return undefined;
|
|
48
|
+
return new _apidomAst.YamlAnchor({
|
|
49
|
+
name: anchorNode.text,
|
|
50
|
+
position: CstVisitor.toPosition(anchorNode)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
43
53
|
static hasKeyValuePairEmptyKey(node) {
|
|
44
54
|
if (node.type !== 'block_mapping_pair' && node.type !== 'flow_pair') {
|
|
45
55
|
return false;
|
|
@@ -67,91 +77,10 @@ class CstVisitor {
|
|
|
67
77
|
position
|
|
68
78
|
});
|
|
69
79
|
}
|
|
70
|
-
static kindNodeToYamlAnchor(node) {
|
|
71
|
-
const {
|
|
72
|
-
anchor: anchorNode
|
|
73
|
-
} = node;
|
|
74
|
-
if (typeof anchorNode === 'undefined') return undefined;
|
|
75
|
-
return new _apidomAst.YamlAnchor({
|
|
76
|
-
name: anchorNode.text,
|
|
77
|
-
position: CstVisitor.toPosition(anchorNode)
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
static createKeyValuePairEmptyKey(node) {
|
|
81
|
-
const emptyPoint = new _apidomAst.Point({
|
|
82
|
-
row: node.startPosition.row,
|
|
83
|
-
column: node.startPosition.column,
|
|
84
|
-
char: node.startIndex
|
|
85
|
-
});
|
|
86
|
-
const {
|
|
87
|
-
keyNode
|
|
88
|
-
} = node;
|
|
89
|
-
const children = (keyNode == null ? void 0 : keyNode.children) || [];
|
|
90
|
-
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
91
|
-
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
92
|
-
const tag = typeof tagNode !== 'undefined' ? new _apidomAst.YamlTag({
|
|
93
|
-
explicitName: tagNode.text,
|
|
94
|
-
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
95
|
-
position: CstVisitor.toPosition(tagNode)
|
|
96
|
-
}) : new _apidomAst.YamlTag({
|
|
97
|
-
explicitName: '?',
|
|
98
|
-
kind: _apidomAst.YamlNodeKind.Scalar
|
|
99
|
-
});
|
|
100
|
-
const anchor = typeof anchorNode !== 'undefined' ? new _apidomAst.YamlAnchor({
|
|
101
|
-
name: anchorNode.text,
|
|
102
|
-
position: CstVisitor.toPosition(anchorNode)
|
|
103
|
-
}) : undefined;
|
|
104
|
-
return new _apidomAst.YamlScalar({
|
|
105
|
-
content: '',
|
|
106
|
-
position: new _apidomAst.Position({
|
|
107
|
-
start: emptyPoint,
|
|
108
|
-
end: emptyPoint
|
|
109
|
-
}),
|
|
110
|
-
tag,
|
|
111
|
-
anchor,
|
|
112
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
113
|
-
style: _apidomAst.YamlStyle.Plain
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
static createKeyValuePairEmptyValue(node) {
|
|
117
|
-
const emptyPoint = new _apidomAst.Point({
|
|
118
|
-
row: node.endPosition.row,
|
|
119
|
-
column: node.endPosition.column,
|
|
120
|
-
char: node.endIndex
|
|
121
|
-
});
|
|
122
|
-
const {
|
|
123
|
-
valueNode
|
|
124
|
-
} = node;
|
|
125
|
-
const children = (valueNode == null ? void 0 : valueNode.children) || [];
|
|
126
|
-
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
127
|
-
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
128
|
-
const tag = typeof tagNode !== 'undefined' ? new _apidomAst.YamlTag({
|
|
129
|
-
explicitName: tagNode.text,
|
|
130
|
-
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
131
|
-
position: CstVisitor.toPosition(tagNode)
|
|
132
|
-
}) : new _apidomAst.YamlTag({
|
|
133
|
-
explicitName: '?',
|
|
134
|
-
kind: _apidomAst.YamlNodeKind.Scalar
|
|
135
|
-
});
|
|
136
|
-
const anchor = typeof anchorNode !== 'undefined' ? new _apidomAst.YamlAnchor({
|
|
137
|
-
name: anchorNode.text,
|
|
138
|
-
position: CstVisitor.toPosition(anchorNode)
|
|
139
|
-
}) : undefined;
|
|
140
|
-
return new _apidomAst.YamlScalar({
|
|
141
|
-
content: '',
|
|
142
|
-
position: new _apidomAst.Position({
|
|
143
|
-
start: emptyPoint,
|
|
144
|
-
end: emptyPoint
|
|
145
|
-
}),
|
|
146
|
-
tag,
|
|
147
|
-
anchor,
|
|
148
|
-
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
149
|
-
style: _apidomAst.YamlStyle.Plain
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
80
|
|
|
153
81
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
|
-
|
|
82
|
+
schema;
|
|
83
|
+
referenceManager;
|
|
155
84
|
stream = {
|
|
156
85
|
enter: node => {
|
|
157
86
|
const position = CstVisitor.toPosition(node);
|
|
@@ -258,6 +187,7 @@ class CstVisitor {
|
|
|
258
187
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
259
188
|
style: _apidomAst.YamlStyle.Plain
|
|
260
189
|
});
|
|
190
|
+
this.registerAnchor(emptyScalarNode);
|
|
261
191
|
return [...node.children, emptyScalarNode];
|
|
262
192
|
}
|
|
263
193
|
};
|
|
@@ -285,6 +215,7 @@ class CstVisitor {
|
|
|
285
215
|
style: _apidomAst.YamlStyle.NextLine,
|
|
286
216
|
isMissing: node.isMissing
|
|
287
217
|
});
|
|
218
|
+
this.registerAnchor(mappingNode);
|
|
288
219
|
return this.schema.resolve(mappingNode);
|
|
289
220
|
}
|
|
290
221
|
};
|
|
@@ -293,11 +224,11 @@ class CstVisitor {
|
|
|
293
224
|
const position = CstVisitor.toPosition(node);
|
|
294
225
|
const children = [...node.children];
|
|
295
226
|
if (CstVisitor.hasKeyValuePairEmptyKey(node)) {
|
|
296
|
-
const keyNode =
|
|
227
|
+
const keyNode = this.createKeyValuePairEmptyKey(node);
|
|
297
228
|
children.unshift(keyNode);
|
|
298
229
|
}
|
|
299
230
|
if (CstVisitor.hasKeyValuePairEmptyValue(node)) {
|
|
300
|
-
const valueNode =
|
|
231
|
+
const valueNode = this.createKeyValuePairEmptyValue(node);
|
|
301
232
|
children.push(valueNode);
|
|
302
233
|
}
|
|
303
234
|
return new _apidomAst.YamlKeyValuePair({
|
|
@@ -322,6 +253,7 @@ class CstVisitor {
|
|
|
322
253
|
style: _apidomAst.YamlStyle.Explicit,
|
|
323
254
|
isMissing: node.isMissing
|
|
324
255
|
});
|
|
256
|
+
this.registerAnchor(mappingNode);
|
|
325
257
|
return this.schema.resolve(mappingNode);
|
|
326
258
|
}
|
|
327
259
|
};
|
|
@@ -330,11 +262,11 @@ class CstVisitor {
|
|
|
330
262
|
const position = CstVisitor.toPosition(node);
|
|
331
263
|
const children = [...node.children];
|
|
332
264
|
if (CstVisitor.hasKeyValuePairEmptyKey(node)) {
|
|
333
|
-
const keyNode =
|
|
265
|
+
const keyNode = this.createKeyValuePairEmptyKey(node);
|
|
334
266
|
children.unshift(keyNode);
|
|
335
267
|
}
|
|
336
268
|
if (CstVisitor.hasKeyValuePairEmptyValue(node)) {
|
|
337
|
-
const valueNode =
|
|
269
|
+
const valueNode = this.createKeyValuePairEmptyValue(node);
|
|
338
270
|
children.push(valueNode);
|
|
339
271
|
}
|
|
340
272
|
return new _apidomAst.YamlKeyValuePair({
|
|
@@ -363,6 +295,7 @@ class CstVisitor {
|
|
|
363
295
|
styleGroup: _apidomAst.YamlStyleGroup.Block,
|
|
364
296
|
style: _apidomAst.YamlStyle.NextLine
|
|
365
297
|
});
|
|
298
|
+
this.registerAnchor(sequenceNode);
|
|
366
299
|
return this.schema.resolve(sequenceNode);
|
|
367
300
|
}
|
|
368
301
|
};
|
|
@@ -408,6 +341,7 @@ class CstVisitor {
|
|
|
408
341
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
409
342
|
style: _apidomAst.YamlStyle.Explicit
|
|
410
343
|
});
|
|
344
|
+
this.registerAnchor(sequenceNode);
|
|
411
345
|
return this.schema.resolve(sequenceNode);
|
|
412
346
|
}
|
|
413
347
|
};
|
|
@@ -429,6 +363,7 @@ class CstVisitor {
|
|
|
429
363
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
430
364
|
style: _apidomAst.YamlStyle.Plain
|
|
431
365
|
});
|
|
366
|
+
this.registerAnchor(scalarNode);
|
|
432
367
|
return this.schema.resolve(scalarNode);
|
|
433
368
|
}
|
|
434
369
|
};
|
|
@@ -445,6 +380,7 @@ class CstVisitor {
|
|
|
445
380
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
446
381
|
style: _apidomAst.YamlStyle.SingleQuoted
|
|
447
382
|
});
|
|
383
|
+
this.registerAnchor(scalarNode);
|
|
448
384
|
return this.schema.resolve(scalarNode);
|
|
449
385
|
}
|
|
450
386
|
};
|
|
@@ -461,6 +397,7 @@ class CstVisitor {
|
|
|
461
397
|
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
462
398
|
style: _apidomAst.YamlStyle.DoubleQuoted
|
|
463
399
|
});
|
|
400
|
+
this.registerAnchor(scalarNode);
|
|
464
401
|
return this.schema.resolve(scalarNode);
|
|
465
402
|
}
|
|
466
403
|
};
|
|
@@ -478,6 +415,7 @@ class CstVisitor {
|
|
|
478
415
|
styleGroup: _apidomAst.YamlStyleGroup.Block,
|
|
479
416
|
style
|
|
480
417
|
});
|
|
418
|
+
this.registerAnchor(scalarNode);
|
|
481
419
|
return this.schema.resolve(scalarNode);
|
|
482
420
|
}
|
|
483
421
|
};
|
|
@@ -488,6 +426,14 @@ class CstVisitor {
|
|
|
488
426
|
});
|
|
489
427
|
}
|
|
490
428
|
};
|
|
429
|
+
alias = {
|
|
430
|
+
enter: node => {
|
|
431
|
+
const alias = new _apidomAst.YamlAlias({
|
|
432
|
+
content: node.text
|
|
433
|
+
});
|
|
434
|
+
return this.referenceManager.resolveAlias(alias);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
491
437
|
|
|
492
438
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
493
439
|
constructor(schema) {
|
|
@@ -529,5 +475,86 @@ class CstVisitor {
|
|
|
529
475
|
}
|
|
530
476
|
return errorNode;
|
|
531
477
|
}
|
|
478
|
+
registerAnchor(node) {
|
|
479
|
+
if (node.anchor !== undefined) {
|
|
480
|
+
this.referenceManager.addAnchor(node);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
createKeyValuePairEmptyKey(node) {
|
|
484
|
+
const emptyPoint = new _apidomAst.Point({
|
|
485
|
+
row: node.startPosition.row,
|
|
486
|
+
column: node.startPosition.column,
|
|
487
|
+
char: node.startIndex
|
|
488
|
+
});
|
|
489
|
+
const {
|
|
490
|
+
keyNode
|
|
491
|
+
} = node;
|
|
492
|
+
const children = (keyNode == null ? void 0 : keyNode.children) || [];
|
|
493
|
+
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
494
|
+
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
495
|
+
const tag = typeof tagNode !== 'undefined' ? new _apidomAst.YamlTag({
|
|
496
|
+
explicitName: tagNode.text,
|
|
497
|
+
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
498
|
+
position: CstVisitor.toPosition(tagNode)
|
|
499
|
+
}) : new _apidomAst.YamlTag({
|
|
500
|
+
explicitName: '?',
|
|
501
|
+
kind: _apidomAst.YamlNodeKind.Scalar
|
|
502
|
+
});
|
|
503
|
+
const anchor = typeof anchorNode !== 'undefined' ? new _apidomAst.YamlAnchor({
|
|
504
|
+
name: anchorNode.text,
|
|
505
|
+
position: CstVisitor.toPosition(anchorNode)
|
|
506
|
+
}) : undefined;
|
|
507
|
+
const scalarNode = new _apidomAst.YamlScalar({
|
|
508
|
+
content: '',
|
|
509
|
+
position: new _apidomAst.Position({
|
|
510
|
+
start: emptyPoint,
|
|
511
|
+
end: emptyPoint
|
|
512
|
+
}),
|
|
513
|
+
tag,
|
|
514
|
+
anchor,
|
|
515
|
+
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
516
|
+
style: _apidomAst.YamlStyle.Plain
|
|
517
|
+
});
|
|
518
|
+
this.registerAnchor(scalarNode);
|
|
519
|
+
return scalarNode;
|
|
520
|
+
}
|
|
521
|
+
createKeyValuePairEmptyValue(node) {
|
|
522
|
+
const emptyPoint = new _apidomAst.Point({
|
|
523
|
+
row: node.endPosition.row,
|
|
524
|
+
column: node.endPosition.column,
|
|
525
|
+
char: node.endIndex
|
|
526
|
+
});
|
|
527
|
+
const {
|
|
528
|
+
valueNode
|
|
529
|
+
} = node;
|
|
530
|
+
const children = (valueNode == null ? void 0 : valueNode.children) || [];
|
|
531
|
+
const tagNode = children.find(CstVisitor.isKind('tag'));
|
|
532
|
+
const anchorNode = children.find(CstVisitor.isKind('anchor'));
|
|
533
|
+
const tag = typeof tagNode !== 'undefined' ? new _apidomAst.YamlTag({
|
|
534
|
+
explicitName: tagNode.text,
|
|
535
|
+
kind: _apidomAst.YamlNodeKind.Scalar,
|
|
536
|
+
position: CstVisitor.toPosition(tagNode)
|
|
537
|
+
}) : new _apidomAst.YamlTag({
|
|
538
|
+
explicitName: '?',
|
|
539
|
+
kind: _apidomAst.YamlNodeKind.Scalar
|
|
540
|
+
});
|
|
541
|
+
const anchor = typeof anchorNode !== 'undefined' ? new _apidomAst.YamlAnchor({
|
|
542
|
+
name: anchorNode.text,
|
|
543
|
+
position: CstVisitor.toPosition(anchorNode)
|
|
544
|
+
}) : undefined;
|
|
545
|
+
const scalarNode = new _apidomAst.YamlScalar({
|
|
546
|
+
content: '',
|
|
547
|
+
position: new _apidomAst.Position({
|
|
548
|
+
start: emptyPoint,
|
|
549
|
+
end: emptyPoint
|
|
550
|
+
}),
|
|
551
|
+
tag,
|
|
552
|
+
anchor,
|
|
553
|
+
styleGroup: _apidomAst.YamlStyleGroup.Flow,
|
|
554
|
+
style: _apidomAst.YamlStyle.Plain
|
|
555
|
+
});
|
|
556
|
+
this.registerAnchor(scalarNode);
|
|
557
|
+
return scalarNode;
|
|
558
|
+
}
|
|
532
559
|
}
|
|
533
560
|
var _default = exports.default = CstVisitor;
|