I'm trying to write a plugin which works in the response context and cannot access any environment values when handling the response. It would also be necessary to view the request ion the same context.
Context - I'm trying to write a plugin which validates a response body against a path in an API spec. I don't want to hardcode the spec file location on disk and make those assumptions. I want to be able to set up a different spec file by directing users to create a key called schema which will be a string with an absolute path that the response handlers can access.
Pseudo:
const fs = require('fs');
module.exports.responseHooks = [
context => {
let body = context.response.getBody();
if (body !== null) {
let schemaLocation = context.response.getEnvironmentVariable('schema');
if (schemaLocation !== undefined && fs.exists(schemaLocation)) {
// does validation work here
}
}
}
];
What you'll also notice is that where the validation work needs to happen, I would need to know the request method and endpoint so that I can dynamically search the schema based on path / method so really, the context in a response needs to have the request context available as well (minus any methods that can no longer apply - setHeader and other set methods for example).
馃憢 Thanks for opening your first issue! If you're reporting a 馃悶 bug, please make sure
you include steps to reproduce it. If you're requesting a feature 馃巵, please provide real
use cases that would benefit. 馃應
To help make this a smooth process, please be sure you have first read the
contributing guidelines.
Accessing the request should be easy to add. Environment hopefully as well. I'll try and get these new APIs into the next release!
This will work in the next release! 馃榾
module.exports.responseHooks = [
context => {
console.log('ENV', context.request.getEnvironmentVariable('foo'));
}
];
Most helpful comment
This will work in the next release! 馃榾