import f from"node:path";import{CONFIG_FILE_NAME as h}from"../../../constants/common.js";import{normalizeRouteSlug as c}from"../../../utils/path/normalize-route-slug.js";import{removeLeadingSlash as L}from"../../../utils/url/remove-leading-slash.js";import{parseBaseName as x}from"../utils.js";const y=async(e,s)=>{if(!e.match(/(\.ya?ml|\.json)$/)||f.posix.basename(e)===h||await s.isPathIgnored(e))return!1;const i=s.fs.getFileInfo(e);if(!i)return!1;try{const{data:n}=await s.cache.load(i.realRelativePath,"yaml");return!(!n?.openapi&&!n?.swagger)}catch{return!1}},F=async(e,s,i,n)=>{const{getRouteBySlug:u,getRouteByFsPath:l}=i,o={isOpenapiDetected:!1,isOpenapiValid:!1},g={isOpenapiDetected:!0,isOpenapiValid:!1},d={isOpenapiDetected:!0,isOpenapiValid:!0};let r=e.toLowerCase();if(e.startsWith("/"))r=c(e);else if(e.startsWith("./")||e.startsWith("../")){const t=l(s)?.slug;if(!t)return o;const{isIndexFile:a}=x(s);r=a?c(f.posix.join(t,e)):c(f.posix.join(t,"../",e))}else return o;const p=r.toLowerCase().split("/");for(let t=p.length;t>=0;t--){const a=p.slice(0,t).join("/"),O=p.slice(t).join("/"),m=u(a)||l(L(a));if(m)return await y(m.fsPath,n)?O?g:d:o}return o};export{F as isOpenApiURL,y as isOpenapiDoc};
