From 57e79fce1ff6427d1b58b0cc4cd7ec32ed87266d Mon Sep 17 00:00:00 2001 From: Rohit Gohri Date: Fri, 7 Aug 2020 22:37:32 +0530 Subject: [PATCH 1/2] skip custom methods --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 6e3b84e..c9ddffe 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,7 @@ function enrichSchema(schema){ for(var path in schema.paths){ for(var method in schema.paths[path]){ + if (method.indexOf('x-') === 0) continue; var generatedCode = OpenAPISnippet.getEndpointSnippets(schema, path, method, targets); schema.paths[path][method]["x-codeSamples"] = []; for(var snippetIdx in generatedCode.snippets){ From bcf0f4e5d821a22210c0c30d48467a078bc78a14 Mon Sep 17 00:00:00 2001 From: Rohit Gohri Date: Fri, 7 Aug 2020 23:17:38 +0530 Subject: [PATCH 2/2] add error handling --- index.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index c9ddffe..4a6a285 100644 --- a/index.js +++ b/index.js @@ -16,13 +16,17 @@ function enrichSchema(schema){ for(var method in schema.paths[path]){ if (method.indexOf('x-') === 0) continue; - var generatedCode = OpenAPISnippet.getEndpointSnippets(schema, path, method, targets); - schema.paths[path][method]["x-codeSamples"] = []; - for(var snippetIdx in generatedCode.snippets){ - var snippet = generatedCode.snippets[snippetIdx]; - schema.paths[path][method]["x-codeSamples"][snippetIdx] = { "lang": snippet.title, "source": snippet.content }; - } - + try { + var generatedCode = OpenAPISnippet.getEndpointSnippets(schema, path, method, targets); + schema.paths[path][method]["x-codeSamples"] = []; + for(var snippetIdx in generatedCode.snippets){ + var snippet = generatedCode.snippets[snippetIdx]; + schema.paths[path][method]["x-codeSamples"][snippetIdx] = { "lang": snippet.title, "source": snippet.content }; + } + } + catch (err) { + console.error(`Error while processing "${method}" "${path}"\n`, err); + } } } return schema;