mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
d4df5ea5f7
* first pass * capitalise Swagger and OpenAPI in an error message * use docs from plugin scope * extract variables * check only OpenAPI spec version * feedback * fix config mapping * refactor _generate * remove bool casts * revert refactor * consume docs link Co-authored-by: Opender Singh <opender.singh@konghq.com>
34 lines
944 B
JavaScript
34 lines
944 B
JavaScript
const YAML = require('yaml');
|
|
const o2k = require('openapi-2-kong');
|
|
|
|
module.exports = {
|
|
label: 'Kong for Kubernetes',
|
|
docsLink: 'https://docs.insomnia.rest/insomnia/kong-for-kubernetes',
|
|
generate: async ({ contents, formatVersion }) => {
|
|
const isSupported = formatVersion && formatVersion.match(/^3./);
|
|
|
|
if (!isSupported) {
|
|
return {
|
|
document: null,
|
|
error: `Unsupported OpenAPI spec format ${formatVersion}`,
|
|
};
|
|
}
|
|
|
|
try {
|
|
const result = await o2k.generateFromString(contents, 'kong-for-kubernetes');
|
|
const yamlDocs = result.documents.map(d => YAML.stringify(d));
|
|
|
|
return {
|
|
// Join the YAML docs with "---" and strip any extra newlines surrounding them
|
|
document: yamlDocs.join('\n---\n').replace(/\n+---\n+/g, '\n---\n'),
|
|
error: null,
|
|
};
|
|
} catch (err) {
|
|
return {
|
|
document: null,
|
|
error: err.message,
|
|
};
|
|
}
|
|
},
|
|
};
|