UNPKG

@open-rpc/schema-utils-js

Version:

<center> <span> <img alt="CircleCI branch" src="https://img.shields.io/circleci/project/github/open-rpc/schema-utils-js/master.svg"> <img src="https://codecov.io/gh/open-rpc/schema-utils-js/branch/master/graph/badge.svg" /> <img alt="npm" sr

41 lines (40 loc) 2.04 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); /** * Applies extension specifications to an OpenRPC document by modifying the meta schema * @param document - The OpenRPC document containing x-extensions * @param metaSchema - The meta schema to extend * @returns The modified meta schema with extensions applied * @throws {Error} If the schema definition doesn't exist or if extension name conflicts */ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any function applyExtensionSpec(document, metaSchema) { var extendedMetaSchema = metaSchema; if (!document["x-extensions"]) return extendedMetaSchema; // eslint-disable-next-line @typescript-eslint/no-explicit-any document["x-extensions"].forEach(function (extension) { var name = extension.name, schema = extension.schema, summary = extension.summary, description = extension.description, restricted = extension.restricted; restricted.forEach(function (schemaDefinition) { var def = extendedMetaSchema.definitions[schemaDefinition]; if (!def) throw new Error("".concat(schemaDefinition, " does not exist, cannot apply extension ").concat(name)); if (def.properties[name]) throw new Error("".concat(name, " already exists in ").concat(schemaDefinition, ", cannot apply extension ").concat(name)); def.properties[name] = __assign({ title: name, description: description, summary: summary }, schema); }); }); return extendedMetaSchema; } exports.default = applyExtensionSpec;