UNPKG

openapi-modifier

Version:

This package allows you to automate the process of modifying OpenAPI specifications by applying a set of predefined rules

32 lines (31 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.configSchema = void 0; const zod_1 = require("zod"); const each_schema_1 = require("../common/utils/iterators/each-schema"); const refs_1 = require("../common/utils/refs"); const configSchema = zod_1.z.object({ showUnusedWarning: zod_1.z.boolean().optional(), }).strict(); exports.configSchema = configSchema; const processor = { configSchema, defaultConfig: { showUnusedWarning: false, }, processDocument: (openAPIFile, config, logger) => { const { showUnusedWarning } = config; let usageCount = 0; (0, each_schema_1.forEachSchema)(openAPIFile, (schema) => { if (!(0, refs_1.checkIsRefSchema)(schema) && (schema === null || schema === void 0 ? void 0 : schema.maxItems) !== undefined) { delete schema.maxItems; usageCount += 1; } }); if (usageCount === 0 && showUnusedWarning) { logger.warning(`Not found schemas with max-items!`); } return openAPIFile; }, }; exports.default = processor;