import b from"node:path";import{REDOCLY_TEAMS_RBAC as u}from"@redocly/config";import{slash as k}from"../../../utils/path/slash.js";function f(a,r,t){if(!r)throw new Error("Visitor required");if(a){a.description&&r(a,"description",t.location.absolutePointer+"/description",t);for(const o in a["x-enumDescriptions"])r(a["x-enumDescriptions"],o,t.location.absolutePointer+"/x-enumDescriptions/"+o,t)}}const g=/^[a-zA-Z0-9\s\-,.!\?:;'"()/]+$/,s=({outputRelativePath:a,cwd:r})=>{const t=function(e,m,l,p){const{node:n}=p.resolve(e[m]);if(!n||typeof n!="string"||n.match(g))return;const i=p.getVisitorData();i.markdocChunks=i.markdocChunks||[],i.markdocChunks.push({node:e,pointer:k(b.relative(r,l)),markdown:n,relativePath:a,key:m})};return{any:{leave(o,e){f(o,t,e)}},ref:{leave(o,e){f(o,t,e)}}}},c=()=>{const a={};return{Tag:{enter(r){r?.["x-rbac"]&&(a[String(r.name)]=r["x-rbac"])}},any:{leave(r,t){if((t.type.name==="Operation"||t.type.name==="Webhook")&&"tags"in r&&Array.isArray(r.tags))for(const o of r.tags)a[o]&&(r["x-rbac"]=r["x-rbac"]||a[o]);r?.["x-rbac"]&&(r[u]=r["x-rbac"],delete r["x-rbac"])}},ref:{leave(r){r?.["x-rbac"]&&(r[u]=r["x-rbac"],delete r["x-rbac"])}}}};function h(a,r,t){const o={id:"markdown",decorators:{oas2:{markdown:s,rbac:c},oas3:{markdown:s,rbac:c},async3:{markdown:s,rbac:c}}};return{...a,decorators:{"markdown/rbac":"on","markdown/markdown":{outputRelativePath:r,cwd:t},...a.decorators||{}},plugins:[...a.plugins||[],o]}}export{s as MarkdownParserDecorator,c as RbacDecorator,h as injectDecoratorIntoConfig};
