sway: Getting 'UNRESOLVABLE_REFERENCE' Error even though the definition is present in the swagger spec
Output
{ errors:
[ { code: 'INVALID_RESPONSE_BODY',
errors:
[ { code: 'UNRESOLVABLE_REFERENCE',
params: [ '#/definitions/RouteFilter' ],
message: 'Reference could not be resolved: #/definitions/RouteFilter',
path: [] } ],
message: 'Invalid body: Reference could not be resolved: #/definitions/RouteFilter',
path: [] } ],
warnings: [] }
###########################################################
.....Printing the important parts of operation object for reference...........
###########################################################
operation.responseObjects[0].definitionFullyResolved.schema: { '$ref': '#/definitions/RouteFilter' }
operation.definitionFullyResolved.responses['200'].schema: { '$ref': '#/definitions/RouteFilter' }
- The definition “RouteFilter” is actually present in the definitions section of the spec. It can be seen over here.
- I have debugged this to the point where
helper.validateAgainstSchema(validator, schema, value)is called. - The problem is that schema is not fully resolved by json-refs. Hence z-schema validator gives the ‘UNRESOLVABLE_REFERENCE’ error.
Can you please help me find out what is going on here?
Link to the spec is here.
Please run this script to verify the behavior.
var Sway = require('sway'),
util = require('util');
var specUrl = 'https://gist.githubusercontent.com/amarzavery/0a27e2bb3558ed3ef81744ed9c3fa5a3/raw/786f1c4245adcfe69266b8af65d79466a141c43e/spec.json';
var options = { definition: specUrl };
Sway.create(options)
.then(function (api) {
let operations = api.getOperations();
let operation = operations[1];
if (operation.operationId === 'RouteFilters_Get') {
let responseWrapper = {
statusCode: '200',
body: operation['x-ms-examples']['RouteFilterGet']['responses']['200']['body'],
headers: {
'content-type': 'application/json'
}
};
let result = operation.validateResponse(responseWrapper);
console.dir(result, {depth: null, colors: true});
console.log('###########################################################');
console.log('.....Printing the operation object for reference...........')
console.log('###########################################################\n');
console.log('operation.responseObjects[0].definitionFullyResolved.schema: ' + util.inspect(operation.responseObjects[0].definitionFullyResolved.schema, {depth: null}));
console.log('\noperation.definitionFullyResolved.responses[\'200\'].schema: ' + util.inspect(operation.definitionFullyResolved.responses['200'].schema, {depth: null}));
} else {
console.log( operation.operationId + ' is not the operation we are looking for.');
}
}, function (err) {
console.error(err.stack);
});
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 32 (20 by maintainers)
You can use
npm install --save apigee-127/sway#master.I can confirm this. I’ll look into it.