Skip to content

Commit 02a1723

Browse files
committed
test: Add additional coverage for addQuotesToRefInString
1 parent 73869c3 commit 02a1723

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/util-file.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,40 @@ describe('openapi-format CLI file tests', () => {
419419
const output = addQuotesToRefInString(input);
420420
expect(output).toBe(input);
421421
});
422+
423+
test('should parse unquoted local $ref values that start with #', async () => {
424+
const yamlString = 'schema:\n $ref: #/components/schemas/Example';
425+
const result = await parseString(yamlString);
426+
427+
expect(result).toEqual({
428+
schema: {
429+
$ref: '#/components/schemas/Example'
430+
}
431+
});
432+
});
433+
434+
test('should parse unquoted external $ref values with fragments', async () => {
435+
const yamlString = 'schema:\n $ref: ./common.yaml#/components/schemas/Example';
436+
const result = await parseString(yamlString);
437+
438+
expect(result).toEqual({
439+
schema: {
440+
$ref: './common.yaml#/components/schemas/Example'
441+
}
442+
});
443+
});
444+
445+
test('should stringify $ref values with quotes in YAML output', async () => {
446+
const obj = {
447+
schema: {
448+
$ref: '#/components/schemas/Example'
449+
}
450+
};
451+
452+
const result = await stringify(obj, {format: 'yaml'});
453+
454+
expect(result).toContain("$ref: '#/components/schemas/Example'");
455+
});
422456
});
423457

424458
describe('analyzeOpenApi function', () => {

0 commit comments

Comments
 (0)