UNPKG

@redocly/openapi-core

Version:

See https://github.com/Redocly/redocly-cli

35 lines 1.71 kB
import { isRef } from '../../ref-utils.js'; import { getOwn } from '../../utils.js'; export const NoRequiredSchemaPropertiesUndefined = () => { return { Schema: { enter(schema, { location, report, resolve }) { if (!schema.required) return; const visitedSchemas = new Set(); const elevateProperties = (schema, from) => { // Check if the schema has been visited before processing it if (visitedSchemas.has(schema)) { return {}; } visitedSchemas.add(schema); if (isRef(schema)) { const resolved = resolve(schema, from); return elevateProperties(resolved.node, resolved.location?.source.absoluteRef); } return Object.assign({}, schema.properties, ...(schema.allOf?.map((s) => elevateProperties(s, from)) ?? []), ...(schema.anyOf?.map((s) => elevateProperties(s, from)) ?? [])); }; const allProperties = elevateProperties(schema); for (const [i, requiredProperty] of schema.required.entries()) { if (!allProperties || getOwn(allProperties, requiredProperty) === undefined) { report({ message: `Required property '${requiredProperty}' is undefined.`, location: location.child(['required', i]), }); } } }, }, }; }; //# sourceMappingURL=no-required-schema-properties-undefined.js.map