UNPKG

@rxap/nest-open-api

Version:

This package provides tools and utilities for integrating OpenAPI specifications into NestJS applications. It includes features for handling upstream API requests, managing server configurations, and generating OpenAPI documentation. It also offers interc

21 lines (20 loc) 913 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetOpenapiJson = GetOpenapiJson; const common_1 = require("@nestjs/common"); const fs_1 = require("fs"); const path_1 = require("path"); function GetOpenapiJson(appRoot, logger = console) { const openapiFilePath = (0, path_1.join)(appRoot, 'openapi.json'); if ((0, fs_1.existsSync)(openapiFilePath)) { try { return JSON.parse((0, fs_1.readFileSync)(openapiFilePath).toString('utf-8')); } catch (e) { logger.error(`openapi.json parse error: ${e.message}`, undefined, 'GetOpenapiJson'); throw new common_1.InternalServerErrorException(`openapi.json parse error: ${e.message}`); } } logger.error(`openapi.json not found in ${appRoot}`, undefined, 'GetOpenapiJson'); throw new common_1.InternalServerErrorException('openapi.json not found'); }