Support plan
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: 14
- module version: 20.0.3
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...): hapi
- any other relevant information: n.a.
What problem are you trying to solve?
I want to create a plugin that enables transparent yaml parsing of request payload. By transparent I mean that I would create an equivalence between yaml and json and transparently parse yaml and allow it to be used with routes expecting JSON.
My current workaround consists of monkey patching Subtext.parse to do something like:
const origParse = Subtext.parse
Subtext.parse = async function (req, tap, options) {
const { payload, mime } = await origParse.call(this, req, tap, {
...options,
allow: options.allow?.some(isJsonMime)
? [ ...options.allow, 'text/vnd.yaml', 'text/yaml', 'text/x-yaml', 'application/x-yaml' ]
: options.allow,
});
if (options.parse === true && isYamlMime(mime)) {
// Expose Yaml as plain JSON
return { payload: parseYaml(payload), mime: 'application/json' };
}
return { payload, mime };
}
Do you have a new or modified API suggestion to solve the problem?
nope
Support plan
Context
What problem are you trying to solve?
I want to create a plugin that enables transparent
yamlparsing of request payload. By transparent I mean that I would create an equivalence betweenyamlandjsonand transparently parse yaml and allow it to be used with routes expecting JSON.My current workaround consists of monkey patching
Subtext.parseto do something like:Do you have a new or modified API suggestion to solve the problem?
nope