@mintlify/validation
Advanced tools
Comparing version
@@ -10,2 +10,3 @@ import { OpenAPIV3_1 } from 'openapi-types'; | ||
refIdentifier?: string; | ||
_depth?: number; | ||
}; | ||
@@ -44,2 +45,3 @@ export type SumOfProducts = SimpleSchema[][]; | ||
isRoot?: true; | ||
_depth?: number; | ||
}): SumOfProducts; | ||
@@ -46,0 +48,0 @@ /** |
import lcm from 'lcm'; | ||
import { inferType } from './SchemaConverter.js'; | ||
import { addKeyIfDefined, copyExampleIfDefined, copyKeyIfDefined, dereference, recursivelyFindDescription, stringFileFormats, structuredDataContentTypes, } from './utils.js'; | ||
function hasSchemaContent(schema) { | ||
const meaningfulKeys = Object.keys(schema).filter((key) => !key.startsWith('_')); | ||
return meaningfulKeys.length > 0; | ||
} | ||
/** | ||
@@ -34,4 +38,5 @@ * Given an OpenAPI 3.1 SchemaObject or ReferenceObject containing any number of | ||
export function reduceToSumOfProducts(schemaOrRef, componentSchemas, opts) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; | ||
let schema; | ||
const _depth = (_a = opts === null || opts === void 0 ? void 0 : opts._depth) !== null && _a !== void 0 ? _a : 0; | ||
if ('$ref' in schemaOrRef) { | ||
@@ -43,3 +48,3 @@ const refIdentifier = schemaOrRef.$ref; | ||
if (dereferencedSchema.type === undefined && | ||
((_a = dereferencedSchema.allOf) === null || _a === void 0 ? void 0 : _a.find((subschema) => 'type' in subschema && subschema.type === 'object'))) { | ||
((_b = dereferencedSchema.allOf) === null || _b === void 0 ? void 0 : _b.find((subschema) => 'type' in subschema && subschema.type === 'object'))) { | ||
dereferencedSchema.type = 'object'; | ||
@@ -49,3 +54,3 @@ } | ||
// @ts-expect-error some customers use title even though it's not part of the spec | ||
title: (_b = schemaOrRef.title) !== null && _b !== void 0 ? _b : dereferencedSchema.title, refIdentifier: refIdentifier, description: (_c = schemaOrRef.description) !== null && _c !== void 0 ? _c : dereferencedSchema.description }); | ||
title: (_c = schemaOrRef.title) !== null && _c !== void 0 ? _c : dereferencedSchema.title, refIdentifier: refIdentifier, description: (_d = schemaOrRef.description) !== null && _d !== void 0 ? _d : dereferencedSchema.description }); | ||
} | ||
@@ -55,13 +60,14 @@ else { | ||
} | ||
if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) && schema.type === 'array' && ((_d = schema.discriminator) === null || _d === void 0 ? void 0 : _d.mapping)) { | ||
if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) && schema.type === 'array' && ((_e = schema.discriminator) === null || _e === void 0 ? void 0 : _e.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) => ({ | ||
const discriminatedRefs = Object.values((_f = discriminator.mapping) !== null && _f !== void 0 ? _f : {}).map((ref) => ({ | ||
$ref: ref, | ||
})); | ||
let extraItems = []; | ||
// depth + 1 because we go one level deeper when we process this oneOf | ||
if ('oneOf' in baseItemSchema) { | ||
extraItems = | ||
(_g = (_f = baseItemSchema.oneOf) === null || _f === void 0 ? void 0 : _f.filter((item) => { | ||
(_h = (_g = baseItemSchema.oneOf) === null || _g === void 0 ? void 0 : _g.filter((item) => { | ||
var _a; | ||
@@ -72,5 +78,7 @@ if ('$ref' in item) { | ||
return true; | ||
})) !== null && _g !== void 0 ? _g : []; | ||
})) !== null && _h !== void 0 ? _h : []; | ||
extraItems = extraItems.map((item) => (Object.assign(Object.assign({}, item), { _depth: _depth + 1 }))); | ||
delete baseItemSchema.oneOf; | ||
} | ||
// depth + 1 because we go one level deeper when we process the discriminated types into oneOf | ||
const processedDiscriminatedTypes = discriminatedRefs.map((refObj) => { | ||
@@ -80,3 +88,3 @@ var _a, _b; | ||
if (!dereferenced) | ||
return baseItemSchema; | ||
return Object.assign(Object.assign({}, baseItemSchema), { _depth: _depth + 1 }); | ||
const resolvedBaseSchema = '$ref' in baseItemSchema | ||
@@ -87,13 +95,11 @@ ? dereference('schemas', baseItemSchema.$ref, componentSchemas) | ||
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) }); | ||
return Object.assign(Object.assign(Object.assign({}, baseItemSchema), dereferenced), { properties: Object.assign(Object.assign({}, baseProperties), dereferencedProperties), _depth: _depth + 1 }); | ||
}); | ||
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) { | ||
else if ((opts === null || opts === void 0 ? void 0 : opts.isRoot) && ((_j = schema.discriminator) === null || _j === void 0 ? void 0 : _j.mapping) && !schema.oneOf && !schema.allOf) { | ||
const properties = Object.values(schema.discriminator.mapping); | ||
if (properties.length) { | ||
delete schema.discriminator; | ||
schema = Object.assign(Object.assign({}, schema), { | ||
// @ts-expect-error allOf is indeed a valid type for schema | ||
allOf: [ | ||
schema = Object.assign(Object.assign({}, schema), { allOf: [ | ||
{ | ||
@@ -112,5 +118,5 @@ oneOf: [ | ||
if (!schema.oneOf && !schema.allOf && !schema.anyOf && !Array.isArray(schema.type) && !nullable) { | ||
return [[schema]]; | ||
return [[Object.assign(Object.assign({}, schema), { _depth: _depth })]]; | ||
} | ||
const baseSchema = Object.assign({}, schema); | ||
const baseSchema = Object.assign(Object.assign({}, schema), { _depth: _depth }); | ||
delete baseSchema.oneOf; | ||
@@ -124,8 +130,8 @@ delete baseSchema.anyOf; | ||
} | ||
const baseSchemaArr = Object.keys(baseSchema).length > 0 | ||
const baseSchemaArr = hasSchemaContent(baseSchema) | ||
? [baseSchemaTypes.map((type) => [Object.assign(Object.assign({}, baseSchema), { type })])] | ||
: []; | ||
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 reducedOneOfs = (_k = schema.oneOf) === null || _k === void 0 ? void 0 : _k.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas, { _depth: _depth + 1 })); | ||
const reducedAnyOfs = (_l = schema.anyOf) === null || _l === void 0 ? void 0 : _l.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas, { _depth: _depth + 1 })); | ||
const reducedAllOfs = (_m = schema.allOf) === null || _m === void 0 ? void 0 : _m.map((subschema) => reduceToSumOfProducts(subschema, componentSchemas, { _depth: _depth + 1 })); | ||
const combinedOneOfs = reducedOneOfs ? [addIncrementalSchemas(reducedOneOfs)] : []; | ||
@@ -191,2 +197,8 @@ const combinedAnyOfs = reducedAnyOfs ? [addIncrementalSchemas(reducedAnyOfs)] : []; | ||
schemas.sort((a, b) => { | ||
var _a, _b; | ||
const aDepth = (_a = a._depth) !== null && _a !== void 0 ? _a : 0; | ||
const bDepth = (_b = b._depth) !== null && _b !== void 0 ? _b : 0; | ||
if (aDepth !== bDepth) { | ||
return aDepth - bDepth; | ||
} | ||
if (a.type && !b.type) | ||
@@ -331,6 +343,6 @@ return -1; | ||
!curr.discriminator && | ||
!curr.description.includes(acc.description)) { | ||
acc.description = `${curr.description}\n${acc.description}`; | ||
!acc.description.includes(curr.description)) { | ||
acc.description = `${acc.description}\n${curr.description}`; | ||
} | ||
else { | ||
else if (!acc.description) { | ||
copyKeyIfDefined('description', curr, acc); | ||
@@ -337,0 +349,0 @@ } |
{ | ||
"name": "@mintlify/validation", | ||
"version": "0.1.388", | ||
"version": "0.1.389", | ||
"description": "Validates mint.json files", | ||
@@ -62,3 +62,3 @@ "author": "Mintlify, Inc.", | ||
}, | ||
"gitHead": "899a9bad35fee9d26e14691bc49b3a16231448b2" | ||
"gitHead": "bd32735db6be24c5bc36f5fc10adb6ecf5d17cc7" | ||
} |
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
1853913
0.06%43199
0.03%