Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 97babae

Browse files
committed
fix(oas3): support empty yaml !!set
1 parent fb11b3b commit 97babae

File tree

2 files changed

+72
-49
lines changed

2 files changed

+72
-49
lines changed

packages/fury-adapter-oas3-parser/lib/parser/parseYAML.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ function yamlToObject(node, annotations, context) {
3737
}
3838

3939
function yamlToArray(node, annotations, context) {
40-
return new context.namespace.elements.Array(node.value.map(nodes => convert(nodes, annotations, context)));
40+
if (node.value) {
41+
return new context.namespace.elements.Array(node.value.map(nodes => convert(nodes, annotations, context)));
42+
}
43+
44+
return new context.namespace.elements.Array();
4145
}
4246

4347
function convert(node, annotations, context) {

packages/fury-adapter-oas3-parser/test/unit/parser/parseYAML-test.js

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -318,54 +318,73 @@ describe('#parseYAML', () => {
318318
expect(warning).to.have.sourceMapEndColumn(13);
319319
});
320320

321-
it('can parse a set into an array element', () => {
322-
const element = parseYAML('!!set\n - one\n - two', context);
323-
324-
expect(element).to.be.instanceof(namespace.elements.ParseResult);
325-
expect(element.length).to.equal(2);
326-
327-
const arry = element.first;
328-
329-
expect(arry).to.be.instanceof(namespace.elements.Array);
330-
expect(arry.toValue()).to.deep.equal(['one', 'two']);
331-
expect(arry).to.have.sourceMapStart(0);
332-
expect(arry).to.have.sourceMapOffset(21);
333-
expect(arry).to.have.sourceMapStartLine(1);
334-
expect(arry).to.have.sourceMapStartColumn(1);
335-
expect(arry).to.have.sourceMapEndLine(3);
336-
expect(arry).to.have.sourceMapEndColumn(8);
337-
338-
const entryOne = arry.get(0);
339-
340-
expect(entryOne).to.be.instanceof(namespace.elements.String);
341-
expect(entryOne.toValue()).to.equal('one');
342-
expect(entryOne).to.have.sourceMapStart(10);
343-
expect(entryOne).to.have.sourceMapOffset(3);
344-
expect(entryOne).to.have.sourceMapStartLine(2);
345-
expect(entryOne).to.have.sourceMapStartColumn(5);
346-
expect(entryOne).to.have.sourceMapEndLine(2);
347-
expect(entryOne).to.have.sourceMapEndColumn(8);
348-
349-
const entryTwo = arry.get(1);
350-
351-
expect(entryTwo).to.be.instanceof(namespace.elements.String);
352-
expect(entryTwo.toValue()).to.equal('two');
353-
expect(entryTwo).to.have.sourceMapStart(18);
354-
expect(entryTwo).to.have.sourceMapOffset(3);
355-
expect(entryTwo).to.have.sourceMapStartLine(3);
356-
expect(entryTwo).to.have.sourceMapStartColumn(5);
357-
expect(entryTwo).to.have.sourceMapEndLine(3);
358-
expect(entryTwo).to.have.sourceMapEndColumn(8);
359-
360-
const warning = element.second;
361-
expect(warning).to.be.instanceof(namespace.elements.Annotation);
362-
expect(warning.toValue()).to.equal('Interpreting YAML !!set as array');
363-
expect(warning).to.have.sourceMapStart(0);
364-
expect(warning).to.have.sourceMapOffset(21);
365-
expect(warning).to.have.sourceMapStartLine(1);
366-
expect(warning).to.have.sourceMapStartColumn(1);
367-
expect(warning).to.have.sourceMapEndLine(3);
368-
expect(warning).to.have.sourceMapEndColumn(8);
321+
describe('set', () => {
322+
it('can parse a set into an array element', () => {
323+
const parseResult = parseYAML('!!set\n - one\n - two', context);
324+
325+
expect(parseResult).to.be.instanceof(namespace.elements.ParseResult);
326+
expect(parseResult.length).to.equal(2);
327+
328+
const array = parseResult.first;
329+
330+
expect(array).to.be.instanceof(namespace.elements.Array);
331+
expect(array.toValue()).to.deep.equal(['one', 'two']);
332+
expect(array).to.have.sourceMapStart(0);
333+
expect(array).to.have.sourceMapOffset(21);
334+
expect(array).to.have.sourceMapStartLine(1);
335+
expect(array).to.have.sourceMapStartColumn(1);
336+
expect(array).to.have.sourceMapEndLine(3);
337+
expect(array).to.have.sourceMapEndColumn(8);
338+
339+
const entryOne = array.get(0);
340+
expect(entryOne).to.be.instanceof(namespace.elements.String);
341+
expect(entryOne.toValue()).to.equal('one');
342+
expect(entryOne).to.have.sourceMapStart(10);
343+
expect(entryOne).to.have.sourceMapOffset(3);
344+
expect(entryOne).to.have.sourceMapStartLine(2);
345+
expect(entryOne).to.have.sourceMapStartColumn(5);
346+
expect(entryOne).to.have.sourceMapEndLine(2);
347+
expect(entryOne).to.have.sourceMapEndColumn(8);
348+
349+
const entryTwo = array.get(1);
350+
expect(entryTwo).to.be.instanceof(namespace.elements.String);
351+
expect(entryTwo.toValue()).to.equal('two');
352+
expect(entryTwo).to.have.sourceMapStart(18);
353+
expect(entryTwo).to.have.sourceMapOffset(3);
354+
expect(entryTwo).to.have.sourceMapStartLine(3);
355+
expect(entryTwo).to.have.sourceMapStartColumn(5);
356+
expect(entryTwo).to.have.sourceMapEndLine(3);
357+
expect(entryTwo).to.have.sourceMapEndColumn(8);
358+
359+
const warning = parseResult.second;
360+
expect(warning).to.be.instanceof(namespace.elements.Annotation);
361+
expect(warning.toValue()).to.equal('Interpreting YAML !!set as array');
362+
expect(warning).to.have.sourceMapStart(0);
363+
expect(warning).to.have.sourceMapOffset(21);
364+
expect(warning).to.have.sourceMapStartLine(1);
365+
expect(warning).to.have.sourceMapStartColumn(1);
366+
expect(warning).to.have.sourceMapEndLine(3);
367+
expect(warning).to.have.sourceMapEndColumn(8);
368+
});
369+
370+
it('can parse empty set into an array element', () => {
371+
const parseResult = parseYAML('!!set', context);
372+
373+
expect(parseResult).to.be.instanceof(namespace.elements.ParseResult);
374+
expect(parseResult.length).to.equal(2);
375+
376+
const array = parseResult.first;
377+
expect(array).to.be.instanceof(namespace.elements.Array);
378+
expect(array.length).to.equal(0);
379+
expect(array).to.have.sourceMapStart(0);
380+
expect(array).to.have.sourceMapOffset(5);
381+
expect(array).to.have.sourceMapStartLine(1);
382+
expect(array).to.have.sourceMapStartColumn(1);
383+
expect(array).to.have.sourceMapEndLine(1);
384+
expect(array).to.have.sourceMapEndColumn(6);
385+
386+
expect(parseResult).to.contain.warning('Interpreting YAML !!set as array');
387+
});
369388
});
370389

371390
it('can accumulate annotations during YAML translation', () => {

0 commit comments

Comments
 (0)