import f from"node:path";import{CONFIG_FILE_NAME as h}from"../../../constants/index.js";import{parseBaseName as L}from"../utils.js";import{normalizeRouteSlug as c,removeLeadingSlash as w}from"../../../shared/utils.js";const x=async(e,s)=>{if(!e.match(/(\.ya?ml|\.json)$/)||f.posix.basename(e)===h||await s.isPathIgnored(e))return!1;const i=await 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}},A=async(e,s,i,n)=>{const{getRouteBySlug:m,getRouteByFsPath:l}=i,a={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 a;const{isIndexFile:o}=L(s);r=o?c(f.posix.join(t,e)):c(f.posix.join(t,"../",e))}else return a;const p=r.toLowerCase().split("/");for(let t=p.length;t>=0;t--){const o=p.slice(0,t).join("/"),O=p.slice(t).join("/"),u=m(o)||l(w(o));if(u)return await x(u.fsPath,n)?O?g:d:a}return a};export{A as isOpenApiURL,x as isOpenapiDoc};
