import*as l from"path";import{lintDocument as p,getTotals as b,getLineColLocation as y,Source as g,getCodeframe as v}from"@redocly/openapi-core";import{slash as d}from"../../../utils/path/slash.js";import{getUniqueProblemsCount as P}from"./shared-utils.js";const m=20;async function R(f,o,t,e){const s=l.resolve(t.fs.cwd,f.relativePath),r=o.resolvedConfig.apis??{},n=Object.keys(r).find(c=>l.resolve(o.configPath?l.dirname(o.configPath):t.fs.cwd,r[c].root)===s),i={config:o.forAlias(n),base:l.dirname(s),document:{source:new g(s,f.content),parsed:f.parsed},externalRefResolver:e},a=await p(i),u=P(a);return{...b(a),uniqueErrors:u.errors,uniqueWarnings:u.warnings,problems:h(a,t.fs.cwd).filter(c=>!c.ignored)}}function C(f){const o=new Set,t={};for(const[e,s]of Object.entries(f)){const r=t[e]=t[e]||new Set,n=s.rules.oas3_0;for(const i of Object.keys(n))if(!(n[i]==="off"||n[i]?.severity==="off"))if(i==="assertions"){if(!Array.isArray(n[i]))continue;for(const a of n[i])!a||a.severity==="off"||(r.add(a.assertionId),o.add(a.assertionId))}else o.add(i),r.add(i)}return{perLevel:Object.fromEntries(Object.entries(t).map(([e,s])=>[e,Array.from(s)])),all:Array.from(o)}}function h(f,o){const t={};return f.map(e=>{const s=t[e.ruleId]||0;t[e.ruleId]=s+1;const r=e.location[0];if(s>m)return{...e,codeframe:`Code frame skipped due to too many errors of this type. Only first ${m} errors are shown.`,location:{...r,source:{absoluteRef:d(l.relative(o,r.source.absoluteRef))}},from:void 0};const n=y(r);return{...e,codeframe:v(n,!1),location:{...r,source:{absoluteRef:d(l.relative(o,r.source.absoluteRef))}},from:void 0}})}export{C as getAllRuleNames,R as lintDefinition};
