Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"xmock": "^0.3.0"
},
"dependencies": {
"@kyleshockey/object-assign-deep": "^0.4.0",
"babel-runtime": "^6.23.0",
"btoa": "1.1.2",
"cookie": "^0.3.1",
Expand All @@ -77,8 +78,8 @@
"isomorphic-form-data": "0.0.1",
"js-yaml": "^3.8.1",
"lodash": "^4.16.2",
"@kyleshockey/object-assign-deep": "^0.4.0",
"qs": "^6.3.0",
"querystring-browser": "^1.0.4",
"url": "^0.11.0",
"utf8-bytes": "0.0.1",
"utfstring": "^2.0.0"
Expand Down
5 changes: 3 additions & 2 deletions src/specmap/lib/refs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {fetch} from 'cross-fetch'
import qs from 'querystring-browser'
import url from 'url'
import lib from '../lib'
import createError from '../lib/create-error'
Expand Down Expand Up @@ -303,15 +304,15 @@ function unescapeJsonPointerToken(token) {
if (typeof token !== 'string') {
return token
}
return token.replace(/~1/g, '/').replace(/~0/g, '~')
return qs.unescape(token.replace(/~1/g, '/').replace(/~0/g, '~'))
}

/**
* Escapes a JSON pointer.
* @api public
*/
function escapeJsonPointerToken(token) {
return token.replace(/~/g, '~0').replace(/\//g, '~1')
return qs.escape(token.replace(/~/g, '~0').replace(/\//g, '~1'))
}

function arrayToJsonPointer(arr) {
Expand Down
63 changes: 63 additions & 0 deletions test/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,69 @@ describe('resolver', () => {
}
})

it('should be able to resolve $refs with percent-encoded values', () => {
// Given
const spec = {
one: {
uno: 1,
$ref: '#/value%20two'
},
'value two': {
duos: 2
}
}

// When
return Swagger.resolve({spec, allowMetaPatches: false})
.then(handleResponse)

// Then
function handleResponse(obj) {
expect(obj.errors).toEqual([])
expect(obj.spec).toEqual({
one: {
duos: 2
},
'value two': {
duos: 2
}
})
}
})

it('should tolerate $refs with raw values that should be percent-encoded', () => {
// NOTE: this is for compatibility and can be removed in the next major
// REVIEW for v4

// Given
const spec = {
one: {
uno: 1,
$ref: '#/value two'
},
'value two': {
duos: 2
}
}

// When
return Swagger.resolve({spec, allowMetaPatches: false})
.then(handleResponse)

// Then
function handleResponse(obj) {
expect(obj.errors).toEqual([])
expect(obj.spec).toEqual({
one: {
duos: 2
},
'value two': {
duos: 2
}
})
}
})

it('should be able to resolve circular $refs when a baseDoc is provided', () => {
// Given
const spec = {
Expand Down