azure-functions-swagger-ui
Version:
A simple npm module that integrates Swagger UI into Azure Functions, providing a user-friendly interface to visualize and interact with your API endpoints. Perfect for documenting and testing Azure Functions with minimal setup.
106 lines (105 loc) • 3.91 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const tmp_path_1 = __importDefault(require("./tmp_path"));
const jsdoc_dir = path.resolve(tmp_path_1.default, 'doc');
function array_jsdoc(fileName, docs_path_array, is_swagger_jsdoc_object) {
const doc_path_start = path.join(jsdoc_dir, fileName);
for (let i = 0; i < is_swagger_jsdoc_object.length; i++) {
if (!is_swagger_jsdoc_object[i])
continue;
const doc = docs_path_array[i];
let data = doc.url;
let doc_path_full;
if (typeof data === 'string') {
doc_path_full = doc_path_start + doc.name + i + '__azfsu__jsdoc.yaml';
}
else {
doc_path_full = doc_path_start + doc.name + i + '__azfsu__jsdoc.json';
data = JSON.stringify(data);
}
doc_path_full = path.normalize(doc_path_full);
// Write the doc content
fs.writeFile(doc_path_full, data, (err) => {
if (err) {
console.error('Error doc the HTML file:', err);
throw err;
}
});
doc.url = doc_path_full;
}
}
function single_jsdoc(fileName, swaggerOptions) {
let doc_path = path.join(jsdoc_dir, fileName);
let data = swaggerOptions.doc_path;
if (typeof data === 'string') {
doc_path += '__azfsu__jsdoc.yaml';
}
else {
doc_path += '__azfsu__jsdoc.json';
data = JSON.stringify(data);
}
doc_path = path.normalize(doc_path);
// Write the doc content
fs.writeFile(doc_path, data, (err) => {
if (err) {
console.error('Error doc the HTML file:', err);
throw err;
}
});
swaggerOptions.doc_path = doc_path;
}
function default_1(fileName, swaggerOptions, is_swagger_jsdoc_object) {
// Create the directory structure for the HTML file(s)
try {
fs.mkdirSync(path.join(jsdoc_dir, path.dirname(fileName)), { recursive: true });
}
catch (err) {
console.error('Error creating doc directory:', err);
throw err;
}
;
if (Array.isArray(swaggerOptions.doc_path)) {
array_jsdoc(fileName, swaggerOptions.doc_path, is_swagger_jsdoc_object);
return;
}
single_jsdoc(fileName, swaggerOptions);
}