addressing code review feedbacks
This commit is contained in:
Родитель
9242594058
Коммит
474e6c59a0
|
@ -21,7 +21,7 @@ exports.builder = {
|
|||
alias: 'matchApiVersion',
|
||||
describe: 'Only generate examples if api-version matches.',
|
||||
boolean: true,
|
||||
default: false
|
||||
default: true
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Загрузка…
Ссылка в новой задаче