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