@mintlify/validation
Advanced tools
Comparing version
@@ -34,3 +34,3 @@ import lcm from 'lcm'; | ||
export function reduceToSumOfProducts(schemaOrRef, componentSchemas, opts) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; | ||
let schema; | ||
@@ -53,3 +53,36 @@ if ('$ref' in schemaOrRef) { | ||
} | ||
if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) && ((_d = schema.discriminator) === null || _d === void 0 ? void 0 : _d.mapping) && !schema.oneOf && !schema.allOf) { | ||
if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) && schema.type === 'array' && ((_d = schema.discriminator) === null || _d === void 0 ? void 0 : _d.mapping)) { | ||
const discriminator = schema.discriminator; | ||
const baseItemSchema = schema.items; | ||
delete schema.discriminator; | ||
const discriminatedRefs = Object.values((_e = discriminator.mapping) !== null && _e !== void 0 ? _e : {}).map((ref) => ({ | ||
$ref: ref, | ||
})); | ||
let extraItems = []; | ||
if ('oneOf' in baseItemSchema) { | ||
extraItems = | ||
(_g = (_f = baseItemSchema.oneOf) === null || _f === void 0 ? void 0 : _f.filter((item) => { | ||
var _a; | ||
if ('$ref' in item) { | ||
return !Object.values((_a = discriminator.mapping) !== null && _a !== void 0 ? _a : {}).includes(item.$ref); | ||
} | ||
return true; | ||
})) !== null && _g !== void 0 ? _g : []; | ||
delete baseItemSchema.oneOf; | ||
} | ||
const processedDiscriminatedTypes = discriminatedRefs.map((refObj) => { | ||
var _a, _b; | ||
const dereferenced = dereference('schemas', refObj.$ref, componentSchemas); | ||
if (!dereferenced) | ||
return baseItemSchema; | ||
const resolvedBaseSchema = '$ref' in baseItemSchema | ||
? dereference('schemas', baseItemSchema.$ref, componentSchemas) | ||
: baseItemSchema; | ||
const baseProperties = (_a = resolvedBaseSchema === null || resolvedBaseSchema === void 0 ? void 0 : resolvedBaseSchema.properties) !== null && _a !== void 0 ? _a : {}; | ||
const dereferencedProperties = (_b = dereferenced.properties) !== null && _b !== void 0 ? _b : {}; | ||
return Object.assign(Object.assign(Object.assign({}, baseItemSchema), dereferenced), { properties: Object.assign(Object.assign({}, baseProperties), dereferencedProperties) }); | ||
}); | ||
schema = Object.assign(Object.assign({}, schema), { items: Object.assign(Object.assign({}, baseItemSchema), { oneOf: [...processedDiscriminatedTypes, ...extraItems] }) }); | ||
} | ||
else if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) && ((_h = schema.discriminator) === null || _h === void 0 ? void 0 : _h.mapping) && !schema.oneOf && !schema.allOf) { | ||
const properties = Object.values(schema.discriminator.mapping); | ||
@@ -88,5 +121,5 @@ if (properties.length) { | ||
: []; | ||
const reducedOneOfs = (_e = schema.oneOf) === null || _e === void 0 ? void 0 : _e.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas)); | ||
const reducedAnyOfs = (_f = schema.anyOf) === null || _f === void 0 ? void 0 : _f.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas)); | ||
const reducedAllOfs = (_g = schema.allOf) === null || _g === void 0 ? void 0 : _g.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas)); | ||
const reducedOneOfs = (_j = schema.oneOf) === null || _j === void 0 ? void 0 : _j.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas)); | ||
const reducedAnyOfs = (_k = schema.anyOf) === null || _k === void 0 ? void 0 : _k.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas)); | ||
const reducedAllOfs = (_l = schema.allOf) === null || _l === void 0 ? void 0 : _l.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas)); | ||
const combinedOneOfs = reducedOneOfs ? [addIncrementalSchemas(reducedOneOfs)] : []; | ||
@@ -93,0 +126,0 @@ const combinedAnyOfs = reducedAnyOfs ? [addIncrementalSchemas(reducedAnyOfs)] : []; |
{ | ||
"name": "@mintlify/validation", | ||
"version": "0.1.382", | ||
"version": "0.1.383", | ||
"description": "Validates mint.json files", | ||
@@ -62,3 +62,3 @@ "author": "Mintlify, Inc.", | ||
}, | ||
"gitHead": "e55dd52d05bdb1379384cf7517ad6feade37cefe" | ||
"gitHead": "7aa4b983500e4e4e92716b5d104db0066c151a1a" | ||
} |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1852325
0.12%43187
0.08%