File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' , ( ) => {
You can’t perform that action at this time.
0 commit comments