UNPKG

@sasonarik/nextapi-swagger

Version:

CLI tool to generate Next.js API routes and types from Swagger/OpenAPI specs

24 lines (23 loc) 784 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchSwaggerDocs = fetchSwaggerDocs; const axios_1 = __importDefault(require("axios")); const chalk_1 = __importDefault(require("chalk")); async function fetchSwaggerDocs(urls) { if (urls.length > 1) { console.log(chalk_1.default.redBright("❌ Just enter one url!")); return []; } const results = []; let i = 1; for (const url of urls) { const res = await axios_1.default.get(url); const spec = res.data; results.push({ url, spec, apiBase: `apiBase${i}` }); i++; } return results; }