diff --git a/lib/commands/extract-xmsexamples.js b/lib/commands/extract-xmsexamples.js index 0e2928f2..7e03428f 100644 --- a/lib/commands/extract-xmsexamples.js +++ b/lib/commands/extract-xmsexamples.js @@ -21,7 +21,7 @@ exports.builder = { alias: 'matchApiVersion', describe: 'Only generate examples if api-version matches.', boolean: true, - default: false + default: true } }; diff --git a/lib/xMsExampleExtractor.js b/lib/xMsExampleExtractor.js index b580362d..127811e1 100644 --- a/lib/xMsExampleExtractor.js +++ b/lib/xMsExampleExtractor.js @@ -65,10 +65,12 @@ class xMsExampleExtractor { let self = this; self.mkdirSync(self.options.output); self.mkdirSync(self.options.output + "/examples"); + self.mkdirSync(self.options.output + "/swagger"); let outputExamples = self.options.output + "/examples/"; let relativeExamplesPath = "../examples/"; let specName = self.specPath.split("/"); + let outputSwagger = self.options.output + "/swagger/" + specName[specName.length - 1].split(".")[0] + ".json" var swaggerObject = require(self.specPath); var SwaggerParser = require('swagger-parser'); @@ -155,11 +157,12 @@ class xMsExampleExtractor { let ref = {}; ref["$ref"] = relativeExamplesPath + exampleFileName; let exampleFriendlyName = fileName + requestMethodFromRecording + pathIndex + entryIndex; + log.debug(`exampleFriendlyName: ${exampleFriendlyName}`); if (!("x-ms-examples" in infoFromOperation)) { infoFromOperation["x-ms-examples"] = {}; } - infoFromOperation["x-ms-examples"][fileName + requestMethodFromRecording + pathIndex + entryIndex] = ref; + infoFromOperation["x-ms-examples"][exampleFriendlyName] = ref; let example = {}; example["parameters"] = {}; example["responses"] = {}; @@ -197,13 +200,15 @@ class xMsExampleExtractor { example['responses'][statusCodeFromRecording]['body'] = ""; } } - fs.writeFile(outputExamples + exampleFileName, JSON.stringify(example, null, 2)); log.info(`Writing x-ms-examples at ${outputExamples + exampleFileName}`); + fs.writeFile(outputExamples + exampleFileName, JSON.stringify(example, null, 2)); } } } } } + log.info(`Writing updated swagger with x-ms-examples at ${outputSwagger}`); + fs.writeFile(outputSwagger, JSON.stringify(swaggerObject, null, 2)); } catch (err) { accErrors[recordingFileName] = err.toString();