This commit is contained in:
Amar Zavery 2017-08-30 09:06:55 -07:00
Родитель 278b435652
Коммит 77ad3161eb
2 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -571,4 +571,15 @@ exports.relaxModelLikeEntities = function relaxModelLikeEntities(model) {
}
}
return model;
}
/**
* Sanitizes the file name by replacing special characters with
* empty string and by replacing space(s) with _.
* @param {string} str - The string to be sanitized.
* @returns {string} result - The sanitized string.
*/
exports.sanitizeFileName = function sanitizeFileName(str) {
let result = str ? str.replace(/[{}\[\]'";\(\)#@~`!%&\^\$\+=,\/\\?<>\|\*:]/ig, '').replace(/(\s+)/ig, '_') : str;
return result;
}

Просмотреть файл

@ -246,10 +246,12 @@ class WireFormatGenerator {
let xmsExamples = operation[Constants.xmsExamples];
if (xmsExamples) {
for (let scenario in xmsExamples) {
let xmsExample = xmsExamples[scenario].value;
//If we do not see the value property then we assume that the swagger spec had x-ms-examples references resolved.
//Then we do not need to access the value property. At the same time the file name for wire-format will be the sanitized scenario name.
let xmsExample = xmsExamples[scenario].value || xmsExamples[scenario];
let sampleRequest = self.processRequest(operation, xmsExample.parameters);
let sampleResponses = self.processXmsExampleResponses(operation, xmsExample.responses);
let exampleFileName = path.basename(xmsExamples[scenario].filePath);
let exampleFileName = xmsExamples[scenario].filePath ? path.basename(xmsExamples[scenario].filePath) : `${utils.sanitizeFileName(scenario)}.json`;
let wireformatFileName = `${exampleFileName.substring(0, exampleFileName.indexOf(path.extname(exampleFileName)))}.`;
wireformatFileName += self.emitYaml ? 'yml' : 'md';
let fileName = path.join(self.wireFormatDir, wireformatFileName);