File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,10 @@ const plugin = {
5555 const refPath = splitString [ 0 ]
5656 const pointer = splitString [ 1 ] || ''
5757
58+ if ( pointer . length > 0 && pointer [ 0 ] !== '/' ) {
59+ console . warn ( `WARNING: $ref '${ ref } ' is malformed, a leading '/' is expected after '#'` )
60+ }
61+
5862 let basePath
5963 try {
6064 basePath = ( baseDoc || refPath ) ? absoluteify ( refPath , baseDoc ) : null
Original file line number Diff line number Diff line change 1- import expect from 'expect'
1+ import expect , { createSpy } from 'expect'
22import clone from 'clone'
33import xmock from 'xmock'
44import traverse from 'traverse'
@@ -419,6 +419,23 @@ describe('specmap', function () {
419419 } )
420420 } )
421421
422+ it ( 'should warn about malformed JSON Pointers' , function ( ) {
423+ // for https://github.com/swagger-api/swagger-editor/issues/1560
424+ const oriWarn = console . warn
425+ console . warn = createSpy ( ) . andCallThrough ( )
426+ return mapSpec ( {
427+ spec : {
428+ nested : { one : 1 } ,
429+ another : { $ref : '#nested' }
430+ } ,
431+ plugins : [ plugins . refs ]
432+ } )
433+ . then ( ( res ) => {
434+ console . warn = oriWarn
435+ expect ( console . warn ) . toHaveBeenCalledWith ( 'WARNING: $ref \'http://example.com/doc-a#two\' is malformed, a leading \'/\' is expected after \'#\'' )
436+ } )
437+ } )
438+
422439 it ( 'should resolve internal $refs in arrays' , function ( ) {
423440 return mapSpec ( {
424441 spec : {
You can’t perform that action at this time.
0 commit comments